Skip to content

Commit 1f58085

Browse files
mstrzyzewskiMaksymilian Strzyżewski
andauthored
Fix problem with adding catalog price rule to order (#95)
Co-authored-by: Maksymilian Strzyżewski <m.strzyzewski@macopedia.pl>
1 parent 4d109f5 commit 1f58085

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Model/OrderImporter/Creator.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Macopedia\Allegro\Api\Data\CheckoutFormInterface;
99
use Macopedia\Allegro\Api\ProductRepositoryInterface;
1010
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\DataObject\Factory;
1112
use Magento\Framework\Event\ManagerInterface;
1213
use Magento\Framework\Exception\LocalizedException;
1314
use 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

Comments
 (0)