Comments

rickmanelius’s picture

Subscribing

hozt’s picture

From the lack of response I guess this may not be on the roadmap.

If this was done with commerce feeds / feeds then I think three difference feeds would make up each order

1) Order data - user, date, amount, etc
2) Line items - skus, qty, cost
3) Payments - amount, type, etc

rickmanelius’s picture

One of the difficult things with orders is going to be all the additional line items and discounts from other data structures (volusion, big commerce, etc). A clear mapping may not be so straightforward.

rfay’s picture

Commerce Migrate does support orders. I suspect that orders are not the best use case for commerce feeds, but perhaps...

rickmanelius’s picture

@rfay. Thanks for the heads up. I saw you vimeo video using feeds (used it, worked great!) but yeah, I did have some concerns using feeds for orders.

Personally, I'm thinking it's better to invest time learning migrate then for that portion and not try to force feeds to go this route unless someone can create an elegant solution.

hozt’s picture

I have tested Commerce Migrate and it works for doing an initial migration of orders and products, but support is only built-in for Ubercart so any other shopping cart would have to be manually coded.

Feeds / Commerce Feeds has several advantages including having the ability to map fields from the source to the destination which would allow nearly any third party store have its orders imported into Commerce. Another advantage that is essential in my use case is that I need orders to be imported continually from another system which works with Feeds. Feeds also has several good plugins modules like Feeds Tamper or Feeds Regex which allows the data to be modified on import.

rickmanelius’s picture

@hotz
That's a good point. i used feeds to map a volusion store product catalog in and it was pretty simple. My only worry with orders is handling the inline items, taxes, coupons, etc. It can potentially be complex. But hopefully we can at least get basic imports done and go from there.

pcambra’s picture

There is also an issue related with importing "generic" entities in feeds #1033202: [Meta] Generic entity processor

ronald54’s picture

Importing Orders can be very helpfull, especialy, when you are running a webshop as a center for other product platforms.

If orders from other platforms are comming in, it would be great to just import and track this order centraly in the commerce shop, creating central invoices ad packing sleeves, and finaly ship the goods and document this on one central place.

This is the way, I am planing the use of commerce.

ronald54’s picture

I am missing an orders processor for commerce_feeds.
Is there somethins alike, I might modify for my needs?

JulienD’s picture

Hi guys

Here is a patch to import orders with feeds. Of course you need first to import products and customers profiles. If the profile is unknow from the database, a new one would be created.

I tried be to generically as much as possible but let me know if changes are needed

I also added some dummy orders examples in the second patch.

Hope this can help

Best,
Julien.

JulienD’s picture

Status: Needs review » Active
StatusFileSize
new6.42 KB

Here is a better demo patch, forget commerce_feeds_example-Dummy_orders_examples-1156952-11.patch in #11 and use this one. In addition to the .csv file I've added a default feed order import.

Best,
Julien.

pcambra’s picture

Could you include both patches in one single?

pcambra’s picture

Status: Active » Needs work
JulienD’s picture

Ok, here a full patch of all my changes.

JulienD’s picture

Status: Needs work » Needs review
pcambra’s picture

Status: Needs review » Needs work

In general looks great, here are some things I've seen in the review

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,319 @@
+      $customer_profile_value = reset($order->commerce_customer_address[LANGUAGE_NONE]);

Let's better use a metadata wrapper in order not to care about the language

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,319 @@
+      // If no customer profil has been found, create a new customer profile

"profile"

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,319 @@
+      variable_set('site_default_country', 'US');

Why do you change the default country?

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,319 @@
+      $instances = field_info_instances('commerce_customer_profile', 'billing');

We should expose the profile type in the settings of the processor, same goes to line item type, if > 1, let's expose a setting

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,319 @@
+      $order->commerce_customer_billing[LANGUAGE_NONE][0]['profile_id'] = $customer_profile->profile_id;

same as above, better to wrap this so we don't care about languages

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,319 @@
+    // Let implementers of hook_feeds_term_processor_targets() add their targets.
...
+    // Let implementers of hook_feeds_term_processor_targets() add their targets.

hook_feeds_term?

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,319 @@
+      $order_id = db_query("SELECT order_id FROM {commerce_order} WHERE order_id = :order_id AND (mail = :mail OR created = :created)", array(':order_id' => $item['order_id'], ':mail' => trim($item['mail']), ':created' => trim($item['created'])))->fetchField();
...
+      $order_id = db_query("SELECT order_id FROM {commerce_order} WHERE mail = :mail AND  created = :created", array(':mail' => trim($item['mail']), ':created' => trim($item['created'])))->fetchField();

Can we use DBTNG here?

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,319 @@
+    if (empty($order->sku) && empty($order->product_id)) {
...
+    else if (!empty($order->product_id) && !commerce_product_load($order->product_id)) {
+      throw new FeedsValidationException(t('Product ID ("@product_id") is invalid.', array('@product_id' => $order->product_id)));

product id is not in the order

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,319 @@
+    else if (!empty($order->sku) && !commerce_product_validate_sku($order->sku)) {
+      throw new FeedsValidationException(t('Product SKU ("@sku") is invalid.', array('@sku' => $order->sku)));

I don't think we have the sku here, do we? $order->sku

JulienD’s picture

Status: Needs work » Needs review
StatusFileSize
new19.1 KB

I corrected my patch and exposed more information in the settings of the processor.

I based my order parser on the other parser, and this is just a copy/paste. This mention is also in the other parser. I haven't corrected the typo in the other files, should we open a new issues for that ?

// Let implementers of hook_feeds_term_processor_targets() add their targets.

According to this @todo found in feeds module "feeds_alter: This needs to be removed and drupal_alter() used. This is crazy dumb." I've replaced the feeds_alter() function.

pcambra’s picture

Status: Needs review » Needs work

Great! it's a good progress here, feel free to open a new issue for fixing typos and code style.

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,353 @@
+    $uid = 0;
...
+    $order->uid = $this->config['author'];

Why not using the author id in the first place?

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,353 @@
+    }

We'd want to add the "Replaced by" text as the other other processors have now

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,353 @@
+    if ($order->order_status) {
+      $order->status = $order->order_status
+        ? $order->order_status
+        : NULL;
+    }

What does this code do? isn't status something that should be filled in no matter what? i.e. default to cart.

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,353 @@
+    if (empty($order->uid) && $order->mail) {
+      $order->uid = ($account = user_load_by_mail($order->mail))
+        ? $account->uid
+        : 0;
+    }

Isn't an author of the orders configured in the importer settings? can this ever be empty?

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,353 @@
+    if ($order->sku) {
+      $product = commerce_product_load_by_sku($order->sku);
+    }
+    elseif ($order->product_id) {
+      $product = commerce_product_load($order->product_id);
+    }

I don't think product_id or sku are properties of the order and definitely they're not unique, any order might have several line items and these have a product each. We should add an example for this

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,353 @@
+    $customer_profile_value = reset($order->commerce_customer_address[LANGUAGE_NONE]);

Why not use entity metadata wrapper here too?

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,353 @@
+    // Tried to get a profil_id by comparing address informations from the order.

profile

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,353 @@
+        ->entityCondition('bundle', 'billing');
...
+        $order_wrapper->commerce_customer_billing->set($profile->profile_id);
...
+    $customer_profile = commerce_customer_profile_new('billing', $order->uid);
...
+    $order_wrapper->commerce_customer_billing->set($customer_profile->profile_id);

Why just billing? we might want to make this configurable?

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,353 @@
+    // @TODO: should we also delete profiles created ?

And line items?

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,353 @@
+      'username' => array(
+        'name' => t('User: Name'),
+        'description' => t('The customer\'s name.'),
+      ),
+      // Product infos.
+      'sku' => array(
+        'name' => t('Product: SKU'),
+        'description' => t('The product identifier.'),
+      ),
+      'quantity' => array(
+        'name' => t('Product: Quantity'),
+        'description' => t('The purchased quantitiy of the product.'),
+      ),

Why are these at order level?

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,353 @@
+    } catch (Exception $e) {
...
+    } catch (Exception $e) {

I think feeds has stopped to use the try catch thing

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,353 @@
+      if (!empty($item['order_id'])) {
+        $query->condition('order_id', $item['order_id']);
+      }

if order id is set we don't need to add further conditions

+++ b/plugins/FeedsCommerceOrderProcessor.inc
@@ -0,0 +1,353 @@
+    if (empty($order->sku) && empty($order->product_id)) {
...
+    else if (!empty($order->sku) && !commerce_product_validate_sku($order->sku)) {
...
+    else if (!empty($order->product_id) && !commerce_product_load($order->product_id)) {

Same as above, SKU and product id can't be at the order level?

If we're using entity metadata wrapper, it's better to add an explicit dependency to entity api module.

I'm not sure about the implementation on the relationships to the customer profiles and the line items, for the profiles, we might want to just add ids or references, and the products can't be at order level directly, we need a line item in the middle.

milekium’s picture

promising pacth. actually only works with the default address fields in the billing profile, not with extra fields in billing profile, neither can inport data into shipping profile fields. hope could do it.

chingis’s picture

StatusFileSize
new17.96 KB

Thanks for patch, guys.

I fixed patch from #18, there were wrong paths, also I removed customer profile type selection, so now by default all customer profile types available in mapping.

I didn't apply fixes described in #19 though.

Patch attached.

UPD:
It seems Processor in current state can't handle all customer profile types, but only creation of new billing customer profiles

hyperglide’s picture

Ping.. any comments on #21.

pcambra’s picture

Ping.. any comments on #21.

#19 hasn't been taken into account yet :)

robit8deb’s picture

anyone have this working? i have a need to bulk update order status based on order id but its not working.

i have order id, status and sku (only because it said it was required) but even though just those three fields are mapped i get an error about quantity format.

Any help is appreciated.

hyperglide’s picture

@robit8deb per #23 seems this is a work in progress.

bryangruneberg’s picture

Issue summary: View changes

For coders wanting to do this, the commerce_migrate_ubercart module provides a really good starting point. My migration is very custom from a legacy platform, so my strategy is to us commerce_migrate_ubercart as the foundation, and hack-and-slash that to work for my use case.

At the least commerce_migrate_ubercart will provide a good example of how to get this done.

allen.jared@gmail.com’s picture

is there a way to get multiple products listed into one order?

Dj_C4’s picture

Any updates or help installing this would be awesome. I really need to be able to bulk import users / orders.

zeezhao’s picture

Please has anyone been able to get this to work? I am using latest patch #21.
- Manually fixed some typos.
- Got it all setup correctly and mapped some fields.
- during the importing of a file I get this error:
"Missing bundle property on entity of type commerce_order."

[edit]
Finally got it to work. Needed to reselect bundle, etc.
Noticed a few potential issues with current version e.g
- Time: it appears time created is used to denote same order. Hence may cause issue if orders loaded from multiple stores and clash in times.
- Totals/Tax: calculating own totals using qty * price, instead of what was used at order time.
- Payments: will need to be entered separately via front-end as not part of import.
- Multiple items on an order: shows in detail on order but not in view or quickedit.

thaistore’s picture

any idea how to import different product variations into one node, there was a module for tht but it does not work

i dont want to create 6 diferent CSV files for each product variation though

any idea?

mglaman’s picture

Issue tags: +Commerce Sprint
nikolino’s picture

Hello,
I'm using Commerce Feeds to import orders within my ecommerce. I insert a SKU variant per line and it is sufficient that the date and the user is the same and it creates a single order.
My questions are:
- can I also import the id of the order? currently it is generated automatically, but if I try to import it, it gives me error
- how can I import the shipment cost?
- how can I set the taxes?

Thank you

maxplus’s picture

Hi,
I also need this feature.
=> I will the patches a try and post back my testing results.

srbracelin’s picture

Something like this would be great so that we can import tracking info for our orders from our custom shipping software.

jieyyal’s picture

StatusFileSize
new5.69 KB

Hi,

I tried the patch commerce-order-support-1156952.patch
But I get the error:
Missing Feeds plugin FeedsCommerceOrderProcessor. See order_impoter. Check whether all required libraries and modules are installed properly.

To fix the issue I believe we need add the plugin in the module info.
Here made a new patch for this feature:

commerce-order-support-1156952-35.patch

Thank you!

jieyyal’s picture

StatusFileSize
new18.42 KB

Missed the plugin in patch, re-upload the patch.

kristofferrom’s picture

I'm getting this error "Order status ("Completed") is invalid." on all items.

Does this field need to be formatted in a particular way? The destination are of course already working with a 'Completed' order status...

knipnehpets’s picture

update: looks like you can now do this using
feeds_entity_processor module.
I guess at a minimum you'll need to create the orders first, then the line items to add onto them (these have separate processors in the list).

firfin’s picture

I used the following code in a custom module to achieve this, not very generic and probably not best practice, but is works (for me). In my own module class LmbImporterProcessor extends FeedsProcessor { I have the following code, in the bit beleo I removed all extra trimmings (feedback messages etc).

 public function process(FeedsSource $source, FeedsParserResult $parser_result) {
    // Get the current User
    global $user;
    // Create the new order in checkout; you might also check first to
    // see if your user already has an order to use instead of a new one.
    $order = commerce_order_new($user->uid, 'checkout_checkout');

    // Save the order to get its ID.
    commerce_order_save($order);

    foreach ($parser_result->items as $index => $item) {
      // Create new line item, if the product is valid.
      if( $product = commerce_product_load_by_sku($item['sku']) ) {
        $line_item = commerce_product_line_item_new($product, $item['quantity']);

        // Add to line item to  current user's cart: if the user is not logged in 
        // ($user->uid: 0) Drupal Commerce manages the $_SESSION
        $line_item_added = commerce_cart_product_add($user->uid, $line_item);
      }
    }
}