Note that there are some explanatory texts on larger screens.

plurals
  1. POProgramatically added bundle product isn't showing up in frontend
    primarykey
    data
    text
    <p>I am trying to insert bundled products to the Magento database from a PHP script. The version in question is Community 1.5.1.0. </p> <p>I tried the method described in the question "<a href="https://stackoverflow.com/questions/3108775/programmatically-add-bundle-products-in-magento-using-the-sku-id-of-simple-ite">Programmatically add Bundle Products in Magento, using the SKU / ID of Simple Items</a>". The inserted products show up nicely in the administration section -- I can edit them, add new options and selections etc. However, they are not showing up at all in the Magento frontend no matter what I try - e.g. rebuilding indexes or re-saving them from the back-end. Adding bundles through the administration interface works fine.</p> <p>After some digging through the database, I noticed there are no necessary entries in the <code>catalog_product_index_price</code> and <code>catalog_product_index_price_bundle_idx</code> tables when using my script, while adding the bundle through the back-end updates the indexes normally. Re-indexing simply ignores the added bundle product as far as those tables are concerned.</p> <p>I dug through the Magento source files and can't find any hints on what I'm doing wrong. All caches are disabled, selections are in stock, and I tried to include all data I dug up while studying the POST request Magento sends while inserting the product in the back-end.</p> <p>Here's the complete script I use for testing, along with some desperate attempts commented out at the bottom: <pre><code>$magentoPath = '/home/nikola/bin/magento-1.5/'; require_once($magentoPath . 'includes/config.php'); require_once($magentoPath . 'app/Mage.php'); $storeID = 1; $websiteIDs = array(1); $mageObj = Mage::app()-&gt;setCurrentStore($storeID); $product = Mage::getModel('catalog/product'); $cats = array("210"); $p = array( 'sku_type' =&gt; 0, 'sku' =&gt; 687, 'name' =&gt; "BarProduct", 'description' =&gt; 'Foo', 'short_description' =&gt; 'Bar', 'type_id' =&gt; 'bundle', 'attribute_set_id' =&gt; 4, 'weight_type' =&gt; 0, 'visibility' =&gt; 4, 'price_type' =&gt; 0, 'price_view' =&gt; 0, 'status' =&gt; 1, 'created_at' =&gt; strtotime('now'), 'category_ids' =&gt; $cats, 'store_id' =&gt; $storeID, 'website_ids' =&gt; $websiteIDs ); $product-&gt;setData($p); $product-&gt;setCanSaveBundleSelections(true); $product-&gt;setCanSaveCustomOptions(true); Mage::register('product', $product); Mage::register('current_product', $product); $optionRawData = array(); $selectionRawData = array(); $optionRawData[0] = array( 'required' =&gt; 1, 'option_id' =&gt; '', 'position' =&gt; 0, 'type' =&gt; 'select', 'title' =&gt; 'FooOption', 'default_title' =&gt; 'FooOption', 'delete' =&gt; '' ); $selectionRawData[0] = array(); $selectionRawData[0][] = array( 'product_id' =&gt; 1810, 'position' =&gt; 0, 'is_default' =&gt; true, 'selection_id' =&gt; '', 'option_id' =&gt; '', 'selection_price_type' =&gt; 0, 'selection_price_value' =&gt; 0.0, 'selection_qty' =&gt; 1, 'selection_can_change_qty' =&gt; 1, 'delete' =&gt; '' ); $product-&gt;setBundleOptionsData($optionRawData); $product-&gt;setBundleSelectionsData($selectionRawData); $product-&gt;save(); /* $stockItem = Mage::getModel('cataloginventory/stock_item'); $stockItem-&gt;loadByProduct($product-&gt;getId()); if (!$stockItem-&gt;getId()) { $stockItem-&gt;setProductId($product-&gt;getId())-&gt;setStockId(1); } $stockItem-&gt;setData('is_in_stock', 1); $stockItem-&gt;save(); $pi = Mage::getSingleton('bundle/price_index'); $pi-&gt;addPriceIndexToProduct($product); $pi-&gt;save(); */ ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload