Magento:在php块中获取list.phtml中可用的产品id
我正在尝试获取一个属性,以便将其列在list.phtml上,正在生成的表单如下所示: 我在块上创建了一个模块,并创建了一个捕获属性的函数:Magento:在php块中获取list.phtml中可用的产品id,list,magento,attributes,List,Magento,Attributes,我正在尝试获取一个属性,以便将其列在list.phtml上,正在生成的表单如下所示: 我在块上创建了一个模块,并创建了一个捕获属性的函数: protected function getPreOrder() { $productId = $this->getRequest()->getParam('id'); $product = Mage::getModel('catalog/product')->load($productId); $preOr
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;
}
}
受保护函数getPreOrder()
{
$productId=$this->getRequest()->getParam('id');
$product=Mage::getModel('catalog/product')->load($productId);
$preOrder=$product->getNewsFromDate();
$preOrder=substr($preOrder,0,10);
返回$preOrder;
}
公共函数getViewList()
{
if(strotime(日期('Y-m-d'))getPreOrder())
{
返回true;
}否则{
返回false;
}
}
但是,没有返回任何内容。我也对view.phtml使用了同样的方法,它工作得非常好。这适用于函数getChildHtml()phtml之前的文件,该文件未被编辑list.phtml
创建一个循环是有意义的,但是循环已经是list.phtml了
怎么办?
谢谢。您是否调试了块函数,以查看产品id是否正确以及其加载模型是否正确?? 还要调试template list.phtml以检查其是否正确加载块类型 获得课程($this)
然后查看它是什么类类型。您好,Meabed,是的,函数通常加载到phtml中。函数getPreOrder()在不同的块中用于相同的目的,但本例中使用的view.phtml运行平稳。我的困难是获取产品id,用于list.phtml,不返回任何内容。非常奇怪的是,由于列表是foreach.I tryMage::registry('current_product')->getId()并返回致命错误:对非对象调用成员函数getId(),然后我尝试$_proId=$this->getProduct()->getId()$_product=Mage::getModel('catalog/product')->load($\u proId);并返回相同的内容。该类从Mage_Core_Block_模板扩展而来。对吗?为什么仅在list.phtml中无法获取产品id?因此这意味着注册表中不存在任何产品!打印出你从请求中获得的ID,看看你是否真的能看到它!回应这个?echo$productId=$this->getRequest()->getParam('id');