无法使用洋红色中的按 ID 加载方法加载 2 个产品


can't load 2 products using load by id method in magento

朋友们,我想使用 load by id 方法加载 2 个捆绑产品。 这是我为此编写的代码...

<?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>"
?>

但我的问题是$opt_std_hd_names 和 $opt_cmp_hd_names 返回相同的输出,它们是我首先加载的产品选项。(在本例中$y.如果我首先放置$x代码,则它会显示 $x) 的选项。输出如下所示。

  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

您可以看到输出是相同的。 为什么会这样?? 请给出您的建议

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

这是引用相同的模型对象,并且您将其用于两个加载操作。每次运行 getIdBySku() 方法时,模型的数据都会被覆盖,引用此模型的每个变量也会被更新。

尝试实例化新对象或以这种方式检索数据:

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