0

I want to sort products by manufacturer, but also allow store manager to override this easily.

My first idea was to use category-product position and set it while creating product programmatically, but I couldn't find any appropriate method (it used to be possible in 1.9 with assignProduct - Set Category Product Position of Products ).

My new idea is to use SQL to update all products with position 0 based on manufacturer name. Manufacturer name can be found in eav_attribute_option_value and position is in catalog_category_product_index, but how can I join them?

Thank you in advance for any hints on either approach to the task

1 Answer 1

1

I have found another solution, that is a little bit hacky, but acceptable in my case. I have added new product attribute called "positioner" with default value 500 and "Used for Sorting in Product Listing" set to yes. While creating new products I override the default:

if(in_array($manufacturer,['Special manufacturer 1','Special manufacturer 2']) && is_null($product->getData('positioner'))){
    $product->addData(array('positioner' => '100'));
}

If shop manager wants to change order he simply has to change position attribute of a product. PS: to sort by new attribute by default you have to select correct attribute in

configuration -> catalog -> catalog -> storefront -> Product Listing Sort by

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.