Jump to content

PHP add cart_rule by code


auroncaos
 Share

Recommended Posts

Hello there, I have a problem with a "cart_rule" already created, I add it on a Cart with some product and on the cart it show correctly.

I use:

 $cart ->addCartRule($cart_rule->id); 

then I save the cart and it's show all right.

I create an order 

$order = new Order(); 	 
$product_list = $cart->getProducts();
$order->id_carrier = $id_carrier; //my data, working fine
$order->id_customer = $id_customer;
$order->id_address_invoice = (int)$id_address;
$order->id_address_delivery = (int)$id_address;
$order->id_currency = 2;
$order->id_lang = 2;
$order->id_cart = $id_cart;
$order->reference = $my_reference;
$order->id_shop = 1;
$order->id_shop_group = 1;
$order->secure_key = $customer->secure_key;
$order->payment = "Bank wire"; //change if need
$order->module = "bankwire"; //change if need
$order->recyclable = 0;
$order->gift = (int)0;
$order->gift_message = "";
$order->mobile_theme = 0;
$order->conversion_rate =1.000000;

-- I set the amount to pay, discount, etc.
then I execute
$result = $order->add();
// Insert new Order detail list using cart for the current order
$order_detail = new OrderDetail(null, null, null);
$order_detail->createList($order, $cart, 1, $product_list, 0, true, 0);
$order_detail_list[] = $order_detail;
		
// I set manually my order_detail
//then

$history  = new OrderHistory();
$history->id_order = (int)$order->id;
$history->changeIdOrderState((int)10, $order->id);
$history->save();
$order_carrier = new OrderCarrier();
$order_carrier->id_order = (int)$order->id;
    $order_carrier->id_carrier = (int)$id_carrier;
    $order_carrier->weight = (float)$order->getTotalWeight();
    $order_carrier->shipping_cost_tax_excl = (float)$order->total_shipping_tax_excl;
    $order_carrier->shipping_cost_tax_incl = (float)$order->total_shipping_tax_incl;
    $order_carrier->add();

It's works just fine, i can write the amount I want etc... I have only a problem, even if the cart rule (a discount) is applied at the cart, when I change the state of the order in payment accepted, the cart_rules saved don't change, the amount of the discount don't decrease, like it was infinite...

 

ANy suggestion? thanks 🙂 

 

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