gpt4 book ai didi

magento - 在观察者中获取简单产品的选定自定义选项价格

转载 作者:行者123 更新时间:2023-12-02 15:30:05 24 4
gpt4 key购买 nike

如何在观察者中获取选定的自定义期权价格。我正在使用 checkout_cart_product_add_after 事件作为观察者和观察者代码:

public function applyCartPriceChange(Varien_Event_Observer $observer)
{

$item = $observer->getQuoteItem();
$product = $item->getProduct();
$productOptions = $product->getTypeInstance(true)->getOrderOptions($product);
echo '<pre>';
print_r($productOptions);
foreach($productOptions['options'] as $key=>$value){
if($value['label'] !='Date'){
echo $value['option_id'];
}
}
exit;

if ($specialPrice > 0) {
$item->setCustomPrice($specialPrice);
$item->setOriginalCustomPrice($specialPrice);
$item->getProduct()->setIsSuperMode(true);
}
}

我使用此代码获取所有选定的自定义选项详细信息,但不获取价格 $productOptions = $product->getTypeInstance(true)->getOrderOptions($product); 它打印数组,如下所示:

Array
(
[info_buyRequest] => Array
(
[uenc] => aHR0cDovLzE5Mi4xNjguMS45My9sbWR0L2luZGV4LnBocC9kYXktdG91cnMvdGVzdDIuaHRtbA,,
[product] => 35
[form_key] => UnobrzsuAmTK6rJy
[related_product] =>
[options] => Array
(
[635] => Array
(
[date] => 12/19/2013
[date_internal] => 2013-12-19 00:00:00
)

[633] => 1735
[636] => Array
(
[0] => 1749
)

[634] => 1741
[637] => Array
(
[0] => 1751
)

)

[validate_datetime_635] =>
[qty] => 0
)

[options] => Array
(
[0] => Array
(
[label] => Date
[value] => Dec 19, 2013
[print_value] => Dec 19, 2013
[option_id] => 635
[option_type] => date
[option_value] => 2013-12-19 00:00:00
[custom_view] =>
)

[1] => Array
(
[label] => Adult
[value] => 7
[print_value] => 7
[option_id] => 633
[option_type] => drop_down
[option_value] => 1735
[custom_view] =>
)

[2] => Array
(
[label] => Lunch
[value] => Adult Lunch
[print_value] => Adult Lunch
[option_id] => 636
[option_type] => checkbox
[option_value] => 1749
[custom_view] =>
)

[3] => Array
(
[label] => Child
[value] => 3
[print_value] => 3
[option_id] => 634
[option_type] => drop_down
[option_value] => 1741
[custom_view] =>
)

[4] => Array
(
[label] => Lunch
[value] => Child Lunch
[print_value] => Child Lunch
[option_id] => 637
[option_type] => checkbox
[option_value] => 1751
[custom_view] =>
)

)

)

任何帮助将不胜感激。谢谢

最佳答案

public function applyCartPriceChange(Varien_Event_Observer $observer)
{
$item = $observer->getQuoteItem();
$product = $item->getProduct();
$productOptions = $product->getTypeInstance(true)->getOrderOptions($product);
//echo '<pre>';
//print_r($productOptions);exit;
foreach ($productOptions['options'] as $key => $value) {

$product = Mage::getModel("catalog/product")->load($product->getId()); //product id 1
foreach ($product->getOptions() as $o) {
$values = $o->getValues();
if ($o->getTitle() == 'Adult') { //change your custom option title to compare
foreach ($values as $v) {
if ($value['option_value'] == $v->getOptionTypeId()) {
$adultPrice = $v->getprice(); /* get price of custom option*/
$noOfAdult = $v->getTitle();
}
}
}
}
}
}

关于magento - 在观察者中获取简单产品的选定自定义选项价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20673624/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com