Hi,
Anyone experience with mapping from feeds to Ubercart products with price, image etc?
Thanks a lot in advance for your reply!

greetings,
Martijn

CommentFileSizeAuthor
#12 ubercart-457874-12.patch1.73 KBcedarm
#9 uc_product.inc_.gz597 byteswesleydv

Comments

rszrama’s picture

Status: Active » Closed (won't fix)

Hey Martijn, I'm not familiar myself, but you'll have much better luck finding like minded developers in our forums.

cedarm’s picture

Status: Closed (won't fix) » Needs review

This is a fairly simple hook to implement, at least for the basic fields. I'd like to see this added to core uc_product.module. Alternatively this can be submitted to the feedapi_mapper project as mappers/feedapi_mapper_uc_product.inc, but I think it makes more sense for it to live inside uc_product. What do you think?

This is the implementation I'm using right now:

/**
 * Implementation of hook_feedapi_mapper().
 *
 * @see hook_feedapi_mapper()
 */
function uc_product_feedapi_mapper($op, $node, $feed_element = array(), $field_name = '', $sub_field = '') {
  switch ($op) {
    case 'describe':
      // Description of this mapper.
      return t('Maps a string or number to Ubercart product fields.');
      break;

    case 'list':
      if (in_array($node->type, uc_product_types())) {
        // List of fields we can map to.
        // key = node property name, value = label 
        $fields = array(
          'model' => t('Model/SKU'),
          'list_price' => t('List price'),
          'cost' => t('Cost'),
          'sell_price' => t('Sell price'),
        );
        return $fields;
      }
      return FALSE;
      break;

    case 'map':
      // Here is where the actual mapping happens.
      if (!is_array($feed_element)) {
        $node->$field_name = $feed_element;
      }
      return $node;
      break;
  }
}

Edit: uc_product_node_is_product() was removed in ubercart-6.x-2.0-rc4. Changed (uc_product_node_is_product($node->type)) to (in_array($node->type, uc_product_types())).

kostajh’s picture

@cedarm, thanks! this is very helpful. It works fine for me.

summit’s picture

Hi, what would be the mapper for feeds (www.drupal.org/project/feeds) while feedelement_mapper will become obsolete?
Thanks for considering building this for feeds also!

greetings, Martijn

cedarm’s picture

@Summit, I didn't know about the feeds project until just now. Looks like a noble effort. Since I have already moved on to other projects, I won't be updating or working with feeds any time soon, so don't hold your breath. Hopefully our project will take off like crazy and I'll get to do more work on it... :)

presich’s picture

Guys, will be this feature (mapper to ubercart fields) added to the Feeds module soon?

Does anybody know???

cedarm’s picture

I don't know if anyone else is working on Feeds integration, but I plan to soon. Who wants to help with testing?

We should probably start a new feature request issue for Feeds integration.

presich’s picture

I think I could.

wesleydv’s picture

StatusFileSize
new597 bytes

Based on #2 I created uc_products.inc. Place this file in the feeds/mappers folder and you wil be able to import Model, List price, Cost & Sell price via Feeds

presich’s picture

))))))

I've written the same file yesterday but don't post it yet here.

For me it's work fine.

eileenmcnaughton’s picture

Hi,

I implemented this & it works but I also want to import stock levels. Am I right in thinking this has to be done as a separate import because the node hasn't been created when the import hook is called?

I see the product edit for calls this function

db_query("UPDATE {uc_product_stock} SET active = %d, stock = %d, threshold = %d WHERE sku = '%s'",
$form_state['values']['stock'][$id]['active'] ? 1 : 0, intval($form_state['values']['stock'][$id]['stock']),
intval($form_state['values']['stock'][$id]['threshold']), $form_state['values']['stock'][$id]['sku']);

cedarm’s picture

Title: feed element mapper for ubercart product node? » Feeds mapper for ubercart product node?
StatusFileSize
new1.73 KB

I'm going to step out here and say feedapi_mapper is pretty much dead now. I'm changing this issue to Feeds integration. Cleaned up and made a patch out of #9.

Kraftway’s picture

Hi,
I have applied file from #9 and it works fine. But there is another problem: how to map the feed elements to Ubercart product attributes? I think the attributes might be pre-created via admin UI Attributes, the problem is that different products could have different attributes set. Is this possible to map the only needed attributes to every product node from feed elements? And many thanks again to @cedarm! )

dubs’s picture

Hi there,

I have taken the patches from above and added some code to support product weights and attributes too.

The product had to be created first in order to add attributes to it, so this module uses hook_nodeapi to add them at "insert".

There is a new project release on this page: -

http://drupal.org/project/uc_feeds

If anyone fancies adding to the code (for stock etc..) or helping to maintain then please let me know.

Thanks,

Dubs

Anonymous’s picture

Status: Needs review » Closed (fixed)

uc_feeds looks good, will give it a try.

Looks like we can close this issue now. Future issues should be filled against the uc_feeds module.

Webpark’s picture

Need help with this. I want to import and map ubercart auctions rather than ubercart products. The properties are starting price, expiry date, expiry time and check that the product is an auction. Any development help would be appreciated.
Thanks.