gr4devel Posted May 17, 2013 Share Posted May 17, 2013 (edited) Hi community a very specific question today . How can I set up the name of cart rule when I generating it automatically? I mean from the code . More broader view: I had a module (in PS 1.4) that generates old discount automatically from a given template (i.e. another predefined voucher). Now in PS 1.5 discounts are substituted by cart rules and these have a multilingual name field that must be filled in order to successfully generate them. Actually what I'm trying to do is to set the same name for every language registered in the system. I tried to look to the validation code but I can't get any idea on the structure the the name must have in order to pass the validation and create the rule. Thanks in advance to everyone! Edited May 19, 2013 by gr4devel (see edit history) Link to comment Share on other sites More sharing options...
gr4devel Posted May 19, 2013 Author Share Posted May 19, 2013 (edited) Some update. Here I set up the name as an hash with key equal to the languages id and the values equals to names. $cart_rule_name = $this->generateUniqueVoucherName(); $languages = Language::getLanguages(); foreach ($languages as $key => $language) { $cart_rule->name[$language['id_lang']] = $cart_rule_name; } $cart_rule->code = $cart_rule->name; Actually I get these errors: Warning: preg_match() expects parameter 2 to be string, array given in /media/data/dev/sites/vdp/vdp/classes/Validate.php on line 401 Warning: preg_match() expects parameter 2 to be string, array given in /media/data/dev/sites/vdp/vdp/classes/Validate.php on line 401 Warning: preg_match() expects parameter 2 to be string, array given in /media/data/dev/sites/vdp/vdp/classes/Validate.php on line 401 Warning: preg_match() expects parameter 2 to be string, array given in /media/data/dev/sites/vdp/vdp/classes/Validate.php on line 401 Warning: strip_tags() expects parameter 1 to be string, array given in /media/data/dev/sites/vdp/vdp/classes/db/Db.php on line 627 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Edited May 19, 2013 by gr4devel (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted May 19, 2013 Share Posted May 19, 2013 you have to create an array: array ('1'=>$cart_rule_name, '2'=>$cart_rule_name); foreach ($languages as $key => $language) { $array[$language['id_lang']]= $cart_rule_name; } $cart_rule->name=$array; for me this method works well Link to comment Share on other sites More sharing options...
gr4devel Posted May 19, 2013 Author Share Posted May 19, 2013 (edited) Thank you my friend!!! I'll try hoping to put a [sOVLED] also to this topic! Thanks again you're really great!!! [EDIT]: and it is [sOLVED]!!! You're the number 1!!! Edited May 19, 2013 by gr4devel (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted May 19, 2013 Share Posted May 19, 2013 you're welcome if you've got any other questions related to this thread - feel free to continue discussion here regards Link to comment Share on other sites More sharing options...
ben mbarek afef Posted April 10, 2014 Share Posted April 10, 2014 hi , i have the same warning but in this code : $order_cart_rule = new OrderCartRule(); $order_cart_rule->id_order = $order->id; $order_cart_rule->id_cart_rule = $cart_rule->id; $order_cart_rule->id_order_invoice = $id_order_invoice; $order_cart_rule->name = $cart_rule->name; $order_cart_rule->value = $values['tax_incl']; $order_cart_rule->value_tax_excl = $values['tax_excl']; $order_cart_rule->add(); Link to comment Share on other sites More sharing options...
vekia Posted April 10, 2014 Share Posted April 10, 2014 hi , i have the same warning but in this code : $order_cart_rule = new OrderCartRule(); $order_cart_rule->id_order = $order->id; $order_cart_rule->id_cart_rule = $cart_rule->id; $order_cart_rule->id_order_invoice = $id_order_invoice; $order_cart_rule->name = $cart_rule->name; $order_cart_rule->value = $values['tax_incl']; $order_cart_rule->value_tax_excl = $values['tax_excl']; $order_cart_rule->add(); you mean that exactly the same as Warning: preg_match() expects parameter 2 to be string, array given in /media/data/dev/sites/vdp/vdp/classes/Validate.php on line 401 Warning: preg_match() expects parameter 2 to be string, array given in /media/data/dev/sites/vdp/vdp/classes/Validate.php on line 401 Warning: preg_match() expects parameter 2 to be string, array given in /media/data/dev/sites/vdp/vdp/classes/Validate.php on line 401 Warning: preg_match() expects parameter 2 to be string, array given in /media/data/dev/sites/vdp/vdp/classes/Validate.php on line 401 Warning: strip_tags() expects parameter 1 to be string, array given in /media/data/dev/sites/vdp/vdp/classes/db/Db.php on line 627 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 Notice: Array to string conversion in /media/data/dev/sites/vdp/vdp/tools/swift/Swift/Plugin/Decorator.php on line 191 the same error code and number of errors? Link to comment Share on other sites More sharing options...
ben mbarek afef Posted April 10, 2014 Share Posted April 10, 2014 Warning: preg_match() expects parameter 2 to be string, array given in /web/developpeurappl/www/htd/classes/Validate.php on line 402Warning: preg_match() expects parameter 2 to be string, array given in /web/developpeurappl/www/htd/classes/Validate.php on line 402Warning: preg_match() expects parameter 2 to be string, array given in /web/developpeurappl/www/htd/classes/Validate.php on line 402Warning: preg_match() expects parameter 2 to be string, array given in /web/developpeurappl/www/htd/classes/Validate.php on line 405Warning: stripslashes() expects parameter 1 to be string, array given in /web/developpeurappl/www/htd/classes/db/Db.php on line 628 Link to comment Share on other sites More sharing options...
ben mbarek afef Posted April 10, 2014 Share Posted April 10, 2014 help pleaseee :"( Link to comment Share on other sites More sharing options...
vekia Posted April 10, 2014 Share Posted April 10, 2014 help pleaseee :"( what ps version you use? Link to comment Share on other sites More sharing options...
ben mbarek afef Posted April 10, 2014 Share Posted April 10, 2014 i use prestashop 1.5.6 Link to comment Share on other sites More sharing options...
vekia Posted April 10, 2014 Share Posted April 10, 2014 hello thank you, i checked validate function and i've got one more question: what you've got in this variable: $cart_rule->name; ? Link to comment Share on other sites More sharing options...
ben mbarek afef Posted April 10, 2014 Share Posted April 10, 2014 (edited) when the generate of the cart rule i put this code : $cart_rule = new CartRule(); $cart_rule->description = sprintf('Credit slip for order #%d', $order->id); $languages = Language::getLanguages(false); foreach ($languages as $language) // Define a temporary name $cart_rule->name[$language['id_lang']] = sprintf('#########', $order->id_customer, $order->id); // Define a temporary code $cart_rule->code = sprintf('########', $order->id_customer, $order->id); Edited April 11, 2014 by ben mbarek afef (see edit history) Link to comment Share on other sites More sharing options...
ben mbarek afef Posted April 11, 2014 Share Posted April 11, 2014 (edited) why in generate the cart rule i put this code : $cart_rule = new CartRule(); $cart_rule->description = sprintf('Credit slip for order #%d', $order->id); $languages = Language::getLanguages(false); foreach ($languages as $language) // Define a temporary name $cart_rule->name[$language['id_lang']] = sprintf('#########', $order->id_customer, $order->id); // Define a temporary code $cart_rule->code = sprintf('########', $order->id_customer, $order->id); Edited April 11, 2014 by ben mbarek afef (see edit history) Link to comment Share on other sites More sharing options...
ben mbarek afef Posted April 11, 2014 Share Posted April 11, 2014 the script it works but it shows me warnings that prevent the other party code function because I have this error Fatal error: Call to undefined method stdClass :: clearCache () in / web / developpeurappl / www / htd / classes / Tools.php on line 2250 Link to comment Share on other sites More sharing options...
ben mbarek afef Posted April 11, 2014 Share Posted April 11, 2014 (edited) thunk you i solved the warning by this : $order_cart_rule->name = $cart_rule->name[1]; by i have an error here : $history->changeIdOrderState(19, $order, $use_existings_payment); Fatal error: Call to undefined method stdClass::clearCache() in /web/developpeurappl/www/htd/classes/Tools.php on line 2250 Edited April 11, 2014 by ben mbarek afef (see edit history) 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