Im creating a view of products and cannot seem to sort the view by the product price. I am able to add the price field to the view but the Price field is not available when I an defining a sort for the view. Even when I add define the list style as a Table im not able to select the product price as the default sort. How can I sort the view by product price?

CommentFileSizeAuthor
#12 763238-2.patch1.88 KBxen
#7 763238.patch1.14 KBxen

Comments

gordon’s picture

I would loved to be able to do this, but this only figure for the price is the starting price. You this can be altered on the fly with the help of charges so you can add tax, levies and even discounts directly to the final product price even before you start manipulating them in the transaction.

There are kludges that you could do but they would only work on a small number of products and if you just directly sorted the products by price this will end up very confusing for the customer where products could end up out of order.

Also before you ask adding the final price to the database is not really an option because this can be altered based upon any number of things and the final price could be different between customers based upon any number of modifications to the charge.

markdamo’s picture

I don't have any additional changes/discounts to add to the product pricing so kludges may work for me. It just seems strange that a function of 'Sort by Price' which you can do on most ecommerce sites is not available in the Drupal ecommerce module. Thanks for the info anyway.

xen’s picture

Version: 6.x-4.0-rc9 » 6.x-4.0-rc15
Assigned: Unassigned » xen

Suggestion: make the price available under the name 'base price' and make it clear that it's the price before all the magic. It works for simple shops, and those doing funny things with prices will just have to deal with it.

(I should make a patch.. Yes.. I'll put it on my todo)

rubblemasta’s picture

Just come across the same roadblock recently myself, coincidence that this is a fresh discussion. I'm new to Drupal so I doubt that I've addressed this in the recommended way but my changes seem to be in line with what a patch would do rather than an override of some kind. Without further ado...

I modified ec_product.views.inc, more specifically the $data['ec_product']['price'] array:

  $data['ec_product']['price'] = array(
    'title' => t('Price'),
    'field' => array(
      'handler' => 'ec_product_views_handler_field_price',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );

Cleared my cache and it seems to work. The product_list view lets me add a sort criteria "Product: Price". Is there anything I've missed or any better way of doing this?

gordon’s picture

@Xen, that is a great idea, If you want to submit a price and I will commit it.

gordon’s picture

@runbblemasta this is ok, but the reason I didn't do this is because results will vary, and may give unexpected outcomes depending on how you configure additional charges. The suggestion of having a base price which gives the raw price will work great.

xen’s picture

Status: Active » Needs review
StatusFileSize
new1.14 KB

Added in a base_price field.

Status: Needs review » Needs work

The last submitted patch, 763238.patch, failed testing.

gordon’s picture

Version: 6.x-4.0-rc15 » 6.x-4.x-dev
Status: Needs work » Needs review

Submit it again against the dev branch so the testing is run.

gordon’s picture

#7: 763238.patch queued for re-testing.

gordon’s picture

Status: Needs review » Needs work
+++ ec_product/ec_product.views.inc	12 May 2010 15:37:56 -0000
@@ -62,11 +62,24 @@ function ec_product_views_data() {
+    'field' => array(
+      'handler' => 'ec_product_views_handler_field_price',
+      'click sortable' => TRUE,
+    ),

This handler this going to display the adjusted price and not the base price.

This is going to need a new display handler which just works on the field.

Powered by Dreditor.

xen’s picture

Status: Needs work » Needs review
StatusFileSize
new1.88 KB

Thought it was to quick.

Status: Needs review » Needs work

The last submitted patch, 763238-2.patch, failed testing.

carlhinton’s picture

I implemented this on my site, works a treat

xen’s picture

Assigned: xen » Unassigned