我想获得产品价格与期权价格使用自定义模块,计算产品价格的公式,我喜欢使用的功能,而不添加到购物车的产品。
此函数用于获取报价项参数
public function getProductFinalPrice($item, $forReindex = false, $storeId = null)
所以我想添加一个带有info_buyRequest购买请求的报价项目,我尝试了这个
$product = $this->_objectManager->create('Magento\Catalog\Model\Product')->load(5862);
$customOptions = $this->_objectManager->get('Magento\Catalog\Model\Product\Option')->getProductOptionCollection($product);
$item = $this->_objectManager->create('Magento\Quote\Model\Quote\Item');
$options = $this->_objectManager->get('Magento\Quote\Model\ResourceModel\Quote\Item\Collection');
$quote = $this->cart->getQuote();
$quote->addProduct($product);
$quote->save();
$options->setQuote($quote);
//$options->addItemFilter($item->getId());
$item->setQuote($quote)->setProduct($product)->setQty($qty);
foreach ($options as $option) {
$item->addOption($option);
}
$infoBuyRequest = [
"info_buyRequest" => [
"uenc" => "aHR0cHM6Ly93d3cud2V0YWcuY2EvZW5fY2EvbmFtZS10YWdzL25hbWUtdGFncy1pbnNwaXJhdGlvbi9jdXN0b20tbmFtZS10YWctb3JkZXIv",
"product" => 5862,
"qty" => $qty
]
];
$option = $this->_objectManager->create(
\Magento\Quote\Model\Quote\Item\Option::class,
['data' => $infoBuyRequest]
);
$item->addOption($option);
$item->setProductOptions($infoBuyRequest);
var_dump($this->_getBuyRequest($item));
var_dump($this->_getBuyRequest($item)); return
object(Magento\Framework\DataObject)#3647 (1) {
["_data":protected]=>
array(2) {
["original_qty"]=>
NULL
["qty"]=>
int(100)
}
}
我喜欢用info_buyrequest获得一些东西
[
"info_buyRequest" => [
"uenc" => "aHR0cHM6Ly93d3cud2V0YWcuY2EvZW5fY2EvbmFtZS10YWdzL25hbWUtdGFncy1pbnNwaXJhdGlvbi9jdXN0b20tbmFtZS10YWctb3JkZXIv",
"product" => 5862,
"qty" => $qty
]
]
这是函数_getBuyRequest
public function _getBuyRequest($item) {
$option = $item->getOptionByCode('info_buyRequest');
if ($option) {
$value = json_decode($option->getValue(), true); //in M2.2 json used for the buy request
if (is_null($value))
$value = unserialize($option->getValue()); //in M<2.2 the buy request is serialized
} else
$value = [];
$buyRequest = new \Magento\Framework\DataObject($value);
// Overwrite standard buy request qty, because item qty could have changed since adding to quote
$buyRequest->setOriginalQty($buyRequest->getQty())
->setQty($item->getQty() * 1);
return $buyRequest;
}
那么,如何添加info_buyRequest呢?我想在报价项目中加载选项。
1条答案
按热度按时间5rgfhyps1#
使用此方法
$_item->getBuyRequest()
。getBuyRequest
已在info_buyRequest
的报价模型中定义了方法