Jump to content

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


mogarick

Recommended Posts

Hi,

 

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:

<prestashop>
    <cart_rule>
        <id/>
        <id_customer/>
        <date_from/>
        <date_to/>
        <description/>
        <quantity/>
        <quantity_per_user/>
        <priority/>
        <partial_use/>
        <code/>
        <minimum_amount/>
        <minimum_amount_tax/>
        <minimum_amount_currency/>
        <minimum_amount_shipping/>
        <country_restriction/>
        <carrier_restriction/>
        <group_restriction/>
        <cart_rule_restriction/>
        <product_restriction/>
        <shop_restriction/>
        <free_shipping/>
        <reduction_percent/>
        <reduction_amount/>
        <reduction_tax/>
        <reduction_currency/>
        <reduction_product/>
        <gift_product/>
        <gift_product_attribute/>
        <highlight/>
        <active/>
        <date_add/>
        <date_upd/>
        <name>
            <language id="1"/>
        </name>
    </cart_rule>
</prestashop>

Any help would be really appreciated!

 

Thank you in advance!

  • Like 1
Link to comment
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?)

Link to comment
Share on other sites

  • 2 months later...

I have this:

<?php
    session_start();
	include_once("api_conf.php");
    //extract($_POST);

    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');

 

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

Link to comment
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...

C:\wamp\www\cajondesastre\referido\apis\api_create_cart_rules.php
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
 

Link to comment
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:
https://addons.prestashop.com/en/promotions-gifts/29844-discount-rules-with-conditions-using-api.html

Regards

  • Like 1
Link to comment
Share on other sites

  • 3 years later...
  • 2 years later...
On 1/31/2018 at 11:45 AM, Pablo Pérez said:

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:
https://addons.prestashop.com/en/promotions-gifts/29844-discount-rules-with-conditions-using-api.html

Regards

Hello,

 

I need me too of this module but it is no longer in the prestashop addons. Could you help me?

Thank

Angela

 

 

Link to comment
Share on other sites

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