Jump to content

webservice cart_rules error Warning: It is not yet possible to assign complex types to properties


ludovic1986

Recommended Posts

Hello,

 

I would like to create a cart_rule with the webservice and I have this error when I add cart_rule's name .

 

Warning: It is not yet possible to assign complex types to properties

 

 

 

If I don't add the name I have a error . 

 

 

 

<code><![CDATA[84]]></code>
<message><![CDATA[Validation error: "Property CartRule->name is empty"]]></message>

 

Code when I create the value name and send to prestashop

$xml = $this->webService->get(array('url' => $this->config('shop_path').'/api/cart_rules?schema=blank'));
		$resources = $xml->children()->children();
		
		foreach ($resources as $nodeKey => $node)
		{
			if(isset($values[$nodeKey])){
				$resources->$nodeKey = $values[$nodeKey];
			}else{
				switch($nodeKey){
					case 'name':
						$resources->$nodeKey->language = [1=>'my code name']; 
						break;
				}

			}
		}

		try{
			$opt = array('resource' => 'cart_rules');
			$opt['postXml'] = $xml->asXML();
			
			 

			$xml = $this->webService->add($opt);
			
		}catch (PrestaShopWebserviceException $ex)
		{
			// Here we are dealing with errors
			$trace = $ex->getTrace();
			if ($trace[0]['args'][0] == 404) echo 'Bad ID';
			else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
			else echo 'Other error<br />'.$ex->getMessage();
		}

This are the others values 

		$values = ['id_customer'=>0,
				'date_from'=>date('Y-m-d H:i:s'),
				'date_to'=>date('Y-m-d H:i:s',strtotime('+50 DAYS')),
				'description' => 'Promo Code',
				'quantity' => 5,
				'quantity_per_user' => 1,
				'priority'=>1,
				'partial_use'=>0,
				'code'=>'TESTCODE1025',
				'minimum_amount'=>10.00,
				'minimum_amount_tax'=>10,
				'minimum_amount_currency'=> 1,
				'minimum_amount_shipping'=>0,
				'country_restriction'=>0,
				'carrier_restriction'=>0,
				'group_restriction'=>0,
				'cart_rule_restriction'=>0,
				'product_restriction'=>0,
				'shop_restriction'=>0,
				'free_shipping'=>0,
				'reduction_percent'=>0.00,
				'reduction_amount'=>3.00,
				'reduction_tax'=>1,
				'reduction_currency'=>1,
				'reduction_product'=>0,
				'gift_product'=>0,
				'gift_product_attribute'=>0,
				'highlight'=>0,
				'active'=>1,
				'date_add'=>date('Y-m-d H:i:s'),
				'date_upd'=>date('Y-m-d H:i:s')
				];

How can I add the cart_rules name with the web service ? 

 

I work with prestashop 1.6.1.12 and PHP 5.6 

 

 

 

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