Skip to content
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

Merged

Conversation

Zales0123
Copy link
Member

@Zales0123 Zales0123 commented Sep 20, 2016

Q A
Bug fix? yes
New feature? yes
BC breaks? no
Related tickets
License MIT

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 🌠 🎉

zrzut ekranu 2016-09-20 o 15 22 58
zrzut ekranu 2016-09-20 o 15 23 03
zrzut ekranu 2016-09-20 o 15 23 26
zrzut ekranu 2016-09-20 o 15 24 09

@Zales0123 Zales0123 changed the title [WIP][Behat][Shop] Different product variant prices scenario [WIP][Behat][Shop] Different variant prices on product details page Sep 20, 2016
@Zales0123 Zales0123 changed the title [WIP][Behat][Shop] Different variant prices on product details page [WIP][Shop] Different variant prices on product details page Sep 20, 2016
@Zales0123 Zales0123 force-pushed the display-variant-price-on-product-details branch from 0b0af6e to d63eac1 Compare September 20, 2016 11:52
@Zales0123 Zales0123 changed the title [WIP][Shop] Different variant prices on product details page [Shop] Different variant prices on product details page Sep 20, 2016
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"
Copy link
Contributor

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)
Copy link
Contributor

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() &&
Copy link
Contributor

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);
Copy link
Member

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()+'"]';
Copy link
Member

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');
Copy link
Member

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'));

Copy link
Member

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final?

@Zales0123 Zales0123 force-pushed the display-variant-price-on-product-details branch 2 times, most recently from 3a8bc96 to 55793eb Compare September 22, 2016 07:45
@michalmarcinkowski michalmarcinkowski added New Feature Shop ShopBundle related issues and PRs. labels Sep 22, 2016
@Zales0123 Zales0123 force-pushed the display-variant-price-on-product-details branch from 55793eb to 8230542 Compare September 23, 2016 12:57

@ui
Scenario: Viewing a detailed page with default variant's price
When I check product "Wyborowa Vodka" details
Copy link
Contributor

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"
Copy link
Contributor

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"

@Zales0123 Zales0123 force-pushed the display-variant-price-on-product-details branch 2 times, most recently from 3520596 to 171918a Compare September 23, 2016 13:51
@michalmarcinkowski
Copy link
Contributor

We need one more Behat scenario:

Give the store has a "Wyborowa Vodka" configurable product
And this product has option "Volume" with values "0.5L", "0.7L" and "1L"
And this product is available in "0.5L" volume priced at "$20.00"
And this product is available in "0.7L" volume priced at "$25.00"
When I view this product
And I select "1L" option
Then the product price should be "unavailable"

But this can be implemented in a separate PR.

@Zales0123 Zales0123 force-pushed the display-variant-price-on-product-details branch from 171918a to eb82868 Compare September 23, 2016 14:14
@michalmarcinkowski
Copy link
Contributor

@Zales0123 one last fix required to make it green.

@Zales0123 Zales0123 force-pushed the display-variant-price-on-product-details branch from eb82868 to 3a3fe90 Compare September 23, 2016 16:50
@Zales0123
Copy link
Member Author

@michalmarcinkowski ready to go ;)


/** @var OptionValueInterface $option */
foreach ($variant->getOptions() as $option) {
$optionMap[$option->getOption()->getCode()] = $option->getValue();
Copy link
Contributor

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()

Copy link
Member

@pjedrzejewski pjedrzejewski left a 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?

@Zales0123
Copy link
Member Author

@pjedrzejewski seems reasonable for me 👍

@Zales0123 Zales0123 force-pushed the display-variant-price-on-product-details branch from e739c30 to 1fce4f9 Compare September 30, 2016 06:20
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
Copy link
Member

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');
Copy link
Member

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']),
Copy link
Member

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'])

@pjedrzejewski pjedrzejewski merged commit 81c7687 into Sylius:master Sep 30, 2016
@pjedrzejewski
Copy link
Member

Thanks Mateusz! :) Nice work!

@Zales0123
Copy link
Member Author

👍 I will apply last comments in additional PR in a minute.

@Zales0123 Zales0123 deleted the display-variant-price-on-product-details branch October 6, 2016 20:32
pamil pushed a commit to pamil/Sylius that referenced this pull request May 7, 2019
…n-product-details

[Shop] Different variant prices on product details page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Shop ShopBundle related issues and PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants