我有 2 个自定义选项文本字段与名为 Location To 和 Location From 的产品相关联,
我已经使用称为 getLocationCoords 的方法设置了一个具有 Observer 的模块,checkout_cart_add_product_complete
我将如何从传递给我的方法的事件对象访问这两个字段。
我需要这两个字段,所以我可以对它们进行反向地理编码,我认为我可以自己完成。
一旦我获得了 2 组坐标,我将如何将它们与产品一起存储,以便在订购时能够看到它们与产品相关联?
=======================编辑添加========================= ===
到目前为止我所尝试的
public function getLocationCoords(Varien_Event_Observer $observer)
{
// Retrieve the product being updated from the event observer
$product = $observer->getEvent()->getProduct();
// Write a new line to var/log/product-updates.log
$name = $product->getName();
$sku = $product->getSku();
Mage::log(
"{$name} ({$sku}) updated",
null,
'product-updates.log'
);
foreach ($product->getOptions() as $o) {
$type = "Custom Option TYPE: " . $o->getType();
$title = "Custom Option TITLE: " . $o->getTitle();
Mage::log(
"{$type} ({$title}) custom option {$o}",
null,
'product-updates.log'
);
}
}
除了获取自定义选项的值之外,这一切都有效,我将尝试下面的答案,看看我在哪里
当我打印出选项对象的 var 转储时,这就是我得到的
2012-12-11T15:19:45+00:00 DEBUG (7): array (
'option_id' => '1',
'product_id' => '1',
'type' => 'field',
'is_require' => '1',
'max_characters' => '0',
'sort_order' => '0',
'default_title' => 'Location To',
'title' => 'Location To',
'default_price' => '0.0000',
'default_price_type' => 'fixed',
'price' => '0.0000',
'price_type' => 'fixed',
)
对象没有价值