Skip to content

Commit

Permalink
PERF-10: fix add to cart for simple products with options
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedmwalied committed Mar 10, 2024
1 parent 3cc5aa5 commit 5e6a32e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Model/Quote/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
*/
namespace ScandiPWA\QuoteGraphQl\Model\Quote;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Type\AbstractType;
use Magento\Framework\DataObject;
use Magento\Framework\Exception\LocalizedException;
use Magento\Quote\Model\Quote as SourceQuote;

/**
Expand All @@ -29,4 +33,36 @@ public function beforeSave()
$this->setCustomerIsGuest($customerIsGuest);
return $this;
}

public function addProduct(
Product $product,
$request = null,
$processMode = AbstractType::PROCESS_MODE_FULL
)
{
if ($request === null) {
$request = 1;
}

if (is_numeric($request)) {
$request = $this->objectFactory->create(['qty' => $request]);
}

if (!$request instanceof DataObject) {
throw new LocalizedException(
__('We found an invalid request for adding product to quote.')
);
}

if (!$product->isSalable()) {
throw new LocalizedException(
__('Product that you are trying to add is not available.')
);
}

$productId = $product->getId();
$product = clone $this->productRepository->getById($productId, false, $this->getStore()->getId());

parent::addProduct($product, $request, $processMode);
}
}

0 comments on commit 5e6a32e

Please sign in to comment.