douweida2878 2017-02-23 12:35
浏览 41

将available_date添加到Prestashop中的cart.php

I want to add the product.available_date to the cart in Prestashop 1.6.

I added the following line in shopping-cart-product-line-tpl

{if isset($product.available_date) && $product.available_date > $smarty.now|date_format:'%Y-%m-%d'}
  <span id="availability_date_label">{l s='Availability date:'}</span>
  <span id="availability_date_value">
    {if Validate::isDate($product.available_date)}
    {dateFormat date=$product.available_date full=false}
    {/if}
  </span>

But I found out that the available_date is not set in the Cart.php

I found the following function in cart.php

public function getProducts($refresh = false, $id_product = false, $id_country = null)

that I think is used to collect the product data and it has a sql->select like this:

    // Build query
    $sql = new DbQuery();

    // Build SELECT
    $sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, pl.`name`, p.`is_virtual`,
                    pl.`description_short`, pl.`available_now`, pl.`available_later`, **(added p.`available_date` here)**,product_shop.`id_category_default`, p.`id_supplier`,
                    p.`id_manufacturer`, product_shop.`on_sale`, product_shop.`ecotax`, product_shop.`additional_shipping_cost`,
                    product_shop.`available_for_order`, product_shop.`price`, product_shop.`active`, product_shop.`unity`, product_shop.`unit_price_ratio`,
                    stock.`quantity` AS quantity_available, p.`width`, p.`height`, p.`depth`, stock.`out_of_stock`, p.`weight`,
                    p.`date_add`, p.`date_upd`, IFNULL(stock.quantity, 0) as quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category,
                    CONCAT(LPAD(cp.`id_product`, 10, 0), LPAD(IFNULL(cp.`id_product_attribute`, 0), 10, 0), IFNULL(cp.`id_address_delivery`, 0)) AS unique_id, cp.id_address_delivery,
                    product_shop.advanced_stock_management, ps.product_supplier_reference supplier_reference');

    // Build FROM
    $sql->from('cart_product', 'cp');

    // Build JOIN
    $sql->leftJoin('product', 'p', 'p.`id_product` = cp.`id_product`');
    $sql->innerJoin('product_shop', 'product_shop', '(product_shop.`id_shop` = cp.`id_shop` AND product_shop.`id_product` = p.`id_product`)');
    $sql->leftJoin('product_lang', 'pl', '
        p.`id_product` = pl.`id_product`
        AND pl.`id_lang` = '.(int)$this->id_lang.Shop::addSqlRestrictionOnLang('pl', 'cp.id_shop')
    );

    $sql->leftJoin('category_lang', 'cl', '
        product_shop.`id_category_default` = cl.`id_category`
        AND cl.`id_lang` = '.(int)$this->id_lang.Shop::addSqlRestrictionOnLang('cl', 'cp.id_shop')
    );

    $sql->leftJoin('product_supplier', 'ps', 'ps.`id_product` = cp.`id_product` AND ps.`id_product_attribute` = cp.`id_product_attribute` AND ps.`id_supplier` = p.`id_supplier`');

    // @todo test if everything is ok, then refactorise call of this method
    $sql->join(Product::sqlStock('cp', 'cp'));

    // Build WHERE clauses
    $sql->where('cp.`id_cart` = '.(int)$this->id);
    if ($id_product) {
        $sql->where('cp.`id_product` = '.(int)$id_product);
    }
    $sql->where('p.`id_product` IS NOT NULL');

    // Build ORDER BY
    $sql->orderBy('cp.`date_add`, cp.`id_product`, cp.`id_product_attribute` ASC');

    if (Customization::isFeatureActive()) {
        $sql->select('cu.`id_customization`, cu.`quantity` AS customization_quantity');
        $sql->leftJoin('customization', 'cu',
            'p.`id_product` = cu.`id_product` AND cp.`id_product_attribute` = cu.`id_product_attribute` AND cu.`id_cart` = '.(int)$this->id);
        $sql->groupBy('cp.`id_product_attribute`, cp.`id_product`, cp.`id_shop`');
    } else {
        $sql->select('NULL AS customization_quantity, NULL AS id_customization');
    }

    if (Combination::isFeatureActive()) {
        $sql->select('
            product_attribute_shop.`price` AS price_attribute, product_attribute_shop.`ecotax` AS ecotax_attr,
            IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference,
            (p.`weight`+ pa.`weight`) weight_attribute,
            IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13,
            IF (IFNULL(pa.`upc`, \'\') = \'\', p.`upc`, pa.`upc`) AS upc,
            IFNULL(product_attribute_shop.`minimal_quantity`, product_shop.`minimal_quantity`) as minimal_quantity,
            IF(product_attribute_shop.wholesale_price > 0,  product_attribute_shop.wholesale_price, product_shop.`wholesale_price`) wholesale_price
        ');

        $sql->leftJoin('product_attribute', 'pa', 'pa.`id_product_attribute` = cp.`id_product_attribute`');
        $sql->leftJoin('product_attribute_shop', 'product_attribute_shop', '(product_attribute_shop.`id_shop` = cp.`id_shop` AND product_attribute_shop.`id_product_attribute` = pa.`id_product_attribute`)');
    } else {
        $sql->select(
            'p.`reference` AS reference, p.`ean13`,
            p.`upc` AS upc, product_shop.`minimal_quantity` AS minimal_quantity, product_shop.`wholesale_price` wholesale_price'
        );
    }

    $sql->select('image_shop.`id_image` id_image, il.`legend`');
    $sql->leftJoin('image_shop', 'image_shop', 'image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop='.(int)$this->id_shop);
    $sql->leftJoin('image_lang', 'il', 'il.`id_image` = image_shop.`id_image` AND il.`id_lang` = '.(int)$this->id_lang);

    $result = Db::getInstance()->executeS($sql);

I tried adding p.available_date in the query and got the date, but not if a product have a combination. Then it added same date on both combinations.

Anyone got any idea on how to make it work for combinations as well?

  • 写回答

1条回答 默认 最新

  • dongmeixian9665 2017-02-24 10:02
    关注

    Above query will fetch data by joining cart table with product, category and manufacturer table. There is no join combination in the above query. But you have noticed that system is fetching id_product_attribute with each product from above query and if combination feature is active into store then system already has condition to get combination data as shown below:

    if (Combination::isFeatureActive()) {  
       $sql->select('
                product_attribute_shop.`price` AS price_attribute, product_attribute_shop.`ecotax` AS ecotax_attr,
                IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference,
                (p.`weight`+ pa.`weight`) weight_attribute,
                IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13,
                IF (IFNULL(pa.`isbn`, \'\') = \'\', p.`isbn`, pa.`isbn`) AS isbn,
                IF (IFNULL(pa.`upc`, \'\') = \'\', p.`upc`, pa.`upc`) AS upc,
                IFNULL(product_attribute_shop.`minimal_quantity`, product_shop.`minimal_quantity`) as minimal_quantity,
                IF(product_attribute_shop.wholesale_price > 0,  product_attribute_shop.wholesale_price, product_shop.`wholesale_price`) wholesale_price
            ');
            $sql->leftJoin('product_attribute', 'pa', 'pa.`id_product_attribute` = cp.`id_product_attribute`');
            $sql->leftJoin('product_attribute_shop', 'product_attribute_shop', '(product_attribute_shop.`id_shop` = cp.`id_shop` AND product_attribute_shop.`id_product_attribute` = pa.`id_product_attribute`)');  
    }  else {
            $sql->select(
                'p.`reference` AS reference, p.`ean13`, p.`isbn`,
                p.`upc` AS upc, product_shop.`minimal_quantity` AS minimal_quantity, product_shop.`wholesale_price` wholesale_price'
            );
    }  
    

    To get the combination available date, just add the available date column in select query as shown in below code:

    $sql->select('pa.available_date as combination_available_date, 
            product_attribute_shop.`price` AS price_attribute, product_attribute_shop.`ecotax` AS ecotax_attr,
            IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference,
            (p.`weight`+ pa.`weight`) weight_attribute,
            IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13,
            IF (IFNULL(pa.`isbn`, \'\') = \'\', p.`isbn`, pa.`isbn`) AS isbn,
            IF (IFNULL(pa.`upc`, \'\') = \'\', p.`upc`, pa.`upc`) AS upc,
            IFNULL(product_attribute_shop.`minimal_quantity`, product_shop.`minimal_quantity`) as minimal_quantity,
            IF(product_attribute_shop.wholesale_price > 0,  product_attribute_shop.wholesale_price, product_shop.`wholesale_price`) wholesale_price
        '); 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)