Kryptronic Software Support Forum

You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.

#1 09-27-2017 14:04:16

zanart
Member
From: bedford
Registered: 04-02-2008
Posts: 1716

Forcing order into database

Hi Nick

Not expecting too much from you on this one, but is the following feasible....

I want to manually force an order into the ecom_orders and ecom_orderitems table. No shipping, No prices, Same User, No nothing. Just the product id, name and customdata fields.
I want to do this with one click, bypassing the shopping cart and checkout pages.

So, I am looking at creating a new order number with cogetnewordnum, and then filling in the blanks of $data = $this->template_order and $data = $this->template_orderitem with the correct data before saving/inserting the sql as per cowriteorder. Then I think I may need to go through olpsetup namespace to update the status.

Assuming I get all the $data correct, is that all I need to do to force a PS order into the database.


Rob

Offline

 

#2 09-28-2017 07:52:08

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19861
Website

Re: Forcing order into database

Hi.  I love these types of questions.  I do so much custom work for clients where I run into issues like this, the hooks are in there to do it.  And I love answering these types of questions because they're way more interesting than the usual stuff.  So...

First off, why not get the Point of Sale extension module, set up a POS-only gateway, and go to town.  If it's you entering the orders, that is.  If the 'click a button' scenario is for a customer, then you have to do what you're looking to do, I suppose.  I'd try real hard to use the existing cart and checkout as much as possible to fill requirements, but it's not necessary.  You can write the order directly to the db.  But...

Writing the order to the database is just the first part.  You'll want to look in the ECOM_Checkout class at the cowriteorder() function to get all the specifics of how that's done.  You're looking at all the right stuff (the template variables in the ECOM class, the ecom_orders and ecom_orderitems tables, using some ECOM_Checkout classes).  I don't know if you need to register a payment, but if you do, you'll need to write to ecom_payments as well.  You'll want the order's data perfect, matching what you see coming in through checkout for regular orders.  The only exception will be that your ecom_orderitems.cartdata column won't have cart data in it.  That's OK, though.  Put an empty serialized array in there.

After you've got the order written to the database, it needs to be processed in some fashion, and statuses will need to be updated, inventory held, etc. Depending on your processing level tied to your gateway.  So do this:

(1) Write the order to the appropriate database tables as per above.

(2) Use the orderlookup() function in the ECOM_Order class (or use the ecom.orderlookup namespace) to load your data from the database tables into an order array.

(3) Set the global 'ecom.order_autoprocess' to true (1).  This exists to process future orders automatically on their execution date, but gets leveraged perfectly here.

(4) Pass the order array to the orderprocess() function in the ECOM_OrderManager class (or use the ecom.orderprocess namespace).

You might hit a hiccup on the last item and have to tweak your data to get desired results.  Depends on how you set the data up.  Review that function if you run into issues.  Doing it this way basically treats it like a regular order and processes it correctly, getting it to an enabled status.  And if it's supposed to, all the inventory and other updates occur as you'd like.  Mails are sent, etc.

Questions?


Nick Hendler

Offline

 

#3 09-28-2017 08:42:04

zanart
Member
From: bedford
Registered: 04-02-2008
Posts: 1716

Re: Forcing order into database

HI Nick.

why not get the Point of Sale extension module,

Got it, and use it for phone orders which are part of the sites turnover. We also have shops, whose turnovers are accounted for elsewhere. So the idea is to have a Frontend page to simplify are incredibly complicated ordering options. This is all done and works well. Shop workers can create orders using same database of frames, etc and can auto print out.
I have created a new table that stores the 'designs' as I wanted to keep it separate from ecom_cart.
When the orders are created by shop, I thought it would be a great idea to have them included with the online orders so that instore customers would receive order complete emails, etc and the orders would be included in out Batch Order system. This would eliminate workload coming from different directions. Anyway, the obvious problem was I couldn't include the payment of the shop orders in the site turnover as it is already 'rung into the till'. So my head started pounding...

and it has been achieved with incredible ease!

I copied cogetnewordnum as I wanted different order numbers from usual ones. New Orders number are now created with 'Shop' prefix to make them instantly obvious.

Filled in all the blanks for $this->template_order but also added $data['status'] = 'PS' and a few of the important $data['statusinit'] =1.

Done the same for $this->template_orderitem, and added a few such as $data['statusserviced'] =1.

Basically compared the arrays to a PS order in order/order_items table.

By adding the extra variables to the array, I think I have bypassed orderprocess(). If I want to, I can use ordermails to send customer an invoice, but haven't quite finished yet.

So now, shop worker can create an order and click a button. All details are correctly added to ecom_orders and ecom_orderitems. Orders can be viewed, searched for, edited, marked as complete, etc, etc


Rob

Offline

 

#4 09-28-2017 13:27:10

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19861
Website

Re: Forcing order into database

By adding the extra variables to the array, I think I have bypassed orderprocess(). If I want to, I can use ordermails to send customer an invoice, but haven't quite finished yet.

Order processing via the ECOM_OrderManager class is done using a massive amount of logic.  Take a look at:

{private}//apps/ecom/ECOM_OrderMan/init/*.php -> Everything that happens to initialize the order (make it an order)
{private}//apps/ecom/ECOM_OrderMan/proc/*.php -> Everything that happens to enable an order (enable an order for processing, it's an order that can be worked with)
{private}//apps/ecom/ECOM_OrderMan/comp/*.php -> Everything that happens when an order is complete

Using ECOM_OrderManager->orderprocess() as I outlined above gets all this done clean, and sends your mails.  I'm suggesting you write to the db, pull using orderlookup() and process via orderprocess().  I think you could do it in three or four lines of code.


Nick Hendler

Offline

 

Board footer