Problem/Motivation

Currently, there's no way to view the "Prices" of a variation without navigating to the price lists admin, and entering each individual existing price list, and figure out if there's a price for a given variation.
It'd be great to view the prices of a variation, from the variation admin directly.

Proposed resolution

Introduce a "Prices" tab for variations, as well as a "Prices" entity operation.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jsacksick created an issue. See original summary.

jsacksick’s picture

The attached patch adds a "Prices" tab + entity operation for variations (It'd probably make sense to have a similar tab for products as well), see screenshot below:

The "Prices" tab is provided by a view, which has a "Price list" exposed filter.

I wrote a functional test that tests the view and the entity operation.

I had to disable the view caching since the tests were failing when a second price list item was created for a variation and the "Prices" page was reloaded (the second price list item wasn't present on the page), there's probably a way to fix this, but could be implemented as a follow-up I guess.

I first tried grouping the prices by price list, but the result was kind of ugly, so decided to just sort the results by price list weight ASC + price list id DESC.

Unfortunately, there's currently no way to create a price list item from that page, since we'd need the price list id in order to do that.

Furthermore, Views doesn't provide a dropdown exposed filter for entityreference fields (See #2429699: Add Views EntityReference filter to be available for all entity reference fields), so I had to implement that via a hook_form_alter().

I also needed an argument default handler that wasn't present in Commerce (committed to core since, See #3093082: Create a views argument default plugin to extract a Product variation ID from URL), but I didn't want to require Commerce dev, or 2.16 for such a simple need so I copied the handler in Pricelist.

jsacksick’s picture

Status: Active » Needs review
jsacksick’s picture

Now that we require Commerce dev, we don't need the argument handler anymore.

jsacksick’s picture

FileSize
33.04 KB

I renamed the view to "commerce_product_variation_prices", and no longer turning the price list into a dropdown if there are more than 25 price lists...

I tried to fallback to the #entity_autocomplete element in that case, but for some reason, the view returns no results when no price list is selected in the autocomplete element.

jsacksick’s picture

FileSize
6.01 KB

Attaching the interdiff.

  • jsacksick committed b608b17 on 8.x-2.x
    Issue #3093494 by jsacksick: Introduce a 'Prices' tab for variations.
    
jsacksick’s picture

Status: Needs review » Fixed

Committed! I'll create 2 follow-up issues to allow adding prices from that page, and to implement a better "fallback" for the price list filter when there are more than 25 price lists.

  • jsacksick committed 1b0429d on 8.x-2.x
    Issue #3093494 followup by jsacksick: Add a post update function that...
eiriksm’s picture

Wow this looks great!

Is there an issue to do something similar with promotions? Would be great to have on the same page, actually.

Status: Fixed » Closed (fixed)

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