首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在magento中使用id方法加载2种产品

无法在magento中使用id方法加载2种产品
EN

Stack Overflow用户
提问于 2013-10-28 06:03:29
回答 1查看 151关注 0票数 0

朋友们,我想用id方法加载两个捆绑产品。这是我写的密码.

代码语言:javascript
复制
<?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的选项).the输出如下所示。

代码语言:javascript
复制
  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

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

EN

回答 1

Stack Overflow用户

发布于 2013-10-28 09:48:40

代码语言:javascript
复制
$bundled = Mage::getModel('catalog/product');

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

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

代码语言:javascript
复制
$stdid  = Mage::getModel('catalog/product')->getIdBySku('123457');
$compid = Mage::getModel('catalog/product')->getIdBySku('123458');
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19628093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档