如何在产品组合标签中添加自定义字段在Prestashop中显示前端的值?

时间:2015-07-12 09:23:20

标签: javascript php prestashop-1.6

我是一个关于黄麻产品和圆顶的网站,其功能因产品的属性而异。 所以我需要做的是在组合选项卡中添加自定义字段,然后在前端显示此字段的值以及产品功能。 在我的PS 1.6.0.14安装中,我设法成功添加字段并从后台填充它但它没有保存的值(它在页面重新加载时消失)。 我做的是:(该字段的名称是每包装包装)

  • 在ps_product_attribute表中添加了batch_per_bale列作为varchar(250)。

  • 在主题文件夹中修改了Combination.tpl,为每个打包打包添加字段

<div class="form-group">
<label class="control-label col-lg-3" for="attribute_packing_per_bale">
{l s='Packing Per Bale'}
</label>
<div class="col-lg-5">
<input maxlength="250" type="text" id="attribute_packing_per_bale" name="attribute_packing_per_bale" value="" />
</div>
</div>

  • 修改了Combination.php以声明变量&amp;定义它。

    59. public $packing_per_bale;

    75. 'packing_per_bale' => array('type' => self::TYPE_STRING, 'size' => 250),

  • 修改后的Product.php:a)在addProductAttribute函数中

    public function addProductAttribute($price, $weight, $unit_impact, $ecotax, $quantity, $id_images, $reference, $packing_per_bale,
        $id_supplier = null, $ean13, $default, $location = null, $upc = null, $minimal_quantity = 1)
    {
        Tools::displayAsDeprecated();
    
        $id_product_attribute = $this->addAttribute(
            $price, $weight, $unit_impact, $ecotax, $id_images,
            $reference, $packing_per_bale, $ean13, $default, $location, $upc, $minimal_quantity
        );
    

b)在addCombinationEntity函数

public function addCombinationEntity($wholesale_price, $price, $weight, $unit_impact, $ecotax, $quantity,
        $id_images, $reference, $packing_per_bale, $id_supplier, $ean13, $default, $location = null, $upc = null, $minimal_quantity = 1,  array $id_shop_list = array(), $available_date = null)
    {
        $id_product_attribute = $this->addAttribute(
            $price, $weight, $unit_impact, $ecotax, $id_images,
            $reference, $packing_per_bale, $ean13, $default, $location, $upc, $minimal_quantity, $id_shop_list, $available_date);
        $this->addSupplierReference($id_supplier, $id_product_attribute);

c)在updateAttribute函数中

public function updateAttribute($id_product_attribute, $wholesale_price, $price, $weight, $unit, $ecotax,
        $id_images, $reference, $packing_per_bale, $ean13, $default, $location = null, $upc = null, $minimal_quantity = null, $available_date = null, $update_all_fields = true, array $id_shop_list = array())
    {
        $combination = new Combination($id_product_attribute);

        if (!$update_all_fields)
            $combination->setFieldsToUpdate(array(
                'price' => !is_null($price),
                'wholesale_price' => !is_null($wholesale_price),
                'ecotax' => !is_null($ecotax),
                'weight' => !is_null($weight),
                'unit_price_impact' => !is_null($unit),
                'default_on' => !is_null($default),
                'minimal_quantity' => !is_null($minimal_quantity),
                'available_date' => !is_null($available_date),
            ));

        $price = str_replace(',', '.', $price);
        $weight = str_replace(',', '.', $weight);

        $combination->price = (float)$price;
        $combination->wholesale_price = (float)$wholesale_price;
        $combination->ecotax = (float)$ecotax;
        $combination->weight = (float)$weight;
        $combination->unit_price_impact = (float)$unit;
        $combination->reference = pSQL($reference);
        $combination->packing_per_bale = pSQL($packing_per_bale);
        $combination->location = pSQL($location);
        $combination->ean13 = pSQL($ean13);
        $combination->upc = pSQL($upc);
        $combination->default_on = (int)$default;
        $combination->minimal_quantity = (int)$minimal_quantity;
        $combination->available_date = $available_date ? pSQL($available_date) : '0000-00-00';

d)在addAttribute函数

public function addAttribute($price, $weight, $unit_impact, $ecotax, $id_images, $reference, $packing_per_bale, $ean13,
                                 $default, $location = null, $upc = null, $minimal_quantity = 1, array $id_shop_list = array(), $available_date = null)
    {
        if (!$this->id)
            return;

        $price = str_replace(',', '.', $price);
        $weight = str_replace(',', '.', $weight);

        $combination = new Combination();
        $combination->id_product = (int)$this->id;
        $combination->price = (float)$price;
        $combination->ecotax = (float)$ecotax;
        $combination->quantity = 0;
        $combination->weight = (float)$weight;
        $combination->unit_price_impact = (float)$unit_impact;
        $combination->reference = pSQL($reference);
        $combination->packing_per_bale = pSQL($packing_per_bale);
        $combination->location = pSQL($location);
        $combination->ean13 = pSQL($ean13);
        $combination->upc = pSQL($upc);
        $combination->default_on = (int)$default;
        $combination->minimal_quantity = (int)$minimal_quantity;
        $combination->available_date = $available_date;

e)在getAttributesGroups函数中

public function getAttributesGroups($id_lang)
    {
        if (!Combination::isFeatureActive())
            return array();
        $sql = 'SELECT ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name,
                    a.`id_attribute`, al.`name` AS attribute_name, a.`color` AS attribute_color, product_attribute_shop.`id_product_attribute`,
                    IFNULL(stock.quantity, 0) as quantity, product_attribute_shop.`price`, product_attribute_shop.`ecotax`, product_attribute_shop.`weight`,
                    product_attribute_shop.`default_on`, pa.`reference`, pa.`packing_per_bale`, product_attribute_shop.`unit_price_impact`,
                    product_attribute_shop.`minimal_quantity`, product_attribute_shop.`available_date`, ag.`group_type`
                FROM `'._DB_PREFIX_.'product_attribute` pa
  • 修改过的Productcontroller

功能processProductAttribute:

    886.  Tools::getValue('attribute_plazo_envio'),

    918.  Tools::getValue('attribute_plazo_envio'),

函数initFormInformations:

array_push($product_props, 'reference', 'plazo_envio', 'ean13', 'upc',
        'available_for_order', 'show_price', 'online_only',
        'id_manufacturer'
        );

函数renderListAttributes:

$comb_array[$combination['id_product_attribute']]['plazo_envio'] = $combination['plazo_envio'];
  • Modified ProductsController.php:

function assignAttributesGroups:

464. $combinations[$row['id_product_attribute']]['plazo_envio'] = $row['plazo_envio'];
  • 修改了product.js

a)在函数editProductAttribute

291.  var packing_per_bale = data[0]['packing_per_bale']

b)在fillCombination函数声明中添加packing_per_bale作为争论

c)在fillCombination函数

this.fillCombination = function(wholesale_price, price_impact, weight_impact, unit_impact, reference, packing_per_bale,
    ean, quantity, image, old_attr, id_product_attribute, default_attribute, eco_tax, upc, minimal_quantity, available_date)
    {
        var link = '';
        self.init_elems();
        $('#stock_mvt_attribute').show();
        $('#initial_stock_attribute').hide();
        $('#attribute_quantity').html(quantity);
        $('#attribute_quantity').show();
        $('#attr_qty_stock').show();

        $('#attribute_minimal_quantity').val(minimal_quantity);

        getE('attribute_reference').value = reference;

        getE('attribute_packing_per_bale').value = packing_per_bale;

结果是我在编辑组合时可以在文本框中成功添加文本,我可以在文本框中填写,按页面加载时保存但是后台的文本框为空。

我希望有人可以帮助我完成这项任务,我似乎非常接近于管理它。

0 个答案:

没有答案