我有一个观察者,它将动态自定义选项添加到产品详细信息页面(在catalog_controller_product_view
事件中调用)。这允许客户从其现有许可证代码的下拉列表中进行选择。
public function addLicenseOptions(Varien_Event_Observer $observer) {
$product = $observer->getEvent()->getProduct();
if ($product->isSubscriptionProduct()) {
$optionModel = Mage::getModel('catalog/product_option')
->setTitle('License Code')
->setProductId($product->getId())
->setStoreId($product->getStoreId())
->setId('license_code')
->setType('drop_down')
->setPrice(null)
->setPriceType(null)
->setIsRequire(true);
$customer = Mage::getSingleton('customer/session')->getCustomer();
if ($customer->getId()) {
$linksPurchased = Mage::getResourceModel('downloadable/link_purchased_collection')
->addFieldToFilter('customer_id', $customer->getId());
if ($linksPurchased->count() > 0) {
foreach ($linksPurchased as $linkPurchased) {
$valueModel = Mage::getModel('catalog/product_option_value')
->setTitle($linkPurchased->getData('key_code'))
->setProduct($product)
->setOption($optionModel)
->setId($linkPurchased->getData('license_code'))
->setPrice(null)
->setPriceType('fixed')
->setSku(null);
$optionModel->addValue($valueModel);
}
$product->setHasOptions(1);
$product->addOption($optionModel);
}
}
}
}
但是,当我下订单时,选定的选项仅保存在中info_buyRequest
。有没有办法像保存在管理员中创建的产品一样保存它?