Jump to content

Cart with virtual and physical products


mauricioarango

Recommended Posts

Hi, I'm working on a very customized prestashop site. Version 1.4.10. The client is selling both physical and virtual products. I'm having 2 main issues:

 

1.

When it is a 'mixed' cart (both physical and virtual) in the carrier selection step a special message has to appear. I can detect when the cart is made up by only virtual products ( $isVirtualCart ) BUT haven't figured out how to detect the presence of both physical and virtual.

 

2.

If it is only a virtual cart the customer receives an email with a donwload link after purchasing and payment being accepted -expected behavior. But if it is a mixed cart the customer is not receiving any download link emails... I checked and the orders show a 'Payment Accepted' status.

 

Any help on these topics would be really appreciated.

 

Thank you so much!

Edited by mauricioarango (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

I'm posting this here in case anyone finds it useful. It applies to PS 1.4.x  ... but I imagine it can be easily adapted to newer versions.

In sum, PS considers a cart virtual only when ALL of its products are virtual (makes sense). If for whatever business logic you need to change this behavior and make the cart virtual when there's at least ONE virtual product then you need to change this:

classes > Cart.php

Line 1497 to 1528:

/**
    * Check if cart contains only virtual products
    * @return boolean true if is a virtual cart or false
    *
    */
    public function isVirtualCart()
    {
        if (!isset(self::$_isVirtualCart[$this->id]))
        {
            $products = $this->getProducts();

            if (!count($products))
                return false;

            $list = '';
            foreach ($products as $product)
                $list .= (int)$product['id_product'].',';
            $list = rtrim($list, ',');

            $n = (int)Db::getInstance()->getValue('
            SELECT COUNT(`id_product_download`) n
            FROM `'._DB_PREFIX_.'product_download`
            WHERE `id_product` IN ('.pSQL($list).') AND `active` = 1');

           
/* CHANGE
                PRESTASHOP defines a cart as virtual when all the products on it are virtual items.
                We need the cart to be taken as virtual when at least only 1 product is virtual
               
                self::$_isVirtualCart[$this->id] = ($n == count($products));
            */
           
            self::$_isVirtualCart[$this->id] = ($n >= 1);

           
           
        }
        return self::$_isVirtualCart[$this->id];
    }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...