在模块 prestashop 中检索产品
Retrieve a product in a module prestashop
我尝试在 prestashop 的自定义模块中检索具有特定 ID 的产品。
到目前为止,我已经根据我的一个相关问题创建了控制器和视图以及控制器内部 我正在使用以下内容:
public function initContent()
{
$product = new Product();
$this->context->smarty->assign('product',$product);
parent::initContent();
$this->setTemplate('productcustom.tpl');
}
我的问题是如何调用特定的产品?
一个解决方案是在 link 的 URL 或某处插入。然后使用
$id_product = (int)Tools::getValue('id_product');
例如,如果您的模块控制器有一个 link,如下所示:http://example.com/module/mymodule/mycontroller?id_product=1
您可以通过代码向上检索id产品:)
我尝试在 prestashop 的自定义模块中检索具有特定 ID 的产品。
到目前为止,我已经根据我的一个相关问题创建了控制器和视图以及控制器内部
public function initContent()
{
$product = new Product();
$this->context->smarty->assign('product',$product);
parent::initContent();
$this->setTemplate('productcustom.tpl');
}
我的问题是如何调用特定的产品?
一个解决方案是在 link 的 URL 或某处插入。然后使用
$id_product = (int)Tools::getValue('id_product');
例如,如果您的模块控制器有一个 link,如下所示:http://example.com/module/mymodule/mycontroller?id_product=1
您可以通过代码向上检索id产品:)