0

1) I try to make bundle products throw php in magento 1 and I dont know how to make it to several or more bundle products(in my code only one bundle product) in one script 2) and can u tell me about option_id and selection_id values I must use?

<?php
require_once('includes/config.php');
require_once('app/Mage.php');

$storeID = 1;
$websiteIDs = array(1);
$cats = array("42973");

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$product = Mage::getModel('catalog/product');

$p = array(
  'sku_type' => 0,
  'sku' => '687test', 
  'name' => "testProduct",
  'description' => '', 
  'short_description' => '', 
  'type_id' => 'bundle', 
  'attribute_set_id' => 4, 
  'weight_type' => 0, 
  'visibility' => 4, 
  'price_type' => 0, 
  'price_view' => 0, 
  'status' => 1, 
  'created_at' => strtotime('now'),
  'category_ids' => $cats,
  'store_id' => $storeID,
  'website_ids' => $websiteIDs
);

$stock_data=array(
   'use_config_manage_stock' => 1, 
   'manage_stock' => 1, 
   'is_in_stock' => 1 
);

$product->setData('stock_data',$stock_data);


$product->setData($p);
Mage::register('product', $product);
Mage::register('current_product', $product);


$optionRawData = array();
$optionRawData[0] = array(
  'required' => 1, 
  'option_id' => '', 
  'position' => 0, 
  'type' => 'select', 
  'title' => 'namet',
  'default_title' => 'namet',
  'delete' => '',
);


$selectionRawData = array();
$selectionRawData[0] = array();
$selectionRawData[0][] = array(
  'product_id' => 4, 
  'selection_qty' => 1,
  'selection_can_change_qty' => 1, 
  'position' => 0, 
  'is_default' => 0, 
  'selection_id' => '',
  'selection_price_type' => 0,
  'selection_price_value' => 0.0,
  'option_id' => '',
  'delete' => ''
);

$product->setCanSaveConfigurableAttributes(false);
$product->setCanSaveCustomOptions(true);
$product->setBundleOptionsData($optionRawData);
$product->setBundleSelectionsData($selectionRawData);
$product->setCanSaveBundleSelections(true);
$product->setAffectBundleProductSelections(true);
$product->save();
?>
| improve this question | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.