开发者

Magento custom options: success.. almost!

开发者 https://www.devze.com 2023-02-01 14:42 出处:网络
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).

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 开发者_JAVA技巧$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


load all options in and create array map with unique and already existing options to get their id -s in place

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号