本文整理匯總了PHP中Magento\Quote\Model\Quote\Item::setCustomPrice方法的典型用法代碼示例。如果您正苦於以下問題:PHP Item::setCustomPrice方法的具體用法?PHP Item::setCustomPrice怎麽用?PHP Item::setCustomPrice使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Quote\Model\Quote\Item
的用法示例。
在下文中一共展示了Item::setCustomPrice方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: prepare
/**
* Set qty and custom price for quote item
*
* @param Item $item
* @param Object $request
* @param Product $candidate
* @return void
*/
public function prepare(Item $item, Object $request, Product $candidate)
{
/**
* We specify qty after we know about parent (for stock)
*/
$item->addQty($candidate->getCartQty());
$customPrice = $request->getCustomPrice();
if (!empty($customPrice)) {
$item->setCustomPrice($customPrice);
$item->setOriginalCustomPrice($customPrice);
}
}
示例2: prepare
/**
* Set qty and custom price for quote item
*
* @param Item $item
* @param \Magento\Framework\Object $request
* @param Product $candidate
* @return void
*/
public function prepare(Item $item, Object $request, Product $candidate)
{
/**
* We specify qty after we know about parent (for stock)
*/
if ($request->getResetCount() && !$candidate->getStickWithinParent() && $item->getId() == $request->getId()) {
$item->setData(CartItemInterface::KEY_QTY, 0);
}
$item->addQty($candidate->getCartQty());
$customPrice = $request->getCustomPrice();
if (!empty($customPrice)) {
$item->setCustomPrice($customPrice);
$item->setOriginalCustomPrice($customPrice);
}
}
示例3: setCustomPrice
/**
* Prepares custom price and sets into a BuyRequest object as option of quote item
*
* @param array $info
* @param Item $item
* @return array
*/
protected function setCustomPrice(array $info, Item $item)
{
$itemPrice = $this->parseCustomPrice($info['custom_price']);
/** @var \Magento\Framework\DataObject $infoBuyRequest */
$infoBuyRequest = $item->getBuyRequest();
if ($infoBuyRequest) {
$infoBuyRequest->setCustomPrice($itemPrice);
$infoBuyRequest->setValue(serialize($infoBuyRequest->getData()));
$infoBuyRequest->setCode('info_buyRequest');
$infoBuyRequest->setProduct($item->getProduct());
$item->addOption($infoBuyRequest);
}
$item->setCustomPrice($itemPrice);
$item->setOriginalCustomPrice($itemPrice);
}