102 private $requestInfoFilter;
134 $this->_eventManager = $eventManager;
135 $this->_scopeConfig = $scopeConfig;
137 $this->_resourceCart = $resourceCart;
138 $this->_checkoutSession = $checkoutSession;
139 $this->_customerSession = $customerSession;
144 parent::__construct(
$data);
191 return $this->
getQuote()->getItemsCollection();
219 if (!$this->
hasData(
'quote')) {
220 $this->
setData(
'quote', $this->_checkoutSession->getQuote());
234 $this->
setData(
'quote', $quote);
246 $this->_checkoutSession->setCartWasUpdated(
true);
250 && $this->_checkoutSession->getCheckoutState() !==
null) {
251 $quote->removeAllAddresses()->removePayment();
252 $this->_checkoutSession->resetCheckout();
268 $storeId = $this->_storeManager->getStore()->getId();
279 $info = new \Magento\Framework\DataObject(
$info);
280 if ($qtyFlag ===
null) {
301 if ($productInfo instanceof
Product) {
304 throw new \Magento\Framework\Exception\LocalizedException(
305 __(
"The product wasn't found. Verify the product and try again.")
308 }
elseif (is_int($productInfo) || is_string($productInfo)) {
309 $storeId = $this->_storeManager->getStore()->getId();
311 $product = $this->productRepository->getById($productInfo,
false,
$storeId);
313 throw new \Magento\Framework\Exception\LocalizedException(
314 __(
"The product wasn't found. Verify the product and try again."),
319 throw new \Magento\Framework\Exception\LocalizedException(
320 __(
"The product wasn't found. Verify the product and try again.")
323 $currentWebsiteId = $this->_storeManager->getStore()->getWebsiteId();
324 if (!is_array(
$product->getWebsiteIds()) || !in_array($currentWebsiteId,
$product->getWebsiteIds())) {
325 throw new \Magento\Framework\Exception\LocalizedException(
326 __(
"The product wasn't found. Verify the product and try again.")
348 throw new \Magento\Framework\Exception\LocalizedException(
349 __(
'We found an invalid request for adding product to quote.')
352 $this->getRequestInfoFilter()->filter(
$request);
386 $this->_checkoutSession->setUseNotice(
false);
393 if (
$product->hasOptionsValidationFail()) {
394 $redirectUrl =
$product->getUrlModel()->getUrl(
396 [
'_query' => [
'startcustomization' => 1]]
399 $redirectUrl =
$product->getProductUrl();
401 $this->_checkoutSession->setRedirectUrl($redirectUrl);
402 if ($this->_checkoutSession->getUseNotice() ===
null) {
403 $this->_checkoutSession->setUseNotice(
true);
405 throw new \Magento\Framework\Exception\LocalizedException(
__(
$result));
408 throw new \Magento\Framework\Exception\LocalizedException(
__(
'The product does not exist.'));
411 $this->_eventManager->dispatch(
412 'checkout_cart_product_add_after',
415 $this->_checkoutSession->setLastAddedProductId(
$productId);
427 $allAvailable =
true;
444 $allAvailable =
false;
448 if (!$allAvailable) {
449 $this->messageManager->addErrorMessage(
__(
"We don't have some of the products you want."));
452 $this->messageManager->addErrorMessage(
__(
"We don't have as many of some products as you want."));
470 foreach (
$data as $itemId => $itemInfo) {
471 if (!isset($itemInfo[
'qty'])) {
474 $qty = (float)$itemInfo[
'qty'];
489 $data[$itemId][
'before_suggest_qty'] = $qty;
490 $data[$itemId][
'qty'] = $this->stockState->suggestQty(
493 $product->getStore()->getWebsiteId()
510 $infoDataObject = new \Magento\Framework\DataObject(
$data);
511 $this->_eventManager->dispatch(
512 'checkout_cart_update_items_before',
513 [
'cart' => $this,
'info' => $infoDataObject]
516 $qtyRecalculatedFlag =
false;
517 foreach (
$data as $itemId => $itemInfo) {
523 if (!empty($itemInfo[
'remove']) || isset($itemInfo[
'qty']) && $itemInfo[
'qty'] ==
'0') {
528 $qty = isset($itemInfo[
'qty']) ? (double)$itemInfo[
'qty'] :
false;
532 if (
$item->getHasError()) {
533 throw new \Magento\Framework\Exception\LocalizedException(
__(
$item->getMessage()));
536 if (isset($itemInfo[
'before_suggest_qty']) && $itemInfo[
'before_suggest_qty'] != $qty) {
537 $qtyRecalculatedFlag =
true;
538 $this->messageManager->addNoticeMessage(
539 __(
'Quantity was recalculated from %1 to %2', $itemInfo[
'before_suggest_qty'], $qty),
540 'quote_item' .
$item->getId()
546 if ($qtyRecalculatedFlag) {
547 $this->messageManager->addNoticeMessage(
548 __(
'We adjusted product quantities to fit the required increments.')
552 $this->_eventManager->dispatch(
553 'checkout_cart_update_items_after',
554 [
'cart' => $this,
'info' => $infoDataObject]
569 $this->
getQuote()->removeItem($itemId);
580 $this->_eventManager->dispatch(
'checkout_cart_save_before', [
'cart' => $this]);
582 $this->
getQuote()->getBillingAddress();
583 $this->
getQuote()->getShippingAddress()->setCollectShippingRates(
true);
585 $this->quoteRepository->save($this->
getQuote());
586 $this->_checkoutSession->setQuoteId($this->
getQuote()->getId());
590 $this->_eventManager->dispatch(
'checkout_cart_save_after', [
'cart' => $this]);
614 $this->
getQuote()->removeAllItems();
623 if (
null === $this->_productIds) {
624 $this->_productIds = [];
627 $this->_productIds[] =
$item->getProductId();
630 $this->_productIds = array_unique($this->_productIds);
642 $quoteId = $this->_checkoutSession->getQuoteId();
647 if (!
$quoteId && $this->_customerSession->isLoggedIn()) {
648 $this->_checkoutSession->getQuote();
649 $quoteId = $this->_checkoutSession->getQuoteId();
652 if (
$quoteId && $this->_summaryQty ===
null) {
653 $useQty = $this->_scopeConfig->getValue(
654 'checkout/cart_link/use_qty',
670 return $this->
getQuote()->getItemsCount() * 1;
681 return $this->
getQuote()->getItemsQty() * 1;
703 throw new \Magento\Framework\Exception\LocalizedException(
__(
'This quote item does not exist.'));
724 $this->_checkoutSession->setUseNotice(
false);
732 if ($this->_checkoutSession->getUseNotice() ===
null) {
733 $this->_checkoutSession->setUseNotice(
true);
735 throw new \Magento\Framework\Exception\LocalizedException(
__(
$result));
738 $this->_eventManager->dispatch(
739 'checkout_cart_product_update_after',
742 $this->_checkoutSession->setLastAddedProductId(
$productId);
752 private function getRequestInfoFilter()
754 if ($this->requestInfoFilter ===
null) {
756 ->get(\
Magento\Checkout\Model\
Cart\RequestInfoFilterInterface::class);
758 return $this->requestInfoFilter;
const CHECKOUT_STATE_BEGIN
updateItem($itemId, $requestInfo=null, $updatingParams=null)
_getProductRequest($requestInfo)
getData($key='', $index=null)
elseif(isset( $params[ 'redirect_parent']))
addOrderItem($orderItem, $qtyFlag=null)
addProduct($productInfo, $requestInfo=null)
__construct(\Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Checkout\Model\ResourceModel\Cart $resourceCart, Session $checkoutSession, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\Message\ManagerInterface $messageManager, \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, \Magento\CatalogInventory\Api\StockStateInterface $stockState, \Magento\Quote\Api\CartRepositoryInterface $quoteRepository, ProductRepositoryInterface $productRepository, array $data=[])
setQuote(\Magento\Quote\Model\Quote $quote)
foreach($optionCollection as $option) $requestInfo
setData($key, $value=null)
addProductsByIds($productIds)
_getProduct($productInfo)
foreach( $_productCollection as $_product)() ?>" class $info