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


PHP Quote::addProduct方法代码示例

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


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

示例1: init

 /**
  * @param \Magento\Quote\Model\Quote $quote
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\DataObject $config
  * @return \Magento\Quote\Model\Quote\Item|string
  */
 public function init(\Magento\Quote\Model\Quote $quote, \Magento\Catalog\Model\Product $product, \Magento\Framework\DataObject $config)
 {
     $stockItem = $this->stockRegistry->getStockItem($product->getId(), $quote->getStore()->getWebsiteId());
     if ($stockItem->getIsQtyDecimal()) {
         $product->setIsQtyDecimal(1);
     } else {
         $config->setQty((int) $config->getQty());
     }
     $product->setCartQty($config->getQty());
     $item = $quote->addProduct($product, $config, \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL);
     return $item;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:18,代码来源:Initializer.php

示例2: testAddProductItemPreparation

 public function testAddProductItemPreparation()
 {
     $itemMock = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Item', [], [], '', false);
     $expectedResult = $itemMock;
     $requestMock = $this->getMock('\\Magento\\Framework\\Object');
     $this->objectFactoryMock->expects($this->once())->method('create')->with($this->equalTo(['qty' => 1]))->will($this->returnValue($requestMock));
     $typeInstanceMock = $this->getMock('Magento\\Catalog\\Model\\Product\\Type\\Simple', ['prepareForCartAdvanced'], [], '', false);
     $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getParentProductId', 'setStickWithinParent', '__wakeup'], [], '', false);
     $collectionMock = $this->getMock('Magento\\Quote\\Model\\Resource\\Quote\\Item\\Collection', [], [], '', false);
     $itemMock->expects($this->any())->method('representProduct')->will($this->returnValue(true));
     $iterator = new \ArrayIterator([$itemMock]);
     $collectionMock->expects($this->any())->method('getIterator')->will($this->returnValue($iterator));
     $this->quoteItemCollectionFactoryMock->expects($this->once())->method('create')->will($this->returnValue($collectionMock));
     $typeInstanceMock->expects($this->once())->method('prepareForCartAdvanced')->will($this->returnValue([$productMock]));
     $this->productMock->expects($this->once())->method('getTypeInstance')->will($this->returnValue($typeInstanceMock));
     $result = $this->quote->addProduct($this->productMock, null);
     $this->assertEquals($expectedResult, $result);
 }
开发者ID:nja78,项目名称:magento2,代码行数:18,代码来源:QuoteTest.php

示例3: initializeQuoteItems

 private function initializeQuoteItems()
 {
     foreach ($this->proxyOrder->getItems() as $item) {
         $this->clearQuoteItemsCache();
         /** @var $quoteItemBuilder \Ess\M2ePro\Model\Magento\Quote\Item */
         $quoteItemBuilder = $this->modelFactory->getObject('Magento\\Quote\\Item', ['quote' => $this->quote, 'proxyItem' => $item]);
         $product = $quoteItemBuilder->getProduct();
         $request = $quoteItemBuilder->getRequest();
         // ---------------------------------------
         $productOriginalPrice = (double) $product->getPrice();
         $price = $item->getBasePrice();
         $product->setPrice($price);
         $product->setSpecialPrice($price);
         // ---------------------------------------
         // see Mage_Sales_Model_Observer::substractQtyFromQuotes
         $this->quote->setItemsCount($this->quote->getItemsCount() + 1);
         $this->quote->setItemsQty((double) $this->quote->getItemsQty() + $request->getQty());
         $result = $this->quote->addProduct($product, $request);
         if (is_string($result)) {
             throw new \Ess\M2ePro\Model\Exception($result);
         }
         $quoteItem = $this->quote->getItemByProduct($product);
         if ($quoteItem !== false) {
             $quoteItem->setStoreId($this->quote->getStoreId());
             $quoteItem->setOriginalCustomPrice($item->getPrice());
             $quoteItem->setOriginalPrice($productOriginalPrice);
             $quoteItem->setBaseOriginalPrice($productOriginalPrice);
             $quoteItem->setNoDiscount(1);
             $giftMessageId = $quoteItemBuilder->getGiftMessageId();
             if (!empty($giftMessageId)) {
                 $quoteItem->setGiftMessageId($giftMessageId);
             }
             $quoteItem->setAdditionalData($quoteItemBuilder->getAdditionalData($quoteItem));
         }
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:36,代码来源:Quote.php

示例4: addProductToQuote

 /**
  * Add products to quote
  *
  * @param \Magento\Quote\Model\Quote $quote
  * @param array $itemsData
  * @return $this
  */
 protected function addProductToQuote($quote, $itemsData)
 {
     foreach ($itemsData as $itemData) {
         $sku = $itemData['sku'];
         $price = $itemData['price'];
         $qty = isset($itemData['qty']) ? $itemData['qty'] : 1;
         $taxClassName = isset($itemData['tax_class_name']) ? $itemData['tax_class_name'] : self::PRODUCT_TAX_CLASS_1;
         $taxClassId = $this->productTaxClasses[$taxClassName];
         $product = $this->createSimpleProduct($sku, $price, $taxClassId);
         $quote->addProduct($product, $qty);
     }
     return $this;
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:20,代码来源:SetupUtil.php

示例5: addItemsToQuote

 /**
  * Add existing or newly created products to the quote
  *
  * @param \Magento\Quote\Model\Quote $quote
  */
 protected function addItemsToQuote($quote)
 {
     /* Check if there are some generated sample products */
     $product = $this->productFactory->create();
     $productsCollection = $product->getCollection()->addAttributeToFilter('name', ['like' => self::NAMES_PREFIX . '%']);
     if ($productsCollection->getSize() > 0) {
         $product = $productsCollection->getFirstItem();
     } else {
         /* If there are no generated products - try to create one */
         $product = $this->productsCreator->createSimpleProduct();
     }
     $quote->addProduct($product);
 }
开发者ID:rogyar,项目名称:m2-sampledata-generator,代码行数:18,代码来源:OrdersCreator.php

示例6: _populateQuoteItems

 public function _populateQuoteItems(\Magento\Quote\Model\Quote $quote)
 {
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->_getProductBySku(self::SKU);
     //        $product->setPrice(8.00);
     $req = new \Magento\Framework\DataObject();
     $req->setQty(1);
     $req->setCustomPrice(8);
     $quote->addProduct($product, $req);
     return $quote;
 }
开发者ID:praxigento,项目名称:mobi_app_generic_mage2,代码行数:11,代码来源:SaleOrder.php

示例7: addProductToQuote

 /**
  * Add product to quote
  *
  * This file was inspired by
  * @see dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_bundle_and_options.php
  *
  * @param \Magento\Quote\Model\Quote $quote
  * @param \Magento\Catalog\Model\Product $product
  * @param int $qty
  * @param $itemData
  * @throws \Exception
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function addProductToQuote(\Magento\Quote\Model\Quote $quote, \Magento\Catalog\Model\Product $product, $qty, $itemData)
 {
     if ($product->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) {
         $quote->addProduct($product, $qty);
     } elseif ($product->getTypeId() == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) {
         $attribute = $this->getConfigurableAttribute(self::CONFIGURABLE_ATTRIBUTE_NAME);
         /** @var \Magento\Eav\Api\Data\AttributeOptionInterface[] $options */
         $options = $attribute->getOptions();
         array_shift($options);
         //remove the first option which is empty
         $requestInfo = new \Magento\Framework\DataObject();
         if (!empty($options)) {
             $option = $options[0];
             $requestData = ['qty' => $qty];
             /** @var \Magento\ConfigurableProduct\Api\Data\ConfigurableItemOptionValueInterface $option */
             $requestData['super_attribute'][$attribute->getId()] = $option->getValue();
             $requestInfo->addData($requestData);
         }
         $quote->addProduct($product, $requestInfo);
     } elseif ($product->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
         /** @var $typeInstance \Magento\Bundle\Model\Product\Type */
         //Load options
         $typeInstance = $product->getTypeInstance();
         $typeInstance->setStoreFilter($product->getStoreId(), $product);
         $optionCollection = $typeInstance->getOptionsCollection($product);
         $bundleOptions = [];
         $bundleOptionsQty = [];
         /** @var $option \Magento\Bundle\Model\Option */
         foreach ($optionCollection as $option) {
             $selectionsCollection = $typeInstance->getSelectionsCollection([$option->getId()], $product);
             if ($option->isMultiSelection()) {
                 $selectionsCollection->load();
                 $bundleOptions[$option->getId()] = array_column($selectionsCollection->toArray(), 'selection_id');
             } else {
                 $bundleOptions[$option->getId()] = $selectionsCollection->getFirstItem()->getSelectionId();
             }
             $optionQty = 1;
             foreach ($itemData['bundled_options'] as $bundledOptionData) {
                 if ($option->getTitle() == $bundledOptionData['title']) {
                     $optionQty = $bundledOptionData['qty'];
                     break;
                 }
             }
             $bundleOptionsQty[$option->getId()] = $optionQty;
         }
         $requestInfo = new \Magento\Framework\DataObject(['qty' => $qty, 'bundle_option' => $bundleOptions, 'bundle_option_qty' => $bundleOptionsQty]);
         $quote->addProduct($product, $requestInfo);
     } else {
         throw new \Exception('Unrecognized type: ' . $product->getTypeId());
     }
 }
开发者ID:classyllama,项目名称:ClassyLlama_AvaTax,代码行数:64,代码来源:SetupUtil.php


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