From 177940da2f7ba937cf3daafb190f47d0d7fd451a Mon Sep 17 00:00:00 2001 From: Mikalai_Shostka <Mikalai_Shostka@epam.com> Date: Fri, 9 Dec 2016 14:38:01 +0300 Subject: [PATCH] MAGETWO-61554: UX improvements --- .../Product/Form/Modifier/BundlePanel.php | 40 +++++++++++++++++++ app/code/Magento/Bundle/etc/adminhtml/di.xml | 4 +- app/code/Magento/Bundle/etc/di.xml | 1 + .../templates/product/price/tier_prices.phtml | 2 +- .../Config/Source/Product/Options/Price.php | 2 +- .../Product/Attribute/Backend/Tierprice.php | 1 + .../Product/Form/Modifier/TierPrice.php | 1 + .../Magento/Persistent/Model/Observer.php | 9 ++++- .../web/css/source/_module.less | 16 ++++++++ .../AssertProductTierPriceInCart.php | 2 +- .../Test/Repository/Product/TierPrice.xml | 2 +- 11 files changed, 73 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePanel.php b/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePanel.php index 538c80d9b1c..4012af357e2 100644 --- a/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePanel.php +++ b/app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePanel.php @@ -14,6 +14,8 @@ use Magento\Ui\Component\Container; use Magento\Ui\Component\DynamicRows; use Magento\Ui\Component\Form; use Magento\Ui\Component\Modal; +use Magento\Catalog\Api\Data\ProductAttributeInterface; +use Magento\Catalog\Model\Config\Source\ProductPriceOptionsInterface; /** * Create Ship Bundle Items and Affect Bundle Product Selections fields @@ -73,6 +75,7 @@ class BundlePanel extends AbstractModifier */ public function modifyMeta(array $meta) { + $meta = $this->removeFixedTierPrice($meta); $path = $this->arrayManager->findPath(static::CODE_BUNDLE_DATA, $meta, null, 'children'); $meta = $this->arrayManager->merge( @@ -178,6 +181,43 @@ class BundlePanel extends AbstractModifier return $meta; } + /** + * Remove option with fixed tier price from config. + * + * @param array $meta + * @return array + */ + private function removeFixedTierPrice(array $meta) + { + $tierPricePath = $this->arrayManager->findPath( + ProductAttributeInterface::CODE_TIER_PRICE, + $meta, + null, + 'children' + ); + $pricePath = $this->arrayManager->findPath( + ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE, + $meta, + $tierPricePath + ); + $pricePath = $this->arrayManager->slicePath($pricePath, 0, -1) . '/value_type/arguments/data/options'; + + $price = $this->arrayManager->get($pricePath, $meta); + $meta = $this->arrayManager->remove($pricePath, $meta); + foreach ($price as $key => $item) { + if ($item['value'] == ProductPriceOptionsInterface::VALUE_FIXED) { + unset($price[$key]); + } + } + $meta = $this->arrayManager->merge( + $this->arrayManager->slicePath($pricePath, 0, -1), + $meta, + ['options' => $price] + ); + + return $meta; + } + /** * {@inheritdoc} */ diff --git a/app/code/Magento/Bundle/etc/adminhtml/di.xml b/app/code/Magento/Bundle/etc/adminhtml/di.xml index ca93dd53651..19b683027df 100644 --- a/app/code/Magento/Bundle/etc/adminhtml/di.xml +++ b/app/code/Magento/Bundle/etc/adminhtml/di.xml @@ -27,11 +27,11 @@ <argument name="modifiers" xsi:type="array"> <item name="bundle" xsi:type="array"> <item name="class" xsi:type="string">Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\Composite</item> - <item name="sortOrder" xsi:type="number">125</item> + <item name="sortOrder" xsi:type="number">180</item> </item> <item name="bundle_stock_data" xsi:type="array"> <item name="class" xsi:type="string">Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\StockData</item> - <item name="sortOrder" xsi:type="number">126</item> + <item name="sortOrder" xsi:type="number">190</item> </item> </argument> </arguments> diff --git a/app/code/Magento/Bundle/etc/di.xml b/app/code/Magento/Bundle/etc/di.xml index 2d3913d72e5..3425b9323ed 100644 --- a/app/code/Magento/Bundle/etc/di.xml +++ b/app/code/Magento/Bundle/etc/di.xml @@ -130,4 +130,5 @@ </argument> </arguments> </type> + </config> diff --git a/app/code/Magento/Bundle/view/base/templates/product/price/tier_prices.phtml b/app/code/Magento/Bundle/view/base/templates/product/price/tier_prices.phtml index 3285603c431..63f090acf34 100644 --- a/app/code/Magento/Bundle/view/base/templates/product/price/tier_prices.phtml +++ b/app/code/Magento/Bundle/view/base/templates/product/price/tier_prices.phtml @@ -22,7 +22,7 @@ $tierPrices = $tierPriceModel->getTierPriceList(); <?php /* @escapeNotVerified */ echo __( 'Buy %1 with %2 discount each', $price['price_qty'], - '<strong class="benefit">' . $tierPriceModel->getSavePercent($price['price']) . '%</strong>' + '<strong class="benefit">' . round($price['percentage_value']) . '%</strong>' ); ?> </li> <?php endforeach; ?> diff --git a/app/code/Magento/Catalog/Model/Config/Source/Product/Options/Price.php b/app/code/Magento/Catalog/Model/Config/Source/Product/Options/Price.php index b994c787bee..5e518df37db 100644 --- a/app/code/Magento/Catalog/Model/Config/Source/Product/Options/Price.php +++ b/app/code/Magento/Catalog/Model/Config/Source/Product/Options/Price.php @@ -23,7 +23,7 @@ class Price implements ProductPriceOptionsInterface { return [ ['value' => self::VALUE_FIXED, 'label' => __('Fixed')], - ['value' => self::VALUE_PERCENT, 'label' => __('Percent')], + ['value' => self::VALUE_PERCENT, 'label' => __('Discount')], ]; } } diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Tierprice.php b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Tierprice.php index 480f8e8942e..460204a478d 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Tierprice.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Tierprice.php @@ -157,6 +157,7 @@ class Tierprice extends \Magento\Catalog\Model\Product\Attribute\Backend\GroupPr $data = parent::modifyPriceData($object, $data); foreach ($data as $key => $tierPrice) { if ($this->getPercentage($tierPrice)) { + $data[$key]['price'] = $object->getPrice() * (1 - $this->getPercentage($tierPrice) / 100); $data[$key]['website_price'] = $object->getPrice() * (1 - $this->getPercentage($tierPrice) / 100); } } diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/TierPrice.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/TierPrice.php index ac511edcf2e..9b382464e8e 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/TierPrice.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/TierPrice.php @@ -109,6 +109,7 @@ class TierPrice extends AbstractModifier 'label' => __('Price'), 'enableLabel' => true, 'dataScope' => '', + 'additionalClasses' => 'control-grouped', 'sortOrder' => isset($priceMeta['arguments']['data']['config']['sortOrder']) ? $priceMeta['arguments']['data']['config']['sortOrder'] : 40, ], diff --git a/app/code/Magento/Persistent/Model/Observer.php b/app/code/Magento/Persistent/Model/Observer.php index 283d7bb45a5..392d88a29a5 100644 --- a/app/code/Magento/Persistent/Model/Observer.php +++ b/app/code/Magento/Persistent/Model/Observer.php @@ -121,6 +121,13 @@ class Observer public function emulateTopLinks($block) { $this->_applyAccountLinksPersistentData(); - $block->removeLinkByUrl($this->_url->getUrl('customer/account/login')); + /** @var \Magento\Framework\View\Element\Html\Link[] $links */ + $links = $block->getLinks(); + $removeLink = $this->_url->getUrl('customer/account/login'); + foreach ($links as $link) { + if ($link->getHref() == $removeLink) { + $this->_layout->unsetChild($block->getNameInLayout(), $link->getNameInLayout()); + } + } } } diff --git a/app/design/adminhtml/Magento/backend/Magento_Catalog/web/css/source/_module.less b/app/design/adminhtml/Magento/backend/Magento_Catalog/web/css/source/_module.less index 304f895a85b..77a769d8f5a 100644 --- a/app/design/adminhtml/Magento/backend/Magento_Catalog/web/css/source/_module.less +++ b/app/design/adminhtml/Magento/backend/Magento_Catalog/web/css/source/_module.less @@ -78,3 +78,19 @@ margin-top: -@indent__base; } } + +// +// Advanced Price panel +// --------------------------------------------- + +.admin__control-fields { + .control-grouped { + .lib-vendor-prefix-display(inline-flex); + .lib-vendor-prefix-flex-direction(row); + + .admin__field + .admin__field { + margin-left: @indent__s; + margin-top: 0; + } + } +} diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductTierPriceInCart.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductTierPriceInCart.php index 1bc689d8e1b..f8266026b39 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductTierPriceInCart.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductTierPriceInCart.php @@ -110,7 +110,7 @@ class AssertProductTierPriceInCart extends AbstractConstraint { $tierPrice = $product->getDataFieldConfig('tier_price')['source']->getData()[0]; - if ($tierPrice['value_type'] === "Percent") { + if ($tierPrice['value_type'] === "Discount") { $this->fixtureActualPrice = $this->fixturePrice * (1 - $tierPrice['percentage_value'] / 100); } else { $this->fixtureActualPrice = $tierPrice['price']; diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/Product/TierPrice.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/Product/TierPrice.xml index 2f517f4d6cf..9581427d16e 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/Product/TierPrice.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/Product/TierPrice.xml @@ -92,7 +92,7 @@ <dataset name="custom_with_percentage_discount"> <field name="0" xsi:type="array"> - <item name="value_type" xsi:type="string">Percent</item> + <item name="value_type" xsi:type="string">Discount</item> <item name="percentage_value" xsi:type="string">3</item> <item name="website" xsi:type="string">All Websites [USD]</item> <item name="price_qty" xsi:type="string">10</item> -- GitLab