Skip to content

Commit a60c5a2

Browse files
committed
MAGETWO-55937: [Complex product/Grouped productsl] Tax Amount and Custom Prices isn't displayed on Slide Panel (admin panel)
2 parents b98a2da + b05313e commit a60c5a2

File tree

8 files changed

+307
-1
lines changed

8 files changed

+307
-1
lines changed

app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function getAssociatedProducts($product)
202202
$collection = $this->getAssociatedProductCollection(
203203
$product
204204
)->addAttributeToSelect(
205-
['name', 'price', 'special_price', 'special_from_date', 'special_to_date']
205+
['name', 'price', 'special_price', 'special_from_date', 'special_to_date', 'tax_class_id']
206206
)->addFilterByRequiredOptions()->setPositionOrder()->addStoreFilter(
207207
$this->getStoreFilter($product)
208208
)->addAttributeToFilter(

dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Block/Catalog/Product/View.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,19 @@ public function fillOptions(FixtureInterface $product)
9494
{
9595
$this->getGroupedProductBlock()->fill($product);
9696
}
97+
98+
/**
99+
* Set quantity and click add to cart.
100+
* @param FixtureInterface $product
101+
* @param string|int $qty
102+
*/
103+
public function setQtyAndClickAddToCartGrouped(FixtureInterface $product, $qty)
104+
{
105+
$associatedProducts = $product->getAssociated()['products'];
106+
$groupedProductBlock = $this->getGroupedProductBlock();
107+
foreach ($associatedProducts as $product) {
108+
$groupedProductBlock->setQty($product->getId(), $qty);
109+
}
110+
$this->clickAddToCart();
111+
}
97112
}

dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Block/Catalog/Product/View/Type/Grouped.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ public function getQty($subProductId)
6565
return $this->_rootElement->find(sprintf($this->qtySubProductById, $subProductId))->getValue();
6666
}
6767

68+
/**
69+
* Set qty to subproduct block
70+
*
71+
* @param int $subProductId
72+
* @param string|int $qty
73+
* @return void
74+
*/
75+
public function setQty($subProductId, $qty)
76+
{
77+
$this->_rootElement->find(sprintf($this->qtySubProductById, $subProductId))->setValue($qty);
78+
}
79+
6880
/**
6981
* Fill product options on view page.
7082
*

dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Block/Checkout/Cart/CartItem.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Checkout\Test\Block\Cart\AbstractCartItem;
1010
use Magento\Checkout\Test\Block\Cart\CartItem as CheckoutCartItem;
11+
use Magento\Mtf\Client\Locator;
1112

1213
/**
1314
* Class CartItem
@@ -119,4 +120,57 @@ public function removeItem()
119120
$cartItem->removeItem();
120121
}
121122
}
123+
124+
/**
125+
* Get product price including tax
126+
*
127+
* @return string|null
128+
*/
129+
public function getPriceInclTax()
130+
{
131+
return $this->getPriceByType($this->priceInclTax, Locator::SELECTOR_XPATH);
132+
}
133+
134+
/**
135+
* Get product price excluding tax
136+
*
137+
* @return string|null
138+
*/
139+
public function getPriceExclTax()
140+
{
141+
return $this->getPriceByType($this->priceExclTax, Locator::SELECTOR_XPATH);
142+
}
143+
144+
/**
145+
* Get sub-total excluding tax for the specified item in the cart
146+
*
147+
* @return string|null
148+
*/
149+
public function getSubtotalPriceExclTax()
150+
{
151+
return $this->getPriceByType($this->subTotalPriceExclTax);
152+
}
153+
154+
/**
155+
* Get price for the specified item in the cart by the price type
156+
*
157+
* @return string|null
158+
*/
159+
public function getSubtotalPriceInclTax()
160+
{
161+
return $this->getPriceByType($this->subTotalPriceInclTax);
162+
}
163+
164+
/**
165+
* @param string $priceType
166+
* @param string $strategy
167+
* @return mixed|null
168+
*/
169+
private function getPriceByType($priceType, $strategy = Locator::SELECTOR_CSS)
170+
{
171+
$cartProductPrice = $this->_rootElement->find($priceType, $strategy);
172+
return $cartProductPrice->isVisible()
173+
? str_replace(',', '', $this->escapeCurrency($cartProductPrice->getText()))
174+
: null;
175+
}
122176
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\GroupedProduct\Test\Constraint;
8+
9+
use Magento\Cms\Test\Page\CmsIndex;
10+
use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
11+
use Magento\Catalog\Test\Page\Product\CatalogProductView;
12+
use Magento\Checkout\Test\Page\CheckoutCart;
13+
use Magento\Tax\Test\Constraint\AbstractAssertTaxRuleIsAppliedToAllPrices;
14+
use Magento\Mtf\Fixture\FixtureFactory;
15+
use Magento\Mtf\Fixture\FixtureInterface;
16+
use Magento\Mtf\Fixture\InjectableFixture;
17+
18+
/**
19+
* Checks that prices excl tax on category, product and cart pages are equal to specified in dataset.
20+
*/
21+
abstract class AbstractAssertTaxRuleIsAppliedToAllPricesOnGroupedProductPage extends
22+
AbstractAssertTaxRuleIsAppliedToAllPrices
23+
{
24+
25+
/**
26+
* Get grouped product view prices.
27+
*
28+
* @param FixtureInterface $product
29+
* @param array $actualPrices
30+
* @return array
31+
*/
32+
abstract protected function getGroupedProductPagePrices(FixtureInterface $product, array $actualPrices);
33+
34+
/**
35+
* Assert that specified prices are actual on category, product and cart pages.
36+
*
37+
* @param InjectableFixture $product
38+
* @param array $prices
39+
* @param int $qty
40+
* @param CmsIndex $cmsIndex
41+
* @param CatalogCategoryView $catalogCategoryView
42+
* @param CatalogProductView $catalogProductView
43+
* @param CheckoutCart $checkoutCart
44+
* @param FixtureFactory $fixtureFactory
45+
* @return void
46+
*/
47+
public function processAssert(
48+
InjectableFixture $product,
49+
array $prices,
50+
$qty,
51+
CmsIndex $cmsIndex,
52+
CatalogCategoryView $catalogCategoryView,
53+
CatalogProductView $catalogProductView,
54+
CheckoutCart $checkoutCart,
55+
FixtureFactory $fixtureFactory
56+
) {
57+
$this->cmsIndex = $cmsIndex;
58+
$this->catalogCategoryView = $catalogCategoryView;
59+
$this->catalogProductView = $catalogProductView;
60+
$this->checkoutCart = $checkoutCart;
61+
//Preconditions
62+
$address = $fixtureFactory->createByCode('address', ['dataset' => 'US_address_NY']);
63+
$shipping = ['shipping_service' => 'Flat Rate', 'shipping_method' => 'Fixed'];
64+
$actualPrices = [];
65+
//Assertion steps
66+
$productCategory = $product->getCategoryIds()[0];
67+
$this->openCategory($productCategory);
68+
$actualPrices = $this->getCategoryPrices($product, $actualPrices);
69+
$catalogCategoryView->getListProductBlock()->getProductItem($product)->open();
70+
$catalogProductView->getGroupedProductViewBlock()->fillOptions($product);
71+
$actualPrices = $this->getGroupedProductPagePrices($product, $actualPrices);
72+
$catalogProductView->getGroupedProductViewBlock()->setQtyAndClickAddToCartGrouped($product, $qty);
73+
$catalogProductView->getMessagesBlock()->waitSuccessMessage();
74+
$this->checkoutCart->open();
75+
$this->fillEstimateBlock($address, $shipping);
76+
$actualPrices = $this->getCartPrices($product, $actualPrices);
77+
$actualPrices = $this->getTotals($actualPrices);
78+
//Prices verification
79+
$message = 'Prices from dataset should be equal to prices on frontend.';
80+
\PHPUnit_Framework_Assert::assertEquals($prices, $actualPrices, $message);
81+
}
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\GroupedProduct\Test\Constraint;
8+
9+
use Magento\Mtf\Fixture\FixtureInterface;
10+
11+
/**
12+
* Checks that prices excl tax on category, product and cart pages are equal to specified in dataset.
13+
*/
14+
class AssertTaxRuleIsAppliedToAllPricesGroupedExcludingIncludingTax extends
15+
AbstractAssertTaxRuleIsAppliedToAllPricesOnGroupedProductPage
16+
{
17+
/**
18+
* @inheritdoc
19+
*/
20+
public function getCategoryPrices(FixtureInterface $product, $actualPrices)
21+
{
22+
$priceBlock = $this->catalogCategoryView->getListProductBlock()->getProductItem($product)->getPriceBlock();
23+
$actualPrices['category_price_excl_tax'] = $priceBlock->getPriceExcludingTax();
24+
$actualPrices['category_price_incl_tax'] = $priceBlock->getPriceIncludingTax();
25+
26+
return $actualPrices;
27+
}
28+
29+
/**
30+
* @inheritdoc
31+
*/
32+
public function getGroupedProductPagePrices(FixtureInterface $product, array $actualPrices)
33+
{
34+
$associatedProducts = $product->getAssociated();
35+
/** @var \Magento\GroupedProduct\Test\Block\Catalog\Product\View $groupedProductBlock */
36+
$this->catalogProductView = $this->catalogProductView->getGroupedProductViewBlock();
37+
foreach (array_keys($associatedProducts['products']) as $productIndex) {
38+
//Process assertions
39+
$this->catalogProductView ->itemPriceProductBlock(++$productIndex);
40+
$actualPrices['sub_product_view_prices_' . $productIndex] = $this->getProductPagePrices($actualPrices);
41+
}
42+
return $actualPrices;
43+
}
44+
45+
/**
46+
* @inheritdoc
47+
*/
48+
public function getProductPagePrices($actualPrices)
49+
{
50+
$priceBlock = $this->catalogProductView ->getPriceBlock();
51+
$productPrices['product_view_price_excl_tax'] = $priceBlock->getPriceExcludingTax();
52+
$productPrices['product_view_price_incl_tax'] = $priceBlock->getPriceIncludingTax();
53+
54+
return $productPrices;
55+
}
56+
57+
/**
58+
* @inheritdoc
59+
*/
60+
public function getTotals($actualPrices)
61+
{
62+
$totalsBlock = $this->checkoutCart->getTotalsBlock();
63+
$actualPrices['subtotal_excl_tax'] = $totalsBlock->getSubtotalExcludingTax();
64+
$actualPrices['subtotal_incl_tax'] = $totalsBlock->getSubtotalIncludingTax();
65+
$actualPrices['discount'] = $totalsBlock->getDiscount();
66+
$actualPrices['shipping_excl_tax'] = $totalsBlock->getShippingPrice();
67+
$actualPrices['shipping_incl_tax'] = $totalsBlock->getShippingPriceInclTax();
68+
$actualPrices['tax'] = $totalsBlock->getTax();
69+
$actualPrices['grand_total_excl_tax'] = $totalsBlock->getGrandTotalExcludingTax();
70+
$actualPrices['grand_total_incl_tax'] = $totalsBlock->getGrandTotalIncludingTax();
71+
72+
return $actualPrices;
73+
}
74+
}

dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Repository/GroupedProduct.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,33 @@
125125
<item name="dataset" xsi:type="string">grouped_three_simple_products</item>
126126
</field>
127127
</dataset>
128+
129+
<dataset name="grouped_product_with_special_price">
130+
<field name="name" xsi:type="string">Test grouped product with special price %isolation%</field>
131+
<field name="sku" xsi:type="string">sku_test_grouped_product_with_special_price_%isolation%</field>
132+
<field name="category_ids" xsi:type="array">
133+
<item name="dataset" xsi:type="string">default</item>
134+
</field>
135+
<field name="associated" xsi:type="array">
136+
<item name="dataset" xsi:type="string">defaultSimpleProduct_with_specialPrice</item>
137+
</field>
138+
<field name="status" xsi:type="string">Yes</field>
139+
<field name="visibility" xsi:type="string">Catalog, Search</field>
140+
<field name="tax_class_id" xsi:type="array">
141+
<item name="dataset" xsi:type="string">taxable_goods</item>
142+
</field>
143+
<field name="url_key" xsi:type="string">test-grouped-product-with-special-price-%isolation%</field>
144+
<field name="quantity_and_stock_status" xsi:type="array">
145+
<item name="is_in_stock" xsi:type="string">In Stock</item>
146+
</field>
147+
<field name="website_ids" xsi:type="array">
148+
<item name="0" xsi:type="array">
149+
<item name="dataset" xsi:type="string">default</item>
150+
</item>
151+
</field>
152+
<field name="attribute_set_id" xsi:type="array">
153+
<item name="dataset" xsi:type="string">default</item>
154+
</field>
155+
</dataset>
128156
</repository>
129157
</config>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\Tax\Test\TestCase\TaxCalculationTest" summary="Apply Taxes for grouped products" ticketId="MAGETWO-60576">
10+
<variation name="TaxCalculationTestGroupedProduct">
11+
<data name="product" xsi:type="string">groupedProduct::grouped_product_with_special_price</data>
12+
<data name="taxRule" xsi:type="string">us_full_tax_rule</data>
13+
<data name="shippingAddress/dataset" xsi:type="string">US_address_1</data>
14+
<data name="customer/dataset" xsi:type="string">johndoe_unique</data>
15+
<data name="salesRule" xsi:type="string">active_sales_rule_for_all_groups_no_coupon</data>
16+
<data name="catalogRule" xsi:type="string">-</data>
17+
<data name="configData" xsi:type="string">total_cat_excl_ship_incl_after_disc_on_excl, display_excluding_including_tax</data>
18+
<data name="flushCache" xsi:type="boolean">true</data>
19+
<data name="qty" xsi:type="string">3</data>
20+
<data name="prices/category_price_excl_tax" xsi:type="string">9.00</data>
21+
<data name="prices/category_price_incl_tax" xsi:type="string">9.90</data>
22+
<data name="prices/sub_product_view_prices_1/product_view_price_excl_tax" xsi:type="string">9.00</data>
23+
<data name="prices/sub_product_view_prices_1/product_view_price_incl_tax" xsi:type="string">9.90</data>
24+
<data name="prices/sub_product_view_prices_2/product_view_price_excl_tax" xsi:type="string">9.00</data>
25+
<data name="prices/sub_product_view_prices_2/product_view_price_incl_tax" xsi:type="string">9.90</data>
26+
<data name="prices/cart_item_price_excl_tax" xsi:type="string">9.00</data>
27+
<data name="prices/cart_item_price_incl_tax" xsi:type="string">9.90</data>
28+
<data name="prices/cart_item_subtotal_excl_tax" xsi:type="string">27.00</data>
29+
<data name="prices/cart_item_subtotal_incl_tax" xsi:type="string">29.70</data>
30+
<data name="prices/subtotal_excl_tax" xsi:type="string">54.00</data>
31+
<data name="prices/subtotal_incl_tax" xsi:type="string">59.40</data>
32+
<data name="prices/shipping_excl_tax" xsi:type="string">30.00</data>
33+
<data name="prices/shipping_incl_tax" xsi:type="string">30.00</data>
34+
<data name="prices/discount" xsi:type="string">27.00</data>
35+
<data name="prices/tax" xsi:type="string">2.70</data>
36+
<data name="prices/grand_total_excl_tax" xsi:type="string">57.00</data>
37+
<data name="prices/grand_total_incl_tax" xsi:type="string">59.70</data>
38+
<constraint name="Magento\GroupedProduct\Test\Constraint\AssertTaxRuleIsAppliedToAllPricesGroupedExcludingIncludingTax" />
39+
</variation>
40+
</testCase>
41+
</config>

0 commit comments

Comments
 (0)