Jump to content

[SOLVED] Genereate vouchers (a.k.a. CartRule)


gr4devel
 Share

Recommended Posts

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 by gr4devel (see edit history)

Share this post


Link to post
Share on other sites

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 by gr4devel (see edit history)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

  • 10 months later...

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

Share this post


Link to post
Share on other sites

 

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?

Share this post


Link to post
Share on other sites

Warning: preg_match() expects parameter 2 to be string, array given in /web/developpeurappl/www/htd/classes/Validate.php on line 402

Warning: preg_match() expects parameter 2 to be string, array given in /web/developpeurappl/www/htd/classes/Validate.php on line 402

Warning: preg_match() expects parameter 2 to be string, array given in /web/developpeurappl/www/htd/classes/Validate.php on line 402

Warning: preg_match() expects parameter 2 to be string, array given in /web/developpeurappl/www/htd/classes/Validate.php on line 405

Warning: stripslashes() expects parameter 1 to be string, array given in /web/developpeurappl/www/htd/classes/db/Db.php on line 628

Share this post


Link to post
Share on other sites

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 by ben mbarek afef (see edit history)

Share this post


Link to post
Share on other sites

 

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 by ben mbarek afef (see edit history)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 by ben mbarek afef (see edit history)

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

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