Jump to content

The best way to create a new order in my custom module


Stepel
 Share

Recommended Posts

Hi,

what is the best way to create new order in my custom module ?
Should I create all elements by new Order(), new Cart() etc etc manually or there is some suggested method or class to do it ?


Thanks for your help.

Share this post


Link to post
Share on other sites

You will need to use or create a customer and an address to use as a delivery and billing address.

After that you will have to create a shopping cart, and add the products in it.

Next, you will need to call the validatedOrder() function in the PaymentModule class to create the order, and of course you need to assign it a carrier, and create the OrderCarrier object for the current order.

Share this post


Link to post
Share on other sites

Hmm I have some doubts about using validatedOrder() method.

I created customer, addresses and cart but I see that i can add products by id_product. I would like to have influence on product price and carrier price. I see that I can set those prices in order_details and order so I am not sure if I should use validatedOrder method. I think that it will work like by API and will change prices to be equel with those prices in official product list etc..

Share this post


Link to post
Share on other sites

  • 1 month later...

Hi again. I did it like you suggested. Thank you very much. It looks almost all is OK but I have case like i created SpecificPrice.. and in my mind was that price included tax but in order finally product has calculated tax again hm. Where and when I can set kind of "use_tax" parameter ?

Share this post


Link to post
Share on other sites

Which way did you set the discount? Did you put the price directly? Or did you set a discount (amount or percentage)

Share this post


Link to post
Share on other sites

	$sp = new SpecificPrice();
        $sp->id_shop = 0;
        $sp->id_cart = $cart_id;
        $sp->id_product = $product_id;
        $sp->id_currency = 0;
        $sp->id_country = 0;
        $sp->id_group = 0;
        $sp->id_shop_group = 0;
        $sp->id_customer = $customer_id;
        $sp->price = $price;
        $sp->from_quantity = 1;
        $sp->reduction = 0;
        $sp->reduction_tax = 1;
        $sp->reduction_type = 'amount';
        $sp->from = '0000-00-00 00:00:00';
        $sp->to = '0000-00-00 00:00:00';
        if ($sp->add()) {
            return $sp->id;
        } else {
            return null;
        }

I do it like that so I set price directly and reduction as 0.

Share this post


Link to post
Share on other sites

If you set the price directly, yes, it is the one without tax. That property works when you set the discount amount.

Share this post


Link to post
Share on other sites

  • 2 weeks later...

Hmm I have weird situation yet. Maybe it's fault of some cache..
I changed email address in database for customer but this:
 

$this->context->customer = new Customer((int) $this->context->cart->id_customer);


returns email before changed 😕

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