Jump to content

How can I create a Cart Rule with Product Group Rules via webservice


Recommended Posts



Is there a way to include Product Group Rules via PS webservice?

I'm creating an app that needs to create a discount promo code that applies to a Product category but the XML for cart_rules doesn't include any tag for adding such group rules o at least I don't know where to add them.


This is the blank XML schema where I can't guess where to include such info:

            <language id="1"/>

Any help would be really appreciated!


Thank you in advance!

  • Like 1

Share this post

Link to post
Share on other sites

  • 1 month later...
  • 5 months later...

Hi @W3c2i,


The only way I could do it was without using the Web Service. I copied and modified code fragments from the Controller that implements this feature in the PS Back Office.


(PD: It looks your native language is not english. Mine is spanish. What's yours?)

Share this post

Link to post
Share on other sites

  • 2 months later...

I have this:


    require_once( './PSWebServiceLibrary.php' );

    try {		
            $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
            $opt = array('resource' => 'cart_rules');
            $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/cart_rules?schema=blank'));
            $resources = $xml->children()->children();
            $resources->date_from = date('Y-m-d H:i:s');
			$resources->date_to = date('Y-m-d H:i:s', strtotime ( '+1 year' , strtotime (date('Y-m-d H:i:s')) ));
			$resources->description = "Mi descr. cupon";
			//$resources->quantity = 9999;
			//$resources->quantity_per_user = 1;
			//$resources->priority = 1;
			//$resources->partial_use = 1;
			$resources->code = "kazpacio";
			$resources->minimum_amount = "100";
			$resources->minimum_amount_tax ="1";
			//$resources->minimum_amount_currency = 2;
			$resources->minimum_amount_shipping = "0";
			//$resources->country_restriction = 0;
			//$resources->carrier_restriction = 0;
			//$resources->group_restriction = 0;
			//$resources->cart_rule_restriction = 0;
			//$resources->product_restriction = 0;
			//$resources->shop_restriction = 0;
			//$resources->free_shipping = 0;
			$resources->reduction_percent = "35.00";
			//$resources->reduction_amount = 0.00;
			//$resources->reduction_tax = 0;
			//$resources->reduction_currency = 2;
			//$resources->reduction_product = 0;
			//$resources->gift_product = 0;
			//$resources->gift_product_attribute = 0;
			//$resources->highlight = 0;
			//$resources->active = 1;
			//$resources->date_add = date('Y-m-d H:i:s');
			//$resources->date_upd = date('Y-m-d H:i:s');
			$resources->name->language = array(1 => 'Hola', 2 => 'Hello');

            $opt = array('resource' => 'cart_rules');
            $opt['postXml'] = $xml->asXML();
            $xml = $webService->add($opt);
    catch (PrestaShopWebserviceException $ex) {
        echo 'Error: <br/>'.$ex->getMessage();

And this is the result

Warning: It is not yet possible to assign complex types to properties in C:\wamp\www\cajondesastre\referido\apis\api_create_cart_rules.php on line 44

Line 44 $resources->name->language = array(1 => 'Hola', 2 => 'Hello');


This call to PrestaShop Web Services failed and returned an HTTP status of 400. That means: Bad Request.

Share this post

Link to post
Share on other sites

I suppose I will just copy my response from your other thread since you appear to have over looked or ignored it...

require_once( './PSWebServiceLibrary.php' );

Are these files that you have created, or perhaps you downloaded some API?  These files do not exist in the PS v1.6.1.2 code base.


I also searched the PS v1.6.1.2 code base for the message "It is not yet possible to assign complex types to properties", and nothing comes up.  So I suspect this has nothing to do with Prestashop, but rather the code you have developed or downloaded, which you don't specify

Share this post

Link to post
Share on other sites

  • 2 years later...

Hi @fredopahu, @W3c2i, @mogarick, @jsilkh, @bellini13,

I have solved this problem by buying from the module "Discount rules with conditions using Api Module". This module expands with 2 new API methods that allow the synchronization of catalog and cart rules with any of the conditions available from the BackOffice.

I leave the link to the module:


Share this post

Link to post
Share on other sites

  • 3 years later...

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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More