Script for automatic import of ubercart items

Posted on 2011-05-13
Last Modified: 2012-05-11
I would like to make a cron job, which to update the curent ubercart nodes from CSV file , wich is uploaded via ftp. What is the best way for that (and to be invisible for the users)
Question by:Observer_123
    LVL 16

    Expert Comment

    Wright your own php code to perform exactly what you want to do, and insert it to cron.php
    When running, (based on your configuration), the task will be executed in the background.
    LVL 1

    Author Comment

    I suppose it have to   update to the followinf tables node, image and files?
    Is that All? Can I use some API from ubercart module instead of direct database insert?
    LVL 10

    Expert Comment

    You ask a big question, but I love your interest in automation. Here's a partial set of answers:

    Here's some great conversation about updating nodes from a spreadsheet (could be Ubercart related or other nodes I suppose):

    If you want to go the API route, you'll need to create a module that plugs in (I'm still learning this stuff) then start looking up a lot of API documentation, or to cheat you would create a script and 'bootstrap' Drupal to it so that you could call Drupal API functions. Either way, you have some research and hard work to do.

    Here's more info on how to bootstrap Drupal to a script (and create a new node):

    Does that help inspire something?

    LVL 1

    Author Comment

    for me the both (APIs or direct database input) could be decision.
    Could you point me in which tables I have to insert/delete to add/remove ubercart items?

    LVL 10

    Accepted Solution

    I don't have an ubercart installation in front of me, but I'm pretty sure you'll be playing with the following:

    Drupal in general (product pages/descriptions)
    node (top level overview data containing vid of node_revisions which has the guts - creating node link above will help with that)

    term_* (used for product categories and hierarchy I think, maybe other uses)
    uc_* (working from memory, but you will need to use many of these, some not)

    Other random notes:
    -backups, backups, backups
    -be sure to clear your Drupal cache after direct db alterations otherwise some changes may not be seen right away. Directly, that's any table starting with cache_, and 'cache' itself.
    -It may be handy to configure attributes in ubercart first before importing data, and figuring out a compatible way to reference this data when importing. Maybe not: it just seems complicated pre-coffee.

    Using the API, check out the links above for bootstrapped examples, and also check out the API documentation page for ubercart at:

    I'd lean towards the API first as it handles a lot of the things that often get missed when dealing with the database directly. I mention this as I built my own API that fed data to an external service from my Drupal site. Starting with direct database queries, I ran into tangles that got complicated, rewriting with Drupal API which reduced my code drastically and was helpful when I changed my Drupal CCK field structure.

    Let me know if that helps. :)
    LVL 1

    Author Closing Comment


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to count occurrences of each item in an array.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now