A case for the Drupal commerce detective
Finally solved a curious issue that has been nagging me on a test Drupal commerce site.
I have a utility script that lists products that are not linked to Product Displays (handy). Perplexingly the ‘report’ kept showing some orphaned products even though I had linked them all and the report had shown none previously.
It is a test site undergoing some heavy development so at first I put it down to that - rolling the database back and forth etc But today I noticed it and was pretty sure that nothing had changed that could cause such data changes. Could it be some bug in entity API, commerce ? Unlikely! So crack out the deer stalker and pipe lets investigate!
First stop check the last updated datetime for the related product displays and see that, sure enough they were updated that morning. So if I didn’t update it who or what did? The most likely suspect is cron calling a hook - I could debug that by listing all hooks and chasing the rabbit through them - or think what would cron call that would affect product displays - job scheduler is a likely suspect and ‘ping’ light bulb! It is only a test site so Cron is not set to run regularly - but will run if you visit the site (the new poor mans cron implmentation in Drupal 7 which ensure that cron will run even if you forget to set it up).
I imported the product displays using the excellent feeds module and although I ran it manually from an uploaded file, by default it sets up to run the import every 30mins! And there you have it!
** update ** I thought you couldn't import product displays linked to multiple products - since found out from Randy Fay of Commerce Guys that you can! Using Feeds Tamper! See another great screencast from Randy fay here [http://www.drupalcommerce.org/node/467]. (By the way the latest version of Feeds now also allows you to import to list(text) fields!)
See also this post that explores how to prepare your data for import (http://technology.blue-bag.com/importing-products-displays-and-related-products-drupal-commerce)
So I imported several thousand products and about 30 product displays using feeds then linked the displays to the products - helpfully I had imported a common field on both that allowed the displays to be linked to the products. All fine until every 30 mins the node importer ran and updated the product displays in small batches (hence not immediately obvious that products were being unlinked) I had disabled it on the commerce product importer but overlooked it on the displays import.
So the top tip? When using feeds to import data from an uploaded file make sure you disable the schedule element! and probably disable the feeds module on production if you don’t need it!
- info [at] blue-bag.com
- Telephone: 0843 2894522
- Blue-Bag HQ:
The Garage, Manor Farm
Somerset, BA3 4HP, United Kingdom
- Telephone: (+44) 01761 411542
- Blue-Bag Brighton:
Unit 35 Level 6 North, New England House
New England Street, Brighton
BN1 4GH United Kingdom
- Telephone: (+44) 07944 938204
- VAT GB 748125034
- UK Company Reg: 3932829