當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DataObject::setQty方法代碼示例

本文整理匯總了PHP中Magento\Framework\DataObject::setQty方法的典型用法代碼示例。如果您正苦於以下問題:PHP DataObject::setQty方法的具體用法?PHP DataObject::setQty怎麽用?PHP DataObject::setQty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Framework\DataObject的用法示例。


在下文中一共展示了DataObject::setQty方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: _getProductRequest

 /**
  * Get request for product add to cart procedure
  *
  * @param   \Magento\Framework\DataObject|int|array $requestInfo
  * @return  \Magento\Framework\DataObject
  */
 protected function _getProductRequest($requestInfo)
 {
     if ($requestInfo instanceof \Magento\Framework\DataObject) {
         $request = $requestInfo;
     } elseif (is_numeric($requestInfo)) {
         $request = new \Magento\Framework\DataObject(['qty' => $requestInfo]);
     } else {
         $request = new \Magento\Framework\DataObject($requestInfo);
     }
     if (!$request->hasQty()) {
         $request->setQty(1);
     }
     !$request->hasFormKey() ?: $request->unsFormKey();
     return $request;
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:21,代碼來源:Cart.php

示例3: addOrderItem

 /**
  * Convert order item to quote item
  *
  * @param \Magento\Sales\Model\Order\Item $orderItem
  * @param true|null $qtyFlag if is null set product qty like in order
  * @return $this
  */
 public function addOrderItem($orderItem, $qtyFlag = null)
 {
     /* @var $orderItem \Magento\Sales\Model\Order\Item */
     if ($orderItem->getParentItem() === null) {
         $storeId = $this->_storeManager->getStore()->getId();
         try {
             /**
              * We need to reload product in this place, because products
              * with the same id may have different sets of order attributes.
              */
             $product = $this->productRepository->getById($orderItem->getProductId(), false, $storeId, true);
         } catch (NoSuchEntityException $e) {
             return $this;
         }
         $info = $orderItem->getProductOptionByCode('info_buyRequest');
         $info = new \Magento\Framework\DataObject($info);
         if ($qtyFlag === null) {
             $info->setQty($orderItem->getQtyOrdered());
         } else {
             $info->setQty(1);
         }
         $this->addProduct($product, $info);
     }
     return $this;
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:32,代碼來源:Cart.php


注:本文中的Magento\Framework\DataObject::setQty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。