Magento Forum

Add and update custom products to simple products in different stores
 
conversion_os
Jr. Member
 
Total Posts:  3
Joined:  2011-07-29
 

Hi folks,

I’m developing a module which adds custom options to products in dependence of some values of the product itself. No problem to add custom options with just a few lines of code. But I do have problems making different prices and labels to the options for each store.

There are 2 stores. All products should have the same options in both stores, but different labels and different prices.

My idea was to first add the options to all products and the update the options in the second store. After trying a lot I gave up. A good advice would help me to go on.

I add the options to all products with:

$opt Mage::getModel('catalog/product_option');
    
$opt->setProduct($product);
    
    
$options = array(
            
'is_require' => true,
            
'sort_order' => '1',
            
'title' => $label,
            
'type' => 'drop_down',
            
'values' => array()
    );
    
    foreach(
$sizes as $size{
    
        
if($size == $defaultSize{
            $additionalAmount 
0;
        
}else {
            $additionalAmount 
calculateOptionPrice($formulaId$originalPrice$size$defaultSize);
        
}
        
        $options[
'values'][] = array(
                
'price' => $additionalAmount,
                
'price_type' => 'fixed'// 'percent'
                
'sku' => '',
                
'sort_order' => '0',
                
'title' => $size,
        );
    
}
    $opt
->addOption($options);
    
$opt->saveOptions();
    
    
$product->setHasOptions(1);
    
$product->save();

And now I thought that I could update the options with other prices and labels loading the product with the specific store id:

$product Mage::getModel('catalog/product')->setStoreId(1)->load($product->getId());

A hint would be much appreciated and would help a lot…

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top