donglu7816
2013-12-01 15:53
浏览 50
已采纳

我在哪里可以找到Magento中函数的定义?

I'm helping a friend with his Magento website and I have very little PHP and Magento experience. I haven't had to do too much when it comes to the actual code, but there's one change we want to make that actually involves changing code.

The code contains something like this:

$model = Mage::getModel('catalog/product');
$_product = $model->load($entity_id);
$bedroom = $_product->getTotalrooms();

The above works fine, and I'd like to add the following:

enter code here`$bathroom = $_product->getTotalbathrooms();

I've added totalbathrooms to the Attributes page and tried to make it identical to totalrooms, the only difference I see right now is that in the System column, for totalrooms it says Yes but for totalbathrooms it says No. I've updated the html in the forms to add new places and updated the html of the product page, but currently it isn't displaying the no. of bathrooms. You can see an example product here: http://book.bnbtlv.com/index.php/bathroom-test.html. If you scroll to the middle of the page, you'll notice that there's no value for bathrooms. Bedrooms is 4 however.

One question I have is whether getTotalrooms was defined anywhere or if it was created automatically somehow? If it was defined manually, then where would is that so I can also define getTotalbathrooms there? Also, where would I find the place where setTotalrooms is called? I'm guessing that setTotalbathrooms is never called for my products at the moment.

Lastly, when I go to the Manage Products page on the admin page and click on a product and then click Product Information, I see the no of rooms, but I don't see the number of bathrooms. How can I get the number of bathrooms to display on this page and be editable by the admin?

Thanks

图片转代码服务由CSDN问答提供 功能建议

我正在用他的Magento网站帮助一个朋友,我的PHP和Magento体验很少。 在实际代码方面我没有做太多的事情,但我们想要做的一件事实际上涉及更改代码。

代码包含这样的内容:< / p>

  $ model = Mage :: getModel('catalog / product'); 
 $ _product = $ model-&gt; load($ entity_id); 
 $ bedroom = $  _product-&gt; getTotalrooms(); 
   
 
 

以上工作正常,我想添加以下内容:

 在这里输入代码`$ bathroom = $ _product-&gt; getTotalbathrooms(); 
   
 
 

我已将totalbathrooms添加到“属性”页面并尝试制作 它与整个房间相同,我现在看到的唯一区别是,在系统栏中,对于总房间,它说是,但是对于总浴室,它说没有 我已更新表格中的html以添加新地点并更新了html 产品页面,但目前它没有显示否。 浴室。 您可以在此处查看示例产品: http://book.bnbtlv 的.com / index.php的/浴室-的test.html 。 如果您滚动到页面中间,您会发现浴室没有价值。 但是卧室是4。

我有一个问题是getTotalrooms是在任何地方定义的,还是以某种方式自动创建的? 如果它是手动定义的,那么那里我也可以在那里定义getTotalbathrooms? 另外,在哪里可以找到调用setTotalrooms的地方? 我猜测目前我的产品从未调用过setTotalbathrooms。

最后,当我转到管理页面上的“管理产品”页面并单击某个产品然后单击“产品”时 信息,我看到没有房间,但我没有看到浴室的数量。 如何获得此页面上显示的浴室数量并可由管理员编辑?

谢谢

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dronthpi05943 2013-12-01 17:06
    已采纳

    Firstly, getTotalRooms() is not defined anywhere in nmagento, it gets picked up from the attribute you created.

    I think your problem is that you have missed out adding the created attribute to your attribute set and then re-index data, using the re-indexing options.

    After creating attribute on the attribute page you will need to add that Attribute to the attribute set that your product is using.

    Refer to this video : http://www.youtube.com/watch?v=MqhCcCpR4DI

    打赏 评论
  • douchun5969 2013-12-01 19:26

    $_product->getTotalrooms() is part of Magento's Magic getter-setter methods, that works on that data object of the Model instance.

    print_r($_product->getData()); will give you idea of all the data associated with your product. You can get any data directly by

    $_product->getData('my_attribute'); OR $_product->getMyAttribute();

    Naming conviction is that first letter be uppercase than letter just after underscore be uppercase after ->get.

    And same goes with setter methods. $_product->setTotalrooms('5')->save(); Will save totalrooms field to 5 for your product.

    I think problem you are facing at $bathroom = $_product->getTotalbathrooms(); is that you are using wrong Naming here. Check print_r($_product->getData()); and correct it.

    打赏 评论

相关推荐 更多相似问题