[英]Prestashop 1.7 register smarty related products tag
Introduction 介绍
I need to display related products from a product in a different place than prestashop's deffault (however, the theme needs to be capable to show prestashop's default related products block). 我需要在与prestashop的授权不同的位置显示产品的相关产品(但是,该主题必须能够显示prestashop的默认相关产品框)。
I was searching a lot about this and all I can find are modules, tutorials for <1.6 version
etc. 我在这方面进行了很多搜索,所有我能找到的都是模块,
<1.6 version
教程等。
I'm using 1.7.2
and those examples don't work to me. 我正在使用
1.7.2
,这些示例对我不起作用。
My Expectation : 我的期望 :
Register some smarty to use it after and wherever to display product attributes from a related product I want (individually). 注册一些聪明的人,无论何时何地都可以使用它来显示我想要的(单独)相关产品的产品属性。
For example 例如
{$product.id.accessory.reference}
or {$product.id.accessory.image}
, {$product.id.accessory.reference}
或{$product.id.accessory.image}
,
same with name, description and price. 名称,说明和价格相同。
I suppose it could be 我想可能是
{foreach $accessory ...}
{$accessory.name}
{$accessory.price}
{/foreach}
I'll have only a related product for some products, but i would like to keep a multi-referred product code to ensure it will be useful to everybody. 对于某些产品,我只会有一个相关产品,但是我想保留一个多引用的产品代码,以确保它对每个人都有用。
I'm surprised that prestashop has this functionallity but it's shown on a single place by default (if active) and i didn't found any tag to apply it on another place. 我很惊讶prestashop具有这种功能,但是默认情况下它显示在单个位置(如果处于活动状态),而我没有找到任何标签将其应用于另一个位置。 Using {debug} i can't see accessory, accessories or related on anywhere.
使用{debug},在任何地方都看不到附件,附件或相关内容。
The point is that we need some steps to reach it and i sincerelly don't know prestashop's core, nor how it deals with smarty or database. 关键是我们需要采取一些步骤来实现它,我真不知道prestashop的核心,也不知道它如何处理smarty或数据库。 I would like to code a custom shop but this is where i'm working now...
我想为一家自定义商店编写代码,但这是我现在正在工作的地方...
i tried this answer but i can't reach the expected: Prestashop: How to get accessories for product 我尝试了这个答案,但我达不到预期: Prestashop:如何获取产品配件
Any help will be great, thanks! 任何帮助将是巨大的,谢谢!
* EDIT * *编辑*
I tried accessing the public static function through smarty {Product::getAccessoriesLight(intval($cookie->id_lang), $product.id)}
我试图通过smarty
{Product::getAccessoriesLight(intval($cookie->id_lang), $product.id)}
访问公共静态函数。
if i var_dump it: 如果我var_dump它:
{Product::getAccessoriesLight(intval($cookie->id_lang), $product.id)|@var_dump}
I get: 我得到:
array(1) { [0]=> array(3) { ["id_product"]=> string(3) "963" ["reference"]=> string(15) "CFPS SAH0-M11-L" ["name"]=> NULL } } array(1){[0] => array(3){[“” id_product“] => string(3)” 963“ [” reference“] => string(15)” CFPS SAH0-M11-L“ [”名称“] => NULL}}
so it's working for getting the product id and the reference, not taking the name (donno why). 因此,它用于获取产品ID和参考,而不是使用名称(不知道为什么)。 I'll try another function so and try to discover how to show a single value.
我将尝试另一个函数,然后尝试发现如何显示单个值。
** SOLVED ** **已解决 **
prestashop return an array of objects or objects with arrays. prestashop返回对象数组或带有数组的对象。 Sometimes an array with only a position and this position is an array too.
有时只有一个位置的数组,这个位置也是一个数组。 Smarty deals with arrays starting at position 1 depending on the case.
Smarty根据情况处理从位置1开始的数组。 It's all a bit confusing logically.
从逻辑上来说,这一切都有些混乱。
What i did: 我做了什么:
create a public static method to access non-static ones (example 1) or create a static method to query something and get results (in which case, using executeS you'll receive the bulk data like the example 2: 创建一个公共静态方法来访问非静态方法(示例1)或创建一个静态方法来查询某些事物并获取结果(在这种情况下,使用executeS您将像示例2一样接收批量数据:
{assign var=foo value=Product::getSomethingNew($product.id)}
returns 回报
Object(Product)->values|attrArray->values
in which case, you can do {$foo.value}
or {assign var=data value=$foo->attrArray}
then {$data.value}
在这种情况下,您可以执行
{$foo.value}
或{assign var=data value=$foo->attrArray}
然后执行{$data.value}
In the second case, you'll get: 在第二种情况下,您将获得:
Array[1]->array[data] so you can simply: {$foo[1].value}
And obviously, it works wherever you need as you create your own methods to access data. 显然,当您创建自己的访问数据的方法时,它可以在您需要的任何地方工作。
I didn't found the logic or the reason for some arrays to being null at 0 index but having values from index 1 and others start normally at index 0 but... I was getting different attribute values on a product object for the same ID so i don't mind on investigate too much on prestashop. 我没有发现某些数组在0索引处为空但从索引1开始具有值且其他值通常从索引0开始为逻辑的逻辑或原因,但是...我在相同ID的乘积对象上获得了不同的属性值所以我不介意在prestashop上进行过多调查。 It seems a school project that went too far...
看来一个学校项目做得太过分了...
Hope it helps someone. 希望它可以帮助某人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.