Question

Friends, I wanna load 2 bundle products using load by id method. this is the code that i have written for that...

<?php
$bundled = Mage::getModel('catalog/product');
$stdid=$bundled->getIdBySku('123457');
$compid=$bundled->getIdBySku('123458');

/*get additional options of the each products*/
 $y=$bundled->load($compid);
 $selectionCollection_complete = $y->getTypeInstance(true)->getSelectionsCollection(
            $y->getTypeInstance(true)->getOptionsIds($y), $y);

$x=$bundled->load($stdid);
$selectionCollection_standard = $x->getTypeInstance(true)->getSelectionsCollection(
            $x->getTypeInstance(true)->getOptionsIds($x), $x);


 /*store the option head name to an array for future 
  reference*/            
 foreach($selectionCollection_standard as $std_opt)
 {
    $opt_std_hd_names.=$std_opt->getName()."<BR>";
 }
 foreach($selectionCollection_complete as $cmp_opt)
 {
   $opt_cmp_hd_names.=$cmp_opt->getName()."<BR>";
 }


 $display="<pre>".print_r($opt_std_hd_names."<br><br>".$opt_cmp_hd_names)."</pre>"

?>

but my problem is $opt_std_hd_names and $opt_cmp_hd_names returns the same output and they are those options of product which i have loaded first.(in this case $y. if i place the $x code at first, then it displays options of $x).the output is shown below.

 output:

   Preparation and Filing of Incorporation Documents
   Verify Business Name Availability
   Unlimited Phone/Email Support
   24/7 Access to Our Online Status Center
   FREE Registered Agent Service for 6 Months
   BizComply (free with your Registered Agent Service)
   500 Four-Color Business Cards
   Business License Application Package
   Palo Alto's Business Plan Pro


   Preparation and Filing of Incorporation Documents
   Verify Business Name Availability
   Unlimited Phone/Email Support
   24/7 Access to Our Online Status Center
   FREE Registered Agent Service for 6 Months
   BizComply (free with your Registered Agent Service)
   500 Four-Color Business Cards
   Business License Application Package
   Palo Alto's Business Plan Pro

you can see the outputs are same. why it happens like this?? please give your suggestions

Was it helpful?

Solution

Try loading the products this way:

$y=Mage::getModel('catalog/product')->load($compid);
//and
$x=Mage::getModel('catalog/product')->load($stdid);

I have a feeling that using the same instance of Mage_Catalog_Model_Product ($bundled in your case) leads to value being overwritten.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top