当前位置: 首页>>代码示例>>PHP>>正文


PHP Session::setCartWasUpdated方法代码示例

本文整理汇总了PHP中Magento\Checkout\Model\Session::setCartWasUpdated方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::setCartWasUpdated方法的具体用法?PHP Session::setCartWasUpdated怎么用?PHP Session::setCartWasUpdated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Checkout\Model\Session的用法示例。


在下文中一共展示了Session::setCartWasUpdated方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 /**
  * @inheritdoc
  */
 public function setUp()
 {
     parent::setUp();
     $this->quote = $this->_objectManager->create('Magento\\Quote\\Model\\Quote');
     $this->checkoutSession = $this->_objectManager->get('Magento\\Checkout\\Model\\Session');
     $this->quote->load('test01', 'reserved_order_id');
     $this->checkoutSession->setQuoteId($this->quote->getId());
     $this->checkoutSession->setCartWasUpdated(false);
 }
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:12,代码来源:CheckoutTest.php

示例2: reinitializeState

 /**
  * Reinitialize cart quote state
  *
  * @return $this
  */
 protected function reinitializeState()
 {
     $quote = $this->getQuote()->setCheckoutMethod('');
     $this->_checkoutSession->setCartWasUpdated(true);
     // TODO: Move this logic to Multishipping module as plug-in.
     // reset for multiple address checkout
     if ($this->_checkoutSession->getCheckoutState() !== Session::CHECKOUT_STATE_BEGIN && $this->_checkoutSession->getCheckoutState() !== null) {
         $quote->removeAllAddresses()->removePayment();
         $this->_checkoutSession->resetCheckout();
     }
     return $this;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:17,代码来源:Cart.php

示例3: execute

 public function execute()
 {
     $params = $this->getRequest()->getParams();
     /** @var \Magento\Checkout\Model\Cart $cart */
     $cart = $this->cartFactory->create();
     $successMessage = '';
     $websiteId = $this->storeManager->getStore()->getWebsiteId();
     foreach ($params as $key => $product) {
         if ($product && is_array($product)) {
             $productModel = $this->productFactory->create();
             // loadByAttribute() return false if the product was not found. There is no need to check the ID,
             // but lets stay on the safe side for the future Magento releases
             /** @var \Magento\Catalog\Model\Product $productBySKU */
             $productBySKU = $productModel->loadByAttribute('sku', $product['sku']);
             if (!$productBySKU || !($productId = $productBySKU->getId())) {
                 continue;
             }
             $stockItem = $this->stockItemApiFactory->create();
             /** @var \Magento\CatalogInventory\Model\ResourceModel\Stock\Item $stockItemResource */
             $stockItemResource = $this->stockItemApiResourceFactory->create();
             $stockItemResource->loadByProductId($stockItem, $productId, $websiteId);
             $qty = $stockItem->getQty();
             try {
                 if (!$cart->getQuote()->hasProductId($productId) && is_numeric($product['qty']) && $qty > $product['qty']) {
                     $cart->addProduct($productBySKU, (int) $product['qty']);
                     $successMessage .= __('%1 was added to your shopping cart.' . '</br>', $this->escaper->escapeHtml($productBySKU->getName()));
                 }
                 unset($params[$key]);
             } catch (\Exception $e) {
                 $this->rejoinerHelper->log($e->getMessage());
             }
         }
     }
     if (isset($params['coupon_code'])) {
         $cart->getQuote()->setCouponCode($params['coupon_code'])->collectTotals();
     }
     try {
         $cart->getQuote()->save();
         $cart->save();
     } catch (\Exception $e) {
         $this->rejoinerHelper->log($e->getMessage());
     }
     $this->checkoutSession->setCartWasUpdated(true);
     if ($successMessage) {
         $this->messageManager->addSuccess($successMessage);
     }
     $url = $this->_url->getUrl('checkout/cart/', ['updateCart' => true]);
     $this->getResponse()->setRedirect($url);
 }
开发者ID:rejoiner,项目名称:magento2-plugin,代码行数:49,代码来源:Index.php


注:本文中的Magento\Checkout\Model\Session::setCartWasUpdated方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。