Magento 自定义选项:成功..几乎!
好吧,我正在编写自己的脚本来读取特定的 xml 文件并导入产品。现在,这些产品中的每一个都可能具有一组属性(例如颜色)。
因此,我正在做的是导入每个自定义属性,并生成一个特定的字符串,例如“黄色、黑色饰面木材”,这将是一个单选按钮,您可以在订购产品时从中进行选择。现在,当我遇到具有相同“parentid”但不同唯一 id 的产品时,我需要为自定义选项单选按钮生成一个新行,因此如果有另一个产品的颜色为红色,我会以下可供选择:
Red, black finish wood
Yellow, black finish wood
这对于具有相同父 ID 的第一个产品非常有效,换句话说,如果我正在创建一个全新的产品,而不仅仅是向同一产品添加自定义选项。
我的问题是,如何为特定选项生成新的自定义选项值?换句话说,如何向已创建的某个选项添加新行?
这基本上就是我为新产品生成第一个选项所做的事情。
$options = array();
$options[$ParentID] = array(
'title' => 'Option Title',
'type' => 'radio',
'is_require' => 1,
'values' => array()
);
$options[$ParentID]['values'][] = array(
'title' => 'Option Value Title',
'price' => 0.00,
'price_type' => 'fixed',
'sku' => $UniqueID,
);
foreach($options as $ParentID => $option) {
$id = Mage::getModel('catalog/product')->getIdBySku($ParentID);
$product = Mage::getModel('catalog/product')->load($id);
if(!$product->getOptionsReadonly()) {
$product->setProductOptions(array($option));
$product->setCanSaveCustomOptions(true);
$product->save();
}
}
这效果很好,因为当他们以 $ParentID_$UniqueID 格式订购某种产品时,magento 会生成一个 sku,然后我可以将 $UniqueID 发送给订单的供应商。
再次强调,我愿意接受有关如何将选项值添加到已创建的自定义选项的建议
Alright, so I'm working on my own script that reads specific xml files, and imports products. Now, each of these products may have a set of attributes, (i.e. color for example).
So, what I'm doing is importing each custom attribute, and generating a specific string, "Yellow, black finish wood" for example, and that would be a radio button you could select from when you go to order the product. Now, when I come to a product that has the same "parentid" but a different unique id, I need to generate a new row for the custom option radio button, so if there is another product where the color is red, I would have the following to select from:
Red, black finish wood
Yellow, black finish wood
This is working great for the first product with the same parent id, in other words, if I'm creating a brand new product, and not just adding custom options to the same product.
My question is, how do I generate a new custom option value, for the specific option? In other words, how do I add a new row to a certain option that is already created?
Here is basically what I'm doing to generate the first option on a new product.
$options = array();
$options[$ParentID] = array(
'title' => 'Option Title',
'type' => 'radio',
'is_require' => 1,
'values' => array()
);
$options[$ParentID]['values'][] = array(
'title' => 'Option Value Title',
'price' => 0.00,
'price_type' => 'fixed',
'sku' => $UniqueID,
);
foreach($options as $ParentID => $option) {
$id = Mage::getModel('catalog/product')->getIdBySku($ParentID);
$product = Mage::getModel('catalog/product')->load($id);
if(!$product->getOptionsReadonly()) {
$product->setProductOptions(array($option));
$product->setCanSaveCustomOptions(true);
$product->save();
}
}
this works out great, because magento generates an sku when they order a certain product in the format of $ParentID_$UniqueID, and then I can send the $UniqueID off to the vendor for the order.
So again, I'm open to suggestions as to how to add a Option Value to an already created Custom Option
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
加载所有选项并使用唯一且已存在的选项创建数组映射,以使其 id -s 就位
load all options in and create array map with unique and already existing options to get their id -s in place