88use Macopedia \Allegro \Api \Data \CheckoutFormInterface ;
99use Macopedia \Allegro \Api \ProductRepositoryInterface ;
1010use Magento \Framework \App \Config \ScopeConfigInterface ;
11+ use Magento \Framework \DataObject \Factory ;
1112use Magento \Framework \Event \ManagerInterface ;
1213use Magento \Framework \Exception \LocalizedException ;
1314use Magento \Framework \Exception \NoSuchEntityException ;
@@ -70,6 +71,9 @@ class Creator
7071 /** @var CartExtensionFactory */
7172 private $ cartExtensionFactory ;
7273
74+ /** @var Factory */
75+ private $ objectFactory ;
76+
7377 /**
7478 * Creator constructor.
7579 * @param Shipping $shipping
@@ -85,6 +89,7 @@ class Creator
8589 * @param ScopeConfigInterface $scopeConfig
8690 * @param QuoteManagement $quoteManagement
8791 * @param Registry $registry
92+ * @param Factory $objectFactory
8893 */
8994 public function __construct (
9095 Shipping $ shipping ,
@@ -99,7 +104,8 @@ public function __construct(
99104 StoreManagerInterface $ storeManager ,
100105 ScopeConfigInterface $ scopeConfig ,
101106 QuoteManagement $ quoteManagement ,
102- Registry $ registry
107+ Registry $ registry ,
108+ Factory $ objectFactory
103109 ) {
104110 $ this ->shipping = $ shipping ;
105111 $ this ->payment = $ payment ;
@@ -114,6 +120,7 @@ public function __construct(
114120 $ this ->scopeConfig = $ scopeConfig ;
115121 $ this ->quoteManagement = $ quoteManagement ;
116122 $ this ->registry = $ registry ;
123+ $ this ->objectFactory = $ objectFactory ;
117124 }
118125
119126 /**
@@ -218,10 +225,12 @@ private function processItems(Quote $quote, CheckoutFormInterface $checkoutForm)
218225 }
219226
220227 $ lineItemsIds [$ product ->getSku ()] = $ lineItem ->getId ();
221- $ product ->setPrice ($ lineItem ->getPrice ()->getAmount ());
228+ $ price = $ lineItem ->getPrice ()->getAmount ();
229+ $ product ->setPrice ($ price );
230+ $ request = $ this ->objectFactory ->create (['qty ' => $ lineItem ->getQty (), 'custom_price ' => $ price ]);
222231 $ product ->setSpecialPrice (null );
223232 try {
224- $ quote ->addProduct ($ product , $ lineItem -> getQty () );
233+ $ quote ->addProduct ($ product , $ request );
225234 } catch (LocalizedException $ e ) {
226235 throw new CreatorItemsException (
227236 "Error while trying to add product with sku {$ product ->getSku ()} to quote " ,
0 commit comments