我正在Prestashop中创建一个网站,下一个是我的问题:
我在db(mysql)中创建了一个名为'tallas'的新表,并且具有用户的大小首选项。现在,我需要从product-variants.tpl页开始调用该表,因为我希望将客户选择的选项作为默认值。
我在classes / Product.php中创建此函数
public function getTalla($id_customer){
$result = Db::getInstance()->ExecuteS('
SELECT `talla1`
FROM `tallas`
WHERE `cliente` = `$id_customer`');
return $result;
}
好吧,我想为参数接收用户ID(我还不知道该怎么做),我想接收talla1
的值,然后我想把这个选项由客户在电台的theme / asmart / templates / catalog / _partials / product-variants.tpl中选择。
<li class="float-xs-left input-container">
<label>
<input class="input-color" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span
{if $group_attribute.html_color_code}class="color" style="background-color: {$group_attribute.html_color_code}" {/if}
{if $group_attribute.texture}class="color texture" style="background-image: url({$group_attribute.texture})" {/if}
><span class="sr-only">{$group_attribute.name}</span></span>
</label>
</li>
真心的我对此一无所知,有人可以帮我吗?
更新:问题已解决!
问题已解决。我这样做:
在classes / Product.php
中public function getTalla(){
$variable = Context::getContext()->customer->id;
$result = Db::getInstance()->ExecuteS('SELECT * FROM `tallas` WHERE `cliente` = `$variable`');
return $result;
}
在ProductController.php中
$this->context->smarty->assign('images_ex',$this->product->getTalla());
在product-variants.tpl
中{if $images_ex[0]['talla1'] == $group_attribute.name} checked="checked"{/if}
我希望这可以在将来对某人有所帮助。