danielevigi Posted January 8, 2014 Share Posted January 8, 2014 Hi, I'm really new to Prestashop. I am a PHP developer. I am trying to understand how apply a cart rules using a URL (with GET parameters). Should I create a module or there is a simpler method? Which hook should I use? Link to comment Share on other sites More sharing options...
Divyesh Prajapati Posted January 8, 2014 Share Posted January 8, 2014 Hi, I'm really new to Prestashop. I am a PHP developer. I am trying to understand how apply a cart rules using a URL (with GET parameters). Should I create a module or there is a simpler method? Which hook should I use? You can create cart rules from back office. Go to Cart Rules --> Price Cart Rules. Add cart rules as per your requirement. Link to comment Share on other sites More sharing options...
danielevigi Posted January 8, 2014 Author Share Posted January 8, 2014 (edited) You can create cart rules from back office. Go to Cart Rules --> Price Cart Rules. Add cart rules as per your requirement. Yes, I know this. I've already created it in the backoffice. What I need is to automatic apply the cart rule when a user connects to the site through a specific URL. I need to do this because of a partnership with a marketing site. EDIT: I can use also catalog price rules. What I'm interested mainly is to apply it only reading GET parameters in the URL. Edited January 8, 2014 by danielevigi (see edit history) Link to comment Share on other sites More sharing options...
danielevigi Posted January 9, 2014 Author Share Posted January 9, 2014 What I've done: create a controller save the parameters of the GET request in some variables create a template in the theme directory set the template in the controller What I need now and that I don't understand is how to apply my custom discount in the cart. I've seen the context object but I don't see where apply the discount or add the cart rule or the catalog rule. Can I use a hook? If yes, what hook? Link to comment Share on other sites More sharing options...
danielevigi Posted January 9, 2014 Author Share Posted January 9, 2014 This is my raw solution from the start: Create a controller In the method init() I check if exists a GET parameter with a specified code, in case I store a boolean variable in $context->cookie In the method initContent() I call setTemplate to display my template that show an alert to the user I have overwritten the method priceCalculation in Product.php adding at the end something like this: $myvar = (bool) intval($context->cookie->myvar); if ($myvar) { $price = $price - (($price * 30) / 100); // 30% discount } So when user visit my custom page (that use the created controller) will see the prices discounted of 30%. 2 Link to comment Share on other sites More sharing options...
lupillus Posted March 12, 2016 Share Posted March 12, 2016 This is my raw solution from the start: Create a controller In the method init() I check if exists a GET parameter with a specified code, in case I store a boolean variable in $context->cookie In the method initContent() I call setTemplate to display my template that show an alert to the user I have overwritten the method priceCalculation in Product.php adding at the end something like this: $myvar = (bool) intval($context->cookie->myvar); if ($myvar) { $price = $price - (($price * 30) / 100); // 30% discount } So when user visit my custom page (that use the created controller) will see the prices discounted of 30%. Hi danielevigi, Can you please show the code of the controller you made? It would really help me to achive the same thing on my shop, Thank you very much! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now