本文整理汇总了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;
}
示例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;
}
示例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;
}