Hi

I have a CCK text field for the price of the item and I want this field to be automatically filled with the price parsed from amazon. Or alternatively let the amazon item cck field return only the price of the item.

I searched the issues but didn't find any thread about that scenario. Some threads state that it's possible to use tokens but I didn't figure how to use them.

Could you please tell me how to do this. thanks.

Comments

akadimi’s picture

Having amazon item returning the price olnly is the best way. How can I do that?
Thanks

rfay’s picture

I'm not sure what you're after here.

You may want to use the prepopulate module with just a bit of custom code.

Perhaps using views will give you the most flexibility. You can use a view of one item if you need to. http://drupal.org/node/595464

If you would like more support, please explain in detail exactly what you want to do.

-Randy

akadimi’s picture

OK, here's the scenario:

I have a CCK type which has a body for reviewing the product and some images stored locally on the server. Additionally there is some CCK field for some product specifications, all this data is filled manually and doesn't need to be parsed from amazon.

Now I need to append to the bottom of the node:

1. The price: "Price at amazon.fr: EUR XXX.XX".
2. the url of the item at amazon.

The way it's done now is by activating the amazon filter and creating two multiple lines CCK text fields (price and url) plus the asin fiel. Each time I create a new node I must fill these two fields manually like that:

[amazon 1430209895 lowestpriceformattedprice] // for the price

[amazon 1430209895 detailpageurl] // for the url

What I actually need is to only fill the amazon asin field, click save and then get my two CCK fields retrieved automatically.

And obviously these values must reflect the current data from amazon so my first thought about using tokens won't address this condition.

Another alternative:

After reflection, and to have accurate data, I wonder if it's possible to use only the amazon item CCK type and let it display the price and the url.

I saw that you can only choose between four display options which all display data that I don't need. Is there a means to choose only the price or the url?

I hope this has sufficient details

Thanks you in advance

Amine

rfay’s picture

I Amine - If you use the Amazon CCK type, then you can use an embedded view to access the individual data. It's a bit of overkill, but it's what comes to mind. You might want to try views_attach module to do that.

akadimi’s picture

Hi,

I already thought of using views to display the price and the url in a dedicated block but the view must have some linking to the node through view arguments. However, to present the price, the view must be of "Amazon item" type which provides no linking to the node.

Using a node-type view will allow linking but will not provide access to the amazon price item. I hope there is some way to use arguments to fetch the price. If so, please let me know how to do.

Thanks

rfay’s picture

Please read the section about using views. You do a node-type view with relationship to amazon item. http://drupal.org/node/595464#views

akadimi’s picture

I did that but the view displays all the prices from all the items that have an ASIN filled. How to display only the price of the current item

here's the view export:


$view = new view;
$view->name = 'item_price';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Paramètres par défaut', 'default');
$handler->override_option('relationships', array(
  'field_amazon_asin' => array(
    'label' => 'field_amazon_asin',
    'required' => 1,
    'id' => 'field_amazon_asin',
    'table' => 'node_data_field_amazon',
    'field' => 'field_amazon_asin',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'lowestpriceformattedprice' => array(
    'label' => 'Prix',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'exclude' => 0,
    'id' => 'lowestpriceformattedprice',
    'table' => 'amazon_item',
    'field' => 'lowestpriceformattedprice',
    'relationship' => 'field_amazon_asin',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler = $view->new_display('block', 'Bloc', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);
rfay’s picture

I think you're asking how to do a views argument, but I'm not sure. I would assume you'd want to use the nid as a views argument.

akadimi’s picture

I think too I have to use an argument, I tried the nid and the Amazon item , but the view returned no results. Maybe I'me not configuring the argument correctly. Could be you please give me more details.

akadimi’s picture

Status: Active » Fixed

Hi Randy,

It works now, I had to check "Provide default argument" Under "Action to take if argument is not present" Then select "Node ID from URL".

Thank you for your guidance.

rfay’s picture

Title: How to auto fill a CCK field with the amazon price » Access specific fields from ASIN on node page using a view

Thanks for the good work.

Remember, though, that somebody else is going to have this problem, so please finish with attaching an export of the view and CCK type you used and perhaps a slight discussion of what you did. It might help someone else who stumbles on this.

akadimi’s picture

OK, so to sum up:
One needs to access and display specific data from amazon API other than the four basic presentations available in the amazon item CCK field.

A solution is to display this data through a view.

First, make sure you have a node type where you have an Amazon item CCK field (I called this field "field_amazon"). This is the field where you will put the ASIN number of your amazon product.

Then, create a new node-type view and add a relationship to the Amazon item CCK field as documented here (2nd way): http://drupal.org/node/595464#views

Then, add an argument of type "Node: Nid". Under "Action to take if argument is not present", check "Provide default argument" then check "Node ID from URL" under "Provide default argument options".

Add the fields you want to display through the view, and if you want this data to be displayed in a block create a new block display. If you want this data to be directly embedded into the node you can have a look at this module: http://drupal.org/project/viewfield

Below is a basic view that displays a medium image and the price linked to the product page -the block is only necessary if you want to display information in a block-.

$view = new view;
$view->name = 'amazon_item_data';
$view->description = 'This view is for displaying amazon data fields associated with an amazon item';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Paramètres par défaut', 'default');
$handler->override_option('relationships', array(
  'field_amazon_asin' => array(
    'label' => 'field_amazon_asin',
    'required' => 1,
    'id' => 'field_amazon_asin',
    'table' => 'node_data_field_amazon',
    'field' => 'field_amazon_asin',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'product_image' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'image_size' => 'mediumimage',
    'link_format' => 'amazon',
    'exclude' => 0,
    'id' => 'product_image',
    'table' => 'amazon_item_image',
    'field' => 'product_image',
    'relationship' => 'field_amazon_asin',
    'presentation_format' => 'markup',
  ),
  'detailpageurl' => array(
    'label' => 'Detail page URL',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'exclude' => 1,
    'id' => 'detailpageurl',
    'table' => 'amazon_item',
    'field' => 'detailpageurl',
    'relationship' => 'field_amazon_asin',
  ),
  'lowestpriceformattedprice' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 1,
      'path' => '[detailpageurl]',
      'link_class' => '',
      'alt' => 'buy from Amazon',
      'prefix' => '',
      'suffix' => '',
      'target' => '_blank',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'exclude' => 0,
    'id' => 'lowestpriceformattedprice',
    'table' => 'amazon_item',
    'field' => 'lowestpriceformattedprice',
    'relationship' => 'field_amazon_asin',
  ),
));
$handler->override_option('arguments', array(
  'nid' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'Tous / Toutes',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'node',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'nid',
    'table' => 'node',
    'field' => 'nid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_fixed' => '',
    'default_argument_user' => 0,
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'montre' => 0,
      'page' => 0,
      'story' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '2' => 0,
      '1' => 0,
      '8' => 0,
      '9' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_php' => '',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler = $view->new_display('block', 'Bloc', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);

HTH

rfay’s picture

Thanks - excellent work!

FYI not so important but next time it will probably be cleaner to attach a text file with the exported view, as it's more accessible to people that way.

Thanks for the great contribution.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.