简体   繁体   English

Magento:在php块中获取产品ID,以在list.phtml中可用

[英]Magento: Get product id in php block for available in list.phtml

I'm trying to get an attribute for it to be listed on list.phtml, the form that is being made is as follows: I created a module on the Block and created a function which captures the attribute: 我正在尝试获取要在list.phtml上列出的属性,其格式如下:我在Block上创建了一个模块,并创建了一个捕获该属性的函数:

    protected function getPreOrder()
{
    $productId = $this->getRequest()->getParam('id');
    $product = Mage::getModel('catalog/product')->load($productId);
    $preOrder = $product->getNewsFromDate();

    $preOrder = substr($preOrder, 0, 10);

    return $preOrder;
}
public function getViewList() 
{
    if(strtotime(date('Y-m-d')) <= strtotime($this->getPreOrder()))
    {
        return true;
    } else {
        return false;
    }

}

However, nothing is returned. 但是,什么也不返回。 I also did this same method to view.phtml and it worked perfectly. 我也对view.phtml使用了相同的方法,并且效果很好。 That goes for a file before the function getChildHtml() phtml, is not being edited list.phtml 这适用于函数getChildHtml()phtml未被编辑list.phtml之前的文件

That makes sense to create a loop, but the loop is already list.phtml! 创建一个循环很有意义,但是循环已经是list.phtml!

What would be the way? 怎么回事? I thank you. 我谢谢你。

Have you debugged your block function to see if the product id is correct and if its loading the model correctly ?? 您是否调试了块函数以查看产品ID是否正确以及是否正确加载了模型? Also debug the template list.phtml to check if its correctly loading the block type ? 还调试模板list.phtml以检查其是否正确加载了块类型?

get_class($this); get_class($ this);

and see what class type is it. 并查看它是什么类类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM