diff --git a/app/code/Magento/Catalog/Ui/Component/ColumnFactory.php b/app/code/Magento/Catalog/Ui/Component/ColumnFactory.php index 128e757ab53eb8ef66a5c16930cf9061381566ea..0b699db5a00526ac06dbbd206b41cdc541e03bd5 100644 --- a/app/code/Magento/Catalog/Ui/Component/ColumnFactory.php +++ b/app/code/Magento/Catalog/Ui/Component/ColumnFactory.php @@ -7,11 +7,6 @@ namespace Magento\Catalog\Ui\Component; class ColumnFactory { - /** - * @var int - */ - private $columnSortOrder = 0; - /** * @var \Magento\Framework\View\Element\UiComponentFactory */ @@ -49,22 +44,20 @@ class ColumnFactory /** * @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute * @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context - * @param int $columnsAmount + * @param array $config * @return \Magento\Ui\Component\Listing\Columns\ColumnInterface */ - public function create($attribute, $context, $columnsAmount) + public function create($attribute, $context, array $config = []) { - $this->columnSortOrder += 1; $columnName = $attribute->getAttributeCode(); - $config = [ + $config = array_merge([ 'label' => __($attribute->getDefaultFrontendLabel()), 'dataType' => $this->getDataType($attribute), 'sorting' => 'asc', 'align' => 'left', 'add_field' => true, 'visible' => $attribute->getIsVisibleInGrid(), - 'sortOrder' => $this->columnSortOrder + $columnsAmount, - ]; + ], $config); if ($attribute->usesSource()) { $config['options'] = $attribute->getSource()->getAllOptions(); diff --git a/app/code/Magento/Catalog/Ui/Component/Listing/Columns.php b/app/code/Magento/Catalog/Ui/Component/Listing/Columns.php index 68d9866733af053ae83cf7a92d0bd8c9964ac0af..6c1bd86c66b75821f94db0868399bd4e4802ef10 100644 --- a/app/code/Magento/Catalog/Ui/Component/Listing/Columns.php +++ b/app/code/Magento/Catalog/Ui/Component/Listing/Columns.php @@ -31,10 +31,11 @@ class Columns extends \Magento\Ui\Component\Listing\Columns */ public function prepare() { - $columnsAmount = count($this->components); + $columnSortOrder = count($this->components); foreach ($this->attributeRepository->getList() as $attribute) { if (!isset($this->components[$attribute->getAttributeCode()])) { - $column = $this->columnFactory->create($attribute, $this->getContext(), $columnsAmount); + $config['sortOrder'] = ++$columnSortOrder; + $column = $this->columnFactory->create($attribute, $this->getContext(), $config); $column->prepare(); $this->addComponent($attribute->getAttributeCode(), $column); } diff --git a/app/code/Magento/Catalog/Ui/Component/Listing/Columns/Price.php b/app/code/Magento/Catalog/Ui/Component/Listing/Columns/Price.php index 35319340b7114b0d5843c7be485b259121b6907d..6d647d6b485312ebfb8af71ef861cad6de174652 100644 --- a/app/code/Magento/Catalog/Ui/Component/Listing/Columns/Price.php +++ b/app/code/Magento/Catalog/Ui/Component/Listing/Columns/Price.php @@ -10,6 +10,9 @@ use Magento\Framework\View\Element\UiComponent\ContextInterface; class Price extends \Magento\Ui\Component\Listing\Columns\Column { + /** + * Column name + */ const NAME = 'price'; /** @@ -46,13 +49,14 @@ class Price extends \Magento\Ui\Component\Listing\Columns\Column */ public function prepareDataSource(array & $dataSource) { - $store = $this->storeManager->getStore( - $this->context->getFilterParam('store_id', \Magento\Store\Model\Store::DEFAULT_STORE_ID) - ); - $currencyCode = $store->getCurrentCurrencyCode(); - $currencyRate = $store->getCurrentCurrencyRate(); - $currency = $this->localeCurrency->getCurrency($currencyCode); if (isset($dataSource['data']['items'])) { + $store = $this->storeManager->getStore( + $this->context->getFilterParam('store_id', \Magento\Store\Model\Store::DEFAULT_STORE_ID) + ); + $currencyCode = $store->getCurrentCurrencyCode(); + $currencyRate = $store->getCurrentCurrencyRate(); + $currency = $this->localeCurrency->getCurrency($currencyCode); + $fieldName = $this->getData('name'); foreach ($dataSource['data']['items'] as & $item) { $item[$fieldName] = $currency->toCurrency(sprintf("%f", $item[$fieldName] * $currencyRate)); diff --git a/app/code/Magento/Catalog/Ui/Component/Listing/Columns/ProductActions.php b/app/code/Magento/Catalog/Ui/Component/Listing/Columns/ProductActions.php index f521512a78ae9a24e2420dd7cee6eaf8502110b0..0be379dabcb822a2a4a3de7439d75deba916aa94 100644 --- a/app/code/Magento/Catalog/Ui/Component/Listing/Columns/ProductActions.php +++ b/app/code/Magento/Catalog/Ui/Component/Listing/Columns/ProductActions.php @@ -46,8 +46,9 @@ class ProductActions extends Column */ public function prepareDataSource(array &$dataSource) { - $storeId = $this->context->getFilterParam('store_id'); if (isset($dataSource['data']['items'])) { + $storeId = $this->context->getFilterParam('store_id'); + foreach ($dataSource['data']['items'] as &$item) { $item[$this->getData('name')]['edit'] = [ 'href' => $this->urlBuilder->getUrl( diff --git a/app/code/Magento/Catalog/view/adminhtml/ui_component/product_listing.xml b/app/code/Magento/Catalog/view/adminhtml/ui_component/product_listing.xml index 28ad7a093b65ffa47d8d5ad370da6b304c4f0865..f4bdb0a05341facf6f1668d4f969aac86a1531a3 100644 --- a/app/code/Magento/Catalog/view/adminhtml/ui_component/product_listing.xml +++ b/app/code/Magento/Catalog/view/adminhtml/ui_component/product_listing.xml @@ -281,7 +281,7 @@ <item name="sorting" xsi:type="string">asc</item> <item name="align" xsi:type="string">left</item> <item name="label" xsi:type="string" translate="true">ID</item> - <item name="sortOrder" xsi:type="number">1</item> + <item name="sortOrder" xsi:type="number">10</item> </item> </argument> </column> @@ -299,7 +299,7 @@ <item name="sorting" xsi:type="string">asc</item> <item name="align" xsi:type="string">left</item> <item name="label" xsi:type="string" translate="true">Thumbnail</item> - <item name="sortOrder" xsi:type="number">2</item> + <item name="sortOrder" xsi:type="number">20</item> </item> </argument> </column> @@ -314,7 +314,7 @@ <item name="sorting" xsi:type="string">asc</item> <item name="align" xsi:type="string">left</item> <item name="label" xsi:type="string" translate="true">Name</item> - <item name="sortOrder" xsi:type="number">3</item> + <item name="sortOrder" xsi:type="number">30</item> </item> </argument> </column> @@ -328,7 +328,7 @@ <item name="dataType" xsi:type="string">select</item> <item name="align" xsi:type="string">left</item> <item name="label" xsi:type="string" translate="true">Type</item> - <item name="sortOrder" xsi:type="number">4</item> + <item name="sortOrder" xsi:type="number">40</item> </item> </argument> </column> @@ -342,7 +342,7 @@ <item name="dataType" xsi:type="string">select</item> <item name="align" xsi:type="string">left</item> <item name="label" xsi:type="string" translate="true">Attribute Set</item> - <item name="sortOrder" xsi:type="number">5</item> + <item name="sortOrder" xsi:type="number">50</item> </item> </argument> </column> @@ -356,7 +356,7 @@ <item name="sorting" xsi:type="string">asc</item> <item name="align" xsi:type="string">left</item> <item name="label" xsi:type="string" translate="true">SKU</item> - <item name="sortOrder" xsi:type="number">6</item> + <item name="sortOrder" xsi:type="number">60</item> </item> </argument> </column> @@ -371,7 +371,7 @@ <item name="sorting" xsi:type="string">asc</item> <item name="align" xsi:type="string">left</item> <item name="label" xsi:type="string" translate="true">Price</item> - <item name="sortOrder" xsi:type="number">7</item> + <item name="sortOrder" xsi:type="number">70</item> </item> </argument> </column> @@ -386,7 +386,7 @@ <item name="dataType" xsi:type="string">select</item> <item name="align" xsi:type="string">left</item> <item name="label" xsi:type="string" translate="true">Visibility</item> - <item name="sortOrder" xsi:type="number">8</item> + <item name="sortOrder" xsi:type="number">80</item> </item> </argument> </column> @@ -401,7 +401,7 @@ <item name="dataType" xsi:type="string">select</item> <item name="align" xsi:type="string">left</item> <item name="label" xsi:type="string" translate="true">Status</item> - <item name="sortOrder" xsi:type="number">9</item> + <item name="sortOrder" xsi:type="number">90</item> </item> </argument> </column> @@ -416,7 +416,7 @@ <item name="dataType" xsi:type="string">select</item> <item name="align" xsi:type="string">left</item> <item name="label" xsi:type="string" translate="true">Websites</item> - <item name="sortOrder" xsi:type="number">10</item> + <item name="sortOrder" xsi:type="number">100</item> </item> </argument> </column> diff --git a/app/code/Magento/CatalogInventory/view/adminhtml/ui_component/product_listing.xml b/app/code/Magento/CatalogInventory/view/adminhtml/ui_component/product_listing.xml index dc1397cf44ec9a266bac5aeb812d60f401b02934..06e3ee8ea98c229a5c87b4cdd38e4d1107fd464d 100644 --- a/app/code/Magento/CatalogInventory/view/adminhtml/ui_component/product_listing.xml +++ b/app/code/Magento/CatalogInventory/view/adminhtml/ui_component/product_listing.xml @@ -17,7 +17,6 @@ <item name="dataType" xsi:type="string">text</item> <item name="align" xsi:type="string">left</item> <item name="label" xsi:type="string" translate="true">Quantity</item> - <item name="sortOrder" xsi:type="number">8</item> </item> </argument> </column> diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/ContextInterface.php b/lib/internal/Magento/Framework/View/Element/UiComponent/ContextInterface.php index 19358482861c6fdf98e089e0e46e0953f1b765f5..290a080de6e443e7be3d37771903f818a7a3fcc8 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/ContextInterface.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/ContextInterface.php @@ -85,7 +85,7 @@ interface ContextInterface public function getRequestParam($key, $defaultValue = null); /** - * Get filters + * Get filters params * * @return array */