2

I have some fields on content node (not on product variation) like images, brand, and others that i want to show up in cart/order views on edit view in advance>relationship, you can add product refference and that enables the option to add fields from product variations, but i cant find a way to add fields that are on the content node

In less words: i want to add fileds like image that are on the content type to cart/order views.

Found a good work around:

adding relationship you can obtain fields from product in views.

4 Answers 4

2

This isn't easy, because the line item has no direct reference to the node. It does store the node URL in a textfield, but that does not a Views reference make. If you have a store where there's only one product display referencing each product, then you can get away with using a reverse product reference - i.e. starting with the line item, you reference the product, and from the product, you add a reverse reference to the "node referencing the product." Then you should be able to add fields from the product display node.

If you have multiple product displays referencing any given product, this solution might not work (unless of course each node contained the same fields you intend to pull into the View).

2
  • i have the idea of using two mysql selects and select the product reference and after that the node id and then render the fields, but i didn't want to go that far, still i think commerce needs to make a easyer way to do this, so you dont need to duplicate images for each sku, if you use the same images for every variation, is a wate of size. On some older project i've actualy made some nasty scripts to reduce the size, with 3-4000 products and some 3-4 variations each that has 4-5 hd images, it realy burns out the server space
    – Tica
    Feb 27, 2013 at 21:56
  • The easier way is to put 'em on nodes and do as I've described using reverse relationships to then make the image accessible to the View. I think you've basically implemented what we'd advise. The only other thing we can do is wait for a mature media handling module that lets you easily reference the same discreet file from multiple locations. (Note: such a module may already exist; I haven't checked out Media in a while.) Feb 28, 2013 at 19:48
0

Using Commerce Kickstart 2, I was able to accomplish this, sort of, by creating a taxonomy term "product_sku" and adding an image field to the term.

Then I created all of my base sku(s) there with the corresponding image.

I added my "product_sku" term to my variant type fields as a term reference and added to the display my image as an extracted field.

Now when I create a new variant, I just select the sku from the drop-down list instead of uploading an image.

This could easily get muddy if you have 1000s of products even without variants. I only have 200 or so but each one has 28 +/- variants(color) and some of those have additional options.

I've used the same approach for the color swatches so when it comes to creating the variations, 120 for one of my products(?AUTO-VARIANT CREATOR?), I don't have to upload anything. This also works in the content type. I use it for manufacturer and model reference terms in the catalog and to display attached logo and model images.

0

I did this with this method edit cart views(or you can did it in your views but my requirement was in cart views) add relation to product reference( I want get product id) then add php field in views, create a function in my custom module and call it in added php field (also cache it for better perfomrance :D )

function mymodule_get_nid_of_pid($pid){
  if ($cache = cache_get('nid-product-' . $pid)) {
    $data = $cache->data;
  }
  else {
  $query = new EntityFieldQuery();
  $result = $query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'products')
  ->fieldCondition('field_product_select', 'product_id', $pid)
  ->propertyCondition('status', 1)
  ->range(0,1)
  ->execute();
  if(array_keys($result['node'])){
  $data = current(array_keys($result['node']));
  cache_set('nid-product-' . $pid, $data, 'cache', REQUEST_TIME + (3600 * 24 ));
  }
  return $data;
}
0

To achieve this in views, you have to add a relationship named "Commerce Line item: Referenced products" and it will fetch field from your product node.

Not the answer you're looking for? Browse other questions tagged or ask your own question.