cancel
Showing results for 
Search instead for 
Did you mean: 

How change order of attributs on product page?

SOLVED

Re: How change order of attributs on product page?

Hi again, yes it's my old post, but it took me so long to find out this simple solution, I just couldn't see it, grrrr. So, when you create configurabe item, well actually his product configurations, you can click and pull the entire box containing the attribute values up or down mith the mous, and define the sort order of them. So if you want to have attribute Size appearing before Color, you just pull it higher.

 

Meanwhile, I've tried also customizing the code, I've found info somewhere on Google and it involved changing the code in file vendor/magento/module-configurable-product/Model/ResourceModel/Product/Type/Configurable.php, the modification is marked with "custom_file_entry" tags. This worked for me, but is not a proper solution, because you'll lose this on magento update. So the way to go, would be to create a module for this. But to be honest, an entire module just for this sorting fix...no I'll stick the mouse pulling for now Smiley Wink

 

 

 public function getAttributeOptions($superAttribute, $productId)
    {
        $scope  = $this->getScopeResolver()->getScope();
        $select = $this->getConnection()->select()->from(
            ['super_attribute' => $this->getTable('catalog_product_super_attribute')],
            [
                'sku' => 'entity.sku',
                'product_id' => 'super_attribute.product_id',
                'attribute_code' => 'attribute.attribute_code',
                'value_index' => 'entity_value.value',
                'option_title' => $this->getConnection()->getIfNullSql(
                    'option_value.value',
                    'default_option_value.value'
                ),
                'default_title' => 'default_option_value.value',
            ]
        )->joinInner(
            ['product_link' => $this->getTable('catalog_product_super_link')],
            'product_link.parent_id = super_attribute.product_id',
            []
        )->joinInner(
            ['attribute' => $this->getTable('eav_attribute')],
            'attribute.attribute_id = super_attribute.attribute_id',
            []
        )->joinInner(
            ['entity' => $this->getTable('catalog_product_entity')],
            'entity.entity_id = product_link.product_id',
            []
        )->joinInner(
            ['entity_value' => $superAttribute->getBackendTable()],
            implode(
                ' AND ',
                [
                    'entity_value.attribute_id = super_attribute.attribute_id',
                    'entity_value.store_id = 0',
                    'entity_value.entity_id = product_link.product_id',
                ]
            ),
            []
        )->joinLeft(
            ['option_value' => $this->getTable('eav_attribute_option_value')],
            implode(
                ' AND ',
                [
                    'option_value.option_id = entity_value.value',
                    'option_value.store_id = ' . $scope->getId()
                ]
            ),			
            []
        )->joinLeft(
            ['default_option_value' => $this->getTable('eav_attribute_option_value')],
            implode(
                ' AND ',
                [
                    'default_option_value.option_id = entity_value.value',
                    'default_option_value.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID
                ]
            ),
            []
        )->where(
            'super_attribute.product_id = ?',
            $productId
        )->where(
            'attribute.attribute_id = ?',
            $superAttribute->getAttributeId()

		//>custom_file_entry  
		// solution taken from: http://magento.stackexchange.com/questions/141899/configurable-product-attribute-sort-order-in-dropdown-2-12      
		//);
		)->joinInner(
		    ['attribute_opt' => $this->getTable('eav_attribute_option')],
		    'attribute_opt.option_id = entity_value.value',
		    []
		)->order(
		    'attribute_opt.sort_order ASC'
		);
		//<custom_file_entry


        return $this->getConnection()->fetchAll($select);
    }

    /**
     * @return ScopeResolverInterface
     * @deprecated
     */
    private function getScopeResolver()
    {
        if (!($this->scopeResolver instanceof ScopeResolverInterface)) {
            $this->scopeResolver = ObjectManager::getInstance()->get(ScopeResolverInterface::class);
        }
        return $this->scopeResolver;
    }

 

Re: How change order of attributs on product page?

Forgot to say, answer of Damian is correct, I just couldn't see it, even if was staring right into it, thanks again.