Skip to content

Commit

Permalink
Fix problem with adding catalog price rule to order (#95)
Browse files Browse the repository at this point in the history
Co-authored-by: Maksymilian Strzyżewski <[email protected]>
  • Loading branch information
mstrzyzewski and Maksymilian Strzyżewski authored Apr 14, 2021
1 parent 4d109f5 commit 1f58085
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Model/OrderImporter/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Macopedia\Allegro\Api\Data\CheckoutFormInterface;
use Macopedia\Allegro\Api\ProductRepositoryInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\DataObject\Factory;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
Expand Down Expand Up @@ -70,6 +71,9 @@ class Creator
/** @var CartExtensionFactory */
private $cartExtensionFactory;

/** @var Factory */
private $objectFactory;

/**
* Creator constructor.
* @param Shipping $shipping
Expand All @@ -85,6 +89,7 @@ class Creator
* @param ScopeConfigInterface $scopeConfig
* @param QuoteManagement $quoteManagement
* @param Registry $registry
* @param Factory $objectFactory
*/
public function __construct(
Shipping $shipping,
Expand All @@ -99,7 +104,8 @@ public function __construct(
StoreManagerInterface $storeManager,
ScopeConfigInterface $scopeConfig,
QuoteManagement $quoteManagement,
Registry $registry
Registry $registry,
Factory $objectFactory
) {
$this->shipping = $shipping;
$this->payment = $payment;
Expand All @@ -114,6 +120,7 @@ public function __construct(
$this->scopeConfig = $scopeConfig;
$this->quoteManagement = $quoteManagement;
$this->registry = $registry;
$this->objectFactory = $objectFactory;
}

/**
Expand Down Expand Up @@ -218,10 +225,12 @@ private function processItems(Quote $quote, CheckoutFormInterface $checkoutForm)
}

$lineItemsIds[$product->getSku()] = $lineItem->getId();
$product->setPrice($lineItem->getPrice()->getAmount());
$price = $lineItem->getPrice()->getAmount();
$product->setPrice($price);
$request = $this->objectFactory->create(['qty' => $lineItem->getQty(), 'custom_price' => $price]);
$product->setSpecialPrice(null);
try {
$quote->addProduct($product, $lineItem->getQty());
$quote->addProduct($product, $request);
} catch (LocalizedException $e) {
throw new CreatorItemsException(
"Error while trying to add product with sku {$product->getSku()} to quote",
Expand Down

0 comments on commit 1f58085

Please sign in to comment.