Search code examples
prestashopshopping-cartprestashop-1.6

Aditionnal price to product in prestashop


I am selling drinks in bottles that have a deposit price. The customer has to pay that amount, but can get it back by bringing the bottles to a supermarket. I would like to show the product price without the deposit in the product pages, but when the user checks out his cart, this amount needs to be added to the cart for each item having a deposit. Here are some extra info: Not all products have a deposit The deposit price depends on the product

I managed to add a "deposit" field to the backoffice in the product page:

http://oi57.tinypic.com/6p9s80.jpg

But it seems that changing the whole workflow of the cart check out would be quite a pain. Is there any easy way to achieve this task?

Thanks !


Solution

  • easiest way to do what you want it is using "product attributes combinations" + little code changes, step by step:

    1. create product attribute e.g. "deposit"
    2. add value to it, any,e.g. "yes"
    3. in product create combination with "deposit: yes", set price impact value as you need, e.g. "$10" and set it as default combination
    4. to show on product page price without "deposit" change in themes/themename/js/product.js in function updatePrice() find lines

      // Apply combination price impact // 0 by default, +x if price is inscreased, -x if price is decreased basePriceWithoutTax = basePriceWithoutTax + +combination.price;

    and wrap it into condition:

    if( your_attribute_id != combination.attributes[0] ) {    
        basePriceWithoutTax = basePriceWithoutTax + +combination.price;
    }
    

    but in cart you will see full price.

    UPD:

    1. I see no good way to do it in template, without core changes, so if you need it (solution also not ideal) file controllers/front/CategoryController.php (use override) method assignProductList() change code block to next view:

      foreach ($this->cat_products as &$product) {
          if ($product['id_product_attribute'] && isset($product['product_attribute_minimal_quantity']))
              $product['minimal_quantity'] = $product['product_attribute_minimal_quantity'];
          $combination = new Combination($product['id_product_attribute']);
          $attributes = $combination->getAttributesName($this->context->language->id);
          foreach ($attributes as $attribute) {
              if(your_attribute_id == $attribute['id_attribute'])
                  $product['price_tax_exc'] -= $combination->price;
          }
      }
      

    you will need to repeat it for all lists controllers that you use (and you can do not use foreach but access to array element by index like you already did), in any case solution very project specific, just quick fix, in common case be better use other ways.