Zen Cart custom software development, Zen Cart modules, Zen Cart Expert eCommerce with Zen Cart!


Please note: This is old content; I have not worked on Prestashop since 2009.
Prestashop Better Together

PrestaShop Better Together

A PrestaShop discounting module allowing vendors to promote related items.

Donate: This is free software. Show your appreciation by supporting my efforts. Donate

Relevance: PrestaShop 1.2.4

Cost: Free, but donation appreciated

Download: download link

Current Version: 0.1

Support Thread: Support Thread

FAQ: click here

Installation Instructions: click here

Installation Difficulty: Moderate (I can install most of my mods for a fee)

Overview:

The gold standard of online retailing is Amazon.com. PrestaShop store operators looking to increase their profitability should constantly be asking, "WWAD?" or "What would Amazon do?"

When you look at an item in Amazon, not only is a cross selling recommendation made, a discount is offered to persuade the customer to accept the recommendation. This mod permits you to offer this type of discounted cross selling in your PrestaShop.

You may specify
  • Buy item X, get item Y at a discount
  • Buy item X, get an item from category A at a discount
  • Buy an item from category A, get an item from category B at a discount
  • Buy an item from category A, get item X at a discount

Discounts may be specified as percentages of the latter item's price or as absolute values in the currency your cart uses.

These discount specifications are called "linkages," because they "link" one product or category to another.

In addition, Better Together may be used to facilitate two-for-one offers for identical items. Although it may be argued that this is simply a special case of "buy item X, get item Y at a discount," this capability was added to facilitate two for one offers for an entire category of goods with a single statement. You may specify two-for-one type specials such as
  • Buy item X, get another item X free
  • Buy an item from category A, another identical item free
At the current time, there is no support in the admin panel for Better Together. Discounts must be added by hand using a special syntax by modifying the setup() function in the file modules/better_together.php. Instructions will be provided in this file. In addition, this mod overwrites some PrestaShop core modules, since there is currently no embedded support in PrestaShop for arbitrary discounts (please update my feature request for discounts in PrestaShop to show your support for this idea).

User Interface

The cart block reflects the discount as soon as the item is added to the cart. (Note that Ajax cart must be turned off; see installation instructions.)
Prestashop cart block


On the shopping cart page, the discount is shown below the products.
Prestashop cart block


On the order page, the discount is summed with any other discounts (vouchers).
Prestashop cart block


Admin Interface:

At the current time, there is no support in the admin panel for Better Together. Discounts must be added by hand using a special syntax by modifying the setup() function in the file modules/better_together.php. Instructions will be provided in this file.

Detailed Description:

Four types of linkages may be performed. The format of each of these is the same:
  • first identifier (product or category)
  • second identifier (product or category)
  • "%" or "$" to indicate how discounting is to be done
  • a number, indicating the discount amount.
The four calls for the four types of discounting are
  • add_prod_to_prod()
  • add_prod_to_cat()
  • add_cat_to_cat()
  • add_cat_to_prod()
If a straight two for one discount is what is desired, the calls are
  • add_twoforone_prod()
  • add_twoforone_cat()
Let's consider two products: product 5 from category 3, and product 2 from category 1.

Suppose you want to offer a 50% discount on product 5 with the purchase of product 2. Modify modules/better_together.php and make the setup() function look like this:
   function setup() { 
      $this->add_prod_to_prod(2,5,"%", 50); 
   }

Want to make it buy product 2, get product 5 free?
   function setup() { 
      $this->add_prod_to_prod(2,5,"%", 100); 
   }

How about buy one product 2, get one free?
   function setup() { 
      $this->add_prod_to_prod(2,2,"%", 100); 
   }

Remember product 5 is in category 3. If instead of specifying product 5 in particular, you want to discount any item in category 3 by 20% with the purchase of a product 2 item, use
   function setup() { 
      $this->add_prod_to_cat(2,3,"%", 20); 
   }

Discount can be done in currencies as well. To offer $7 (or 7 of whatever currency your cart uses), use
   function setup() { 
      $this->add_prod_to_cat(2,3,"$", 7); 
   }

(The "$" is just used to specify currency; your cart's currency settings will be respected when computing the discount.)

Remember product 2 is in category 1. If you want to widen the discount to provide a discount of 20% off any item in category 3 when an item from category 1 is purchased, use
   function setup() { 
      $this->add_cat_to_cat(1,3,"%", 20); 
   }

Any number of these discounts may be offered; discount computation will be done in the order in which your discounts are specified in setup(), and items will be processed in the order in which they appear in the cart.

Using the examples above, suppose these items are in your cart:

1 - Product 2, category 1
2 - Product 10, category 1
2 - Product 20, category 3
2 - Product 5, category 3

and suppose you have coded these discounts:
   function setup() { 
      $this->add_prod_to_prod(2,5,"$", 7); 
      $this->add_cat_to_cat(1,3,"%", 25); 
   }

The following discounts will be computed:
  • $7 off ONE product 5 because of ONE product 2 (rule 1)
  • 25% each off TWO product 20 because of TWO product 10 (rule 2)
To get $7 off the second product 5, the customer would need to add a second product 2 to the cart.

With the same cart, coding
   function setup() { 
      $this->add_cat_to_cat(1,3,"%", 25); 
      $this->add_prod_to_prod(2,5,"$", 7); 
   }

Would compute the following discount:
  • 25% off ONE product 20 because of ONE product 2 (rule 1)
  • 25% off ONE product 20 because of ONE product 10 (rule 1)
  • 25% off ONE product 5 because of ONE product 10 (rule 1)
Obviously these could be very different discounts!

To create a two for one discount for product 5, simply code
   function setup() { 
      $this->add_twoforone_prod(5);
   }
And to create two for one discount for all products in category 3, code
   function setup() { 
      $this->add_twoforone_cat(3);
   }


Note the difference between
   function setup() { 
      $this->add_twoforone_cat(3);
   }
and
   function setup() { 
      $this->add_cat_to_cat(3,3,"%", 100); 
   }
The latter says, "buy any item from category three, and get 100% off any other item from category three." The former says, "all items in category three are buy one, get an identical item free." So if a customer bought items 20 and 30 from category three, a discount would only be given in the latter case.

Category Handling

Note that the "category" in add_cat_to_cat(), add_prod_to_cat(), add_cat_to_prod() and add_twoforone_cat() is the by the default category field, as shown in the product editing screen.
Prestashop default category


Installation Instructions:

  1. Back up everything! Try this in a test environment prior to installing it on a live shop.
  2. Copy the contents of the unzipped folder to the root directory of your shop.
    The names of these files reflect a theme name of "custom." If you are using a different theme name, please change file paths using "custom" to use your template name instead. (For instance, if your theme name is "blue", rename "themes/custom" to "themes/blue".)
  3. If you have already made changes to global.css, the only change you need for Better Together is to style id cart_block_bt in the same way as cart_block_total. So you will want something like this:
    #cart_block_bt, #cart_block_wrapping_cost, #cart_block_shipping_cost , #cart_block_total{ padding-right:1.3em; }
    
  4. This version of Better Together is not compatible with Ajax cart. You must turn off Ajax cart as follows:
    1. In Admin > Preferences > Products, set "Re-direction after adding product to cart" to "cart summary".
    2. In Admin > Modules > Blocks > Cart block, press the configure link, and turn off Ajax cart.
  5. Decide on the linkages you wish to use, and add them to the setup() function in modules/better_together.php. Open a shopping cart in another window to test these discounts. They are shown on the second step of checkout in "Your Total" under "Better Together."
  6. Donate! Show your appreciation by supporting my efforts.
  7. Support my petition for an infrastructure in Prestashop for fees and discounts!


If you need help doing this, I'm happy to install this mod for a fee.

Major Versions

  • 0.1 10/11/2009 First Release

FAQ

Q: Why do I have to modify core files?
A: Because there is currently no easy way to create a per cart discount in PrestaShop. However you can help change this by supporting my feature request for a generalized discount creation infrastructure in PrestaShop. I minimized the changes to be made as much as possible. (Part of the reason ajax cart is not supported is to reduce the number of required changes.)

Q: It's a bit tedious to have to type the discounts in; will you build an admin panel?
A: It depends on how many people send me certificates of appreciation. Software development is very time consuming, and like you, I'm running a business.

Q: How do I translate the Better Together strings into my language?
A: Modify themes/YOUR THEME/lang/YOUR_LANGUAGE.php and add
$_LANG['shopping-cart_c8a8773b89ff1864e0a8b7d00e60ae74'] = 'Better Together (in your language)';
Modify modules/blockcart/YOUR_LANGUAGE.php and add
$_MODULE['<{blockcart}prestashop>blockcart_c8a8773b89ff1864e0a8b7d00e60ae74'] = 'Better Together (in your language)';
For instance, in French, you would modify modules/blockcart/fr.php and add
$_MODULE['<{blockcart}prestashop>blockcart_c8a8773b89ff1864e0a8b7d00e60ae74'] = 'Meilleur Ensemble';