-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Shop] Different variant prices on product details page #6161
[Shop] Different variant prices on product details page #6161
Conversation
0b0af6e
to
d63eac1
Compare
Given the store operates on a single channel in "United States" | ||
And the store has a "Wyborowa Vodka" configurable product | ||
And the product "Wyborowa Vodka" has "Wyborowa Vodka Exquisite" variant priced at "$40.00" | ||
And the product "Wyborowa Vodka" has "Wyborowa Apple" variant priced at "$4.00" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Their prices differ by just one zero, can we use some other numbers than 4 and 0 to make the difference more clear?
* | ||
* @return View | ||
*/ | ||
protected function prepareHtmlRequestView(ProductInterface $resource, RequestConfiguration $configuration, View $view) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$resource
-> $product
]; | ||
|
||
if ( | ||
!$resource->isSimple() && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating $product->isConfigurable()
method which is a shortcut for !$product->isSimple()
would improve readability a lot.
|
||
$this->isGrantedOr403($configuration, ResourceActions::SHOW); | ||
/** @var ProductInterface $resource */ | ||
$resource = $this->findOr404($configuration); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we typehinting $resource anyway, can we change a name of variable?
$selector = ''; | ||
|
||
$('#sylius-product-adding-to-cart select').each(function() { | ||
$selector += '[data-'+$(this).attr('data-option')+'="'+$(this).find('option:selected').text()+'"]'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spaces before and after each '+'
@@ -153,6 +153,11 @@ public function storeHasAConfigurableProduct($productName) | |||
$product->setCode($this->convertToCode($productName)); | |||
$product->setDescription('Awesome '.$productName); | |||
|
|||
if ($this->sharedStorage->has('channel')) { | |||
$channel = $this->sharedStorage->get('channel'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$channel
is not used anywhere else. $product->addChannel($this->sharedStorage->get('channel'));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is still present.
/** | ||
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com> | ||
*/ | ||
class ProductVariantsPricesProvider implements ProductVariantsPricesProviderInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final?
3a8bc96
to
55793eb
Compare
55793eb
to
8230542
Compare
|
||
@ui | ||
Scenario: Viewing a detailed page with default variant's price | ||
When I check product "Wyborowa Vodka" details |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I view product "Wyborowa Vodka"
Scenario: Viewing a detailed page with product's price for different variant | ||
When I check product "Wyborowa Vodka" details | ||
And I select "Wyborowa Apple" variant | ||
Then I should see the product price "$12.55" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the product price should be "$12.55"
3520596
to
171918a
Compare
We need one more Behat scenario:
But this can be implemented in a separate PR. |
171918a
to
eb82868
Compare
@Zales0123 one last fix required to make it green. |
eb82868
to
3a3fe90
Compare
@michalmarcinkowski ready to go ;) |
|
||
/** @var OptionValueInterface $option */ | ||
foreach ($variant->getOptions() as $option) { | ||
$optionMap[$option->getOption()->getCode()] = $option->getValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use $option->getOptionCode()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We definitely should not override an entire controller and add protected methods to obtain this prices. You already have all the info (product + variants), so I'd say that Twig function that takes product as argument and returns array of prices would be a cleaner solution. We need it for the template, so overriding entire controller and processing the data you already have is not good. What do you think?
sylius_product_variant_prices(product)
Or something like that?
@pjedrzejewski seems reasonable for me 👍 |
e739c30
to
1fce4f9
Compare
Feature: Viewing different price for different product variants | ||
In order to see product variant price | ||
As a Visitor | ||
I want to be able to see proper price for each product variant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to be able to see a proper price for each product variant
@@ -153,6 +153,11 @@ public function storeHasAConfigurableProduct($productName) | |||
$product->setCode($this->convertToCode($productName)); | |||
$product->setDescription('Awesome '.$productName); | |||
|
|||
if ($this->sharedStorage->has('channel')) { | |||
$channel = $this->sharedStorage->get('channel'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is still present.
public function getFunctions() | ||
{ | ||
return [ | ||
new \Twig_SimpleFunction('sylius_product_variant_prices', [$this, 'getVariantsPrices']), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't it be simpler to use productVariantsPricesHelper
directly?
new \Twig_SimpleFunction('sylius_product_variant_prices', [$this->productVariantsPricesHelper, 'getPrices'])
Thanks Mateusz! :) Nice work! |
👍 I will apply last comments in additional PR in a minute. |
…n-product-details [Shop] Different variant prices on product details page
On product details page, we have always one price displayed (from the first/default/etc variant). It's obviously confusing, as we could have different price for each variant - therefore it should change after changing variant/option. In this PR, I will implement some lovely JS script, to handle this logic and make Sylius product details page more and more perfect, to reach the sky and more with its perfectness 🌠 🎉