在管理产品页面中使用自定义字段复选框 - PrestaShop 1.6

问题描述 投票:0回答:2

我在产品管理页面中有一个自定义字段(复选框):

Informations.tpl:

    <div class="form-group">
    <div class="col-lg-1">
        <span class="pull-right">{include file="controllers/products/multishop/checkbox.tpl" field="is_exclusive" type="checkbox" multilang="false"}</span></div>
    <label class="control-label col-lg-2" for="is_exclusive">
        <span class="label-tooltip" data-toggle="tooltip" title="{l s='Is Exclusive'}">
            {l s='Is Exclusive ?'}
        </span>
    </label>
    <div class="col-lg-9">
        <input class="admin-form-check form-control" type="checkbox" id="is_exclusive" name="is_exclusive" value="1" {if $product->is_exclusive}checked{/if}/>
    </div>
</div>

并将其添加到override/classes/Product.php

public $is_exclusive = false;
    function __construct( $id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null ) {
         Product::$definition['fields']['is_exclusive'] = 
                array('type' => self::TYPE_BOOL, 'lang' => false, 'validate' => 'isBool');

我需要一种方法来捕获未选中复选框并将字段指定为0。

我创建了override/controllers/admin/AdminProductsController.php

class AdminProductsController extends AdminProductsControllerCore {
    protected function copyFromPost(&$object, $table) {
        if ( $this->isTabSubmitted( 'Informations' ) ) {
            if ( $this->checkMultishopBox( 'is_exclusive', $this->context ) ) {
                $object->is_exclusive = (int) Tools::getValue( 'is_exclusive' );
            }

        }
    }
}

但这并不能解决问题。

prestashop prestashop-1.6 prestashop-1.7 prestashop-1.5
2个回答
1
投票

解决方案是删除缓存文件:cache/class_index.php


0
投票

是的在Prestashopp 1.6 =>解决方案是删除缓存文件:cache/class_index.php在prestashop 1.7 =>解决方案是删除缓存文件:var/cache/class_index.php

问候

© www.soinside.com 2019 - 2024. All rights reserved.