Jump to content

Free shipping voucher for first order with carrier restriction


Recommended Posts

Hello,

I want to create automatic voucher with free shipping only usable on one of my carriers after regristration. So I create an override of AuthController with :

protected function sendConfirmationMail(Customer $customer)
{
    if (!Configuration::get('PS_CUSTOMER_CREATION_EMAIL')) {
        return true;
    }
     $cartRuleObj = new CartRule();
    $cartRuleObj->date_from = date('Y-m-d H:i:s');
    $cartRuleObj->date_to = date('Y-m-d H:i:s', strtotime('+1 year'));
    $cartRuleObj->name[Configuration::get('PS_LANG_DEFAULT')] = 'Free shipping first order';
    $cartRuleObj->quantity = 1;
    $code = Tools::passwdGen();
    while (CartRule::cartRuleExists($code)) {
        $code = Tools::passwdGen();
    }
    $cartRuleObj->code = $code;
    $cartRuleObj->quantity_per_user = 1;
    $cartRuleObj->reduction_percent = 0;
    $cartRuleObj->reduction_amount = 0;
    $cartRuleObj->free_shipping = 1;
    $cartRuleObj->active = 1;
    $cartRuleObj->minimum_amount = 0;
    $cartRuleObj->id_customer = $customer->id;
    $cartRuleObj->add();
 
    return Mail::Send(
           $this->context->language->id,
           'account',
           Mail::l('Welcome!'),
           array(
               '{firstname}' => $customer->firstname,
               '{lastname}' => $customer->lastname,
               '{email}' => $customer->email,
               '{passwd}' => Tools::getValue('passwd'),
               '{coupon}' => $code),
           $customer->email,
           $customer->firstname.' '.$customer->lastname
        );
}     }

This works fine but the free shipping applied to all the carriers.

So I add :

    $cartRuleObj->carrier_restriction = 1;

My created voucher is now not available for any carrier.

What should I add for attribute the ID of my carrier to the voucher ?

Thanks for your help.

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
×
×
  • Create New...

Important Information

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