强制推出产品和购物车的特定价格(bug)

时间:2018-03-19 09:17:13

标签: module prestashop prestashop-1.6

我为客户及其购物车选择的产品添加特定价格。 我这样做:

if (!$this->context->cart->id) {
    if (Context::getContext()->cookie->id_guest) {
        $guest = new Guest(Context::getContext()->cookie->id_guest);
        $this->context->cart->mobile_theme = $guest->mobile_theme;
    }

    $this->context->cart->add();

    if ($this->context->cart->id) {
        $this->context->cookie->id_cart = (int)$this->context->cart->id;
    }
}

$this->product = new Product($id_prod, true, (int)($this->context->cookie->id_lang));

$authorized_text_fields = array();

if (!$field_ids = $this->product->getCustomizationFieldIds()) {
    return false;
}

foreach ($field_ids as $field_id) {
    if ($field_id['type'] == Product::CUSTOMIZE_TEXTFIELD) {
        $authorized_text_fields[(int) $field_id['id_customization_field']] = 'test';
    }

    $indexes = array_flip($authorized_text_fields);

    $this -> context -> cart -> addTextFieldToProduct($this -> product -> id, $indexes['test'], Product::CUSTOMIZE_TEXTFIELD, $customData);

    $texts = $this -> context -> cart -> getProductCustomization($this -> product -> id, Product::CUSTOMIZE_TEXTFIELD, true);
    $text_fields = array();
    foreach($texts as $text_field) {
        $text_fields['textFields_'.$this->product -> id. '_'.$text_field['index']] =
        str_replace('<br />', "\n", $text_field['value']);
    }

    $this -> context -> cart -> updateQty((int) ($qty), (int) ($id_prod), (int) ($ipa), (int) $texts['id_customization'], 'up');
    $this -> context -> cart -> save();

    // Prix spécifique
    $specific_price = new SpecificPrice();
    $specific_price -> id_product = (int) $id_prod; // choosen product id
    $specific_price -> id_product_attribute = (int) $ipa;
    $specific_price -> id_cart = (int) $this -> context -> cart -> id;
    $specific_price -> id_shop = (int) $this -> context -> shop -> id;
    $specific_price -> id_currency = 0;
    $specific_price -> id_country = 0;
    $specific_price -> id_group = 0;
    $specific_price -> id_customer = 0;
    $specific_price -> from_quantity = 1;
    $specific_price -> price = (float) $new_price;
    $specific_price -> reduction_type = 'amount';
    $specific_price -> reduction_tax = 1;
    $specific_price -> reduction = 0;
    $specific_price -> from = date("Y-m-d H:i:s");
    $specific_price -> to = '0000-00-00 00:00:00'; // or set date x days from now
    $specific_price -> add();

    $this -> context -> cart -> save();
}

在我的数据库中,使用特定id_product和商品id_cart成功创建了特定价格。

但是当我去购物车时,我的具体价格没有出现...... 我必须重复解决方案(在具有相同参数的特定价格表中创建第二行)以查看购物车中的具体价格。

你知道为什么吗?

0 个答案:

没有答案