Comments

pattison22’s picture

Would love to know as well!!

krlucas’s picture

The module currently has minimal Views integration. You can create a list of option sets or option set types but that's about it. You can't add relationships to the the line items or products that reference the option sets.

So attached is a patch that allows you to add those important relationships.

My own perspective is that this module should probably be requiring and implementing entityreference module instead of trying to re-invent the wheel.

krlucas’s picture

Status: Active » Needs review
oadaeh’s picture

Status: Needs review » Reviewed & tested by the community

I applied the patch in #2, and it worked for me to fix the lack of relationships.

Other than the two very minor things below, the code seems to be okay.

+++ includes/views/commerce_option.views.inc	(revision )
@@ -1,27 +1,52 @@
+ * @param $data

Unnecessary on hook functions. See the Hook implementation subsection of Drupal API documentation standards for functions.

+++ includes/views/commerce_option.views.inc	(revision )
@@ -1,27 +1,52 @@
+function commerce_option_views_data_alter(&$data){
 
+  $data['commerce_product']['commerce_option'] = array(

Unnecessary extra line. (I couldn't locate a coding standard for this, so it's up to you.)

oadaeh’s picture

I should have added that I don't think those two things I mentioned should keep this patch from being included. I was only pointing them out.

Rosamunda’s picture

Hi there,
I see this is already reviewed... is this going to be commited soon? :)

Homotechsual’s picture

Issue summary: View changes

Still not committed by the looks of things, definitely not in a release yet. Big shame as it has taken a long time to track this issue down and locate this patch!

jeremyr’s picture

I've applied this patch and it works great. I can pull these into a view now, however, it appears that only User1 can view the options. Does that sound like there should be a permissions check box or something?

jeremyr’s picture

I take back my previous question about the permissions thing. It works as expected. My problem was related to the theme taking over the views table when not using the admin overlay.

brylie’s picture

Priority: Normal » Major

Increasing priority to Major, as there are several issues dependent on the requested Views support.

cord1’s picture

I found a possible solution but it only shows up for administrators due to permissions.
http://www.drupalcommerce.org/questions/13840/how-make-view-products-price

mlmoseley’s picture

I've applied this patch but I see no way to show selected option sets on the shopping cart form -- if someone could tell me how to make views show not the option sets for a given line item, but the elements of those sets the user selected. In other words, what he/she ordered. For example, one might be able to order Nixons papers from an historical library. The product is Nixon's papers, but you can using an option set, you don't have to order all of them. In the example below 'Items' is an option set and the user has selected only three of the set.

Product           Items
=======           ====
Nixon's Papers    Ca Gov, President, Retirement.

So far I can't make something like this appear in the Drupal Commerce cart.

Help?

  • d275afb committed on 7.x-1.x
    Issue #1696656 by krlucas: Views integration
    
Anonymous’s picture

Status: Reviewed & tested by the community » Closed (fixed)

@mlmoseley To get the individual options from your set to show up, you need to first create a relation to your commerce option set. That is what this patch allows. Afterwards you can add your separate fields using this relation.

Anyhow, I've committed this to the latest dev version. Thanks to all involved for patching and reviewing.

josebc’s picture

Status: Closed (fixed) » Needs work

I was checking the latest dev 7.x-1.x-dev and those are the contents of includes/views/commerce_option.views.inc
which does not work as stated above, however on the 2.x branch the hook_views_data_alter looks correct
i think this needs to be ported to the 1.x branch also
<?php

/**
* Export Drupal Commerce orders to Views.
*/

function commerce_option_views_data_alter(&$data){
foreach ($data as $table_name => &$table){
if ($table_name == 'commerce_line_item'){
/*foreach($table as $field_name => &$field) {
if($field_name == 'type') {
$field['relationship'] = array(
'base' => 'commerce_order_total_line_type',
'handler' => 'views_handler_relationship',
'label' => t('Order Total Type'),
'base field' => 'line_item_type',
'field' => 'type',
);
}
}*/

}
}
}

Anonymous’s picture

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

Development on the 1.x branch has stopped. Please just use the patch for the 1.x branch.

bisonbleu’s picture

Followed @samspinoy's suggestion in #16. Applying patch in #2 works for me. I was then able to display the selected Option Set option in the checkout. Thanks @krlucas!

FranCarstens’s picture

Patch from #2 works a treat. Unfortunately, if you have multiple option set reference fields the line item is duplicated in the view.

EDIT: there are two issues with displaying unselected options. For example let's say we have a computer store and the following options set:

  • Monitor
    • HP
    • LG
  • Keyboard
    • Logitech
    • Nolable
  • Mouse
    • Logitech
    • Nolable
  • Printer
    • HP
    • Canon

Let’s say I’m selling a laptop that doesn’t have the monitor or keyboard option, so we only activate Mouse and Printer in the product variation, for example:

Computer Options
[ ] Monitor
[ ] Keyboard
[-] Mouse
[-] Printer

Product display shows Mouse and Keyboard, but in cart all for options show up (even if the field is set up as “hide rewriting if empty, hide if empty, hide if contents is 0”)

Creating multiple option sets is all good and well if you need only a couple of versions, but with a large inventory and multiple complex option configurations it becomes a nightmare.

The same thing happens if the option selected is not required and is left as N/A. A lowercase version of the first option is shown, not N/A or nothing.

giorgosk’s picture

#2 works as advertised

pradeepjha’s picture

Whenever I'm doing checkout with new option set value. In the cart view it's showing random value from product option. I think line item reference with product option set not working. Please help in fixing.

bisonbleu’s picture

@pradeepjha, it's difficult to help you if you don't provide more details...

misterpo’s picture

Hi there,

Didi somebody manage to have the option price displayed in the order details and/or in the cart ?

I have read many posts that loop to each other and involve Pricing Attributes and Product Attributes modules.

Cheers.

bisonbleu’s picture

@misterpo, I was able to display the option price in the cart by editing the cart view: Shopping cart form (Commerce Order).

In order to add the Commerce option you require in the Fields pane of Views, you will first need to add a relationship (Advanced pane) of type Commerce options referenced by this line item.

misterpo’s picture

@bisonbleu,

Thanks for your help but I can only get the option label using the "Commerce options referenced by this line item" relationship.

Cheers

bisonbleu’s picture

@misterpo, you first need to apply the patch in #2. Did you? More info here on how to apply patches.

Once patch in #2 is applied, you 1) add the relationship

Commerce Option relationship

and then 2) add your option field

Commerce Option field

misterpo’s picture

StatusFileSize
new65.34 KB
new17.17 KB
new47.22 KB

Hi @bisonbleu,

Sorry for my late answer...

I have of course applied the patch and added the mentioned relationships.

I can add the Commerce options fields in the view but they only have a "Default" and "Key" formatter and there is no way to get the price.

Please see attached sceenshots.

Thanks for your help.

bisonbleu’s picture

StatusFileSize
new56.45 KB

I also only see "Default" and "Key" formatters. But in my use case i get what I need which is to display the rental period price.

In Fields I have:

  • (Commerce option) Commerce Option: Rental period, which I exclude.
  • (Line items referenced by commerce_line_items) Commerce Line item: Unit price (Price) which I rewrite as [commerce_unit_price] per [field_os_rental_period]

And this is what I get in the cart.

Cart showing CPA

misterpo’s picture

OK, so you don't really display the option price but the line item price.

I have many product options per line item and really need to show them in the cart and order summary - customer will.

Please help.

bisonbleu’s picture

StatusFileSize
new206.8 KB

The prices displayed in the capture in #27 are the option prices.

In my use case (a rental store) I'm using CPO in conjunction with CPA and a bunch of other modules. The setup is rather complex.

I have an option set Rental period with the following Pricing attributes:

  • 1 day = 1 x basic price
  • 1 week = 3.5 x basic price
  • 15 days = 7 x basic price
  • 1 month = 10.5 x basic price
  • etc.

This translates as follows for the Tomcat (3020.5) 10 ft. truss which has a $7.79 basic price:

  • 1 day = $7.79
  • 1 week = $27.27
  • 15 days = $54.53
  • 1 month = $81.80
  • etc.

And this is what the product page looks like.

product page

misterpo’s picture

Of course, you are right but it works because your option price fits the line item price which is computed according to your options !

According to me, it is not possible to show the price of each individual selected option, which is my customer's need (really makes sense in the order summary).

I hope I am wrong...

bisonbleu’s picture

StatusFileSize
new41.08 KB

It's just as easy to add the Options to the order summary table (see capture). BTW, it's not exactly clear what you're trying to achieve. Perhaps you could provide a mockup ?

Order summary

misterpo’s picture

Hi,

Indeed, it's easy to add the option label to the cart/order summary.

My product is a registration to a car event.

This product has an options set composed of 3 fields (Paiement (Payment), Hébergement (Hotel booking) and Transport.

Each field is a checkbox/radio buttons list of different values and thus different pricing attributes.

I aim at showing the selected option pricing attributes in the cart and order summary.

You may try it at https://dev.rallystory.com/en/rallyes/28th-coupe-des-alpes and then click on the "Register online button".

Cheers.

bisonbleu’s picture

I went and I got "This product is not available for registration at this time". A screen capture with a short explanation would allow more folks to interact and participate.

misterpo’s picture

StatusFileSize
new93.24 KB

Sorry about that, I can't reproduce the problem you've got.

The attached screenshot will show you the available options.

In my cart, insted of having :

28e Coupe des Alpes (Unlimited slots available)
Payment : Acompte
Hotel booking : Option 2 chambres singles
Transport : PARIS/EVIAN

I would like to have :

28e Coupe des Alpes (Unlimited slots available)
Payment : Acompte +1 650,00 €
Hotel booking : Option 2 chambres singles +950,00 €
Transport : PARIS/EVIAN +850,00 €

Hope this is clear enough.

bisonbleu’s picture

StatusFileSize
new13.87 KB

It's clearer now, yes.

Unless I'm missing something, can you not just add "(+amount)" to your option set labels?

Options + amount

If not then I think the only option left would be creating a custom module with the appropriate hook_form_alter()

misterpo’s picture

Hi bisonbleu,

Of course, I need to get these options price dynamically so I don't know what "(+amount)" is about.

Did anybody manage to get this working ?

To me, it is an essential feature.

misterpo’s picture

To make myself clearer, product options prices are different between products.

So no way to show them statically.

bisonbleu’s picture

Can you expand how you set your product options prices? With Rules?

misterpo’s picture

StatusFileSize
new409.97 KB

Hi,

I just set my option price by editing the product in admin/commerce/products.

It works like a charm except than I can't get these options prices in views :-(

emmanvazz’s picture

StatusFileSize
new45.79 KB

I ran into the same issue as @FranCarstens with "Unfortunately, if you have multiple option set reference fields the line item is duplicated in the view." Say you have one option set for Colors of a shirt and another for Size on the same product your get two lines in the view. This is what I currently get in the view.

bisonbleu’s picture

@misterpo

It works like a charm except than I can't get these options prices in views :-(

I think what you want/need is a custom Views handler.

I'm trying to solve a similar problem and after much R&D I'm moving in that direction, i.e. creating a Views handler. See #2733733: How to expose a product attribute in the bulk add-to-cart form?.

REFERENCES
- Writing Field Handlers for Views
- Custom Views Field Handler

lachezar.valchev’s picture

Hi,

I needed the provided patch and it works for me, but I had to re-roll it. Here is the re-rolled one.