PrestaShop

Integration is easy using our provided module. Currently, we support PrestaShop 1.7 and above. The latest version can be downloaded here:

https://cdn.fanplayr.com/integrations/prestashop/packages/prestashop-1.2.0.zip

Installation

  • Log into your PrestaShop admin

  • Go to Modules and Services

  • Click the Add a new module button at the top right

  • Click Choose a file and select the PrestaShop module you downloaded.

  • Click Upload this module

The module should now be added to your PrestaShop store. You still need to find it and _Install _it though.

  • Scroll down and click on the Pricing and Promotion section of modules

  • You should now see Fanplayr Conversions listed.

  • Click the Install button.

  • Once installed you should see the configuration screen for Fanplayr.

  • Enter your Account Key and a Session Offer Prefix (see below)

  • Click Save

Fanplayr should now be tracking users and orders on your site!

Session Offers

Fanplayr has the ability to stop your users from using Fanplayr coupon codes that they were not given through the Fanplayr system. For details on how this works see, Session Offers.

Because PrestaShop does not allow modification of core functionality via modules you will need to add the following code to one of your controllers.

Prestashop 1.6 and above :

The controller can be found here: controllers/front/ParentOrderController.php

Around line 102 you will find the following code:

if ($this->nbProducts) {
    if (CartRule::isFeatureActive()) {
        if (Tools::isSubmit('submitAddDiscount')) {
        // INSERT THE CODE HERE

Prestashop 1.7 :

The controller can be found here: controllers/front/CartController.php

Around line 238, inside function updatecart() you will find the following code:

protected function updateCart()
    {
        // Update the cart ONLY if $this->cookies are available, in order to avoid ghost carts created by bots
        if ($this->context->cookie->exists()
            && !$this->errors
            && !($this->context->customer->isLogged() && !$this->isTokenValid())
        ) {
            if (Tools::getIsset('add') || Tools::getIsset('update')) {
                $this->processChangeProductInCart();
            } elseif (Tools::getIsset('delete')) {
                $this->processDeleteProductInCart();
            } elseif (CartRule::isFeatureActive()) {
                if (Tools::getIsset('addDiscount')) {
                // INSERT THE CODE HERE

Please enter the following Fanplayr code directly below this line:

/*
    ------------------------------------------------------------------
    begin Fanplayr Session Offers
*/
$fanplayrSessionOfferPrefix = strtolower(Tools::getValue('fanplayr_prefix', Configuration::get('FANPLAYR_CONFIG_PREFIX')));
@$allowedCoupons = (array)json_decode($_COOKIE['fanplayr_so']);
$code = strtolower(trim(Tools::getValue('discount_name')));
if ( !is_array($allowedCoupons) ) {
    $allowedCoupons = [];
}
// if we have a Session Offer Prefix AND the code entered has this prefix AND the code is not in allowed coupons
if (strlen($fanplayrSessionOfferPrefix) > 0 &&
    strpos($code, $fanplayrSessionOfferPrefix) === 0 &&
    !array_key_exists($code, $allowedCoupons)
) {
    // then we clear the coupon from GET and POST variables
    $_POST['discount_name'] = '';
    $_GET['discount_name'] = '';
}
/*
    ------------------------------------------------------------------
    end Fanplayr Session Offers
*/

You should now not be able to use coupons that start with the Session Offer Prefix set when configuration your Fanplayr module, unless you have collected this coupon from a Fanplayr campaign.

Testing Session Offers

To test that Session Offers has been implemented correctly try the following:

  1. In the Fanplayr Configuration set a value for "Session Offer Prefix". For example, FP_.

  2. Create a coupon with this prefix, i.e. FP_10OFF.

  3. Apply this coupon to the cart. It should fail.

  4. Visit the URL that allows this coupon, i.e: https://mystore.com/modules/fanplayr/api.php?coupon&sessionOffer&code=FP_10OFF This should allow the coupon to be used in the current session.

  5. Apply this coupon again. This time it should apply successfully.

If the coupon does not fail at step 3. you may have to change another line of code. Try changing the following line in your "init" method:

parent::init();

to

FrontController::init();

Once this is complete you may need to clear your cache, remove the coupon, and try applying it again. Note that if you have already gone through step 4. you will first have to remove all cookies on the site to clear the current session.

Last updated