Magento category sorting by attributes - sorting

I am currently trying to make a special sort function for a Magento category page.
I have several attributes, which I need to use for sorting:
The first attribute is named designers. This attribute is set on a configurable product.
The next attributes are named colour and size. These are not set on the configurable product itself, but on the ”simple products”, that I combine to make the configurable product.
$attributes_designers = $this->getRequest()->getParam('designers');
$attributes_colors = $this->getRequest()->getParam('color');
$attributes_sizes = $this->getRequest()->getParam('size');
$currentCategory = Mage::getModel('catalog/layer')->getCurrentCategory();
$_productCollection = $currentCategory->getProductCollection();
if(count($attributes_designers)>0 and !in_array("ALL",$attributes_designers)) {
$_productCollection->addAttributeToFilter('designer',$attributes_designers);
}
if(count($attributes_colors)>0 and !in_array("ALL",$attributes_colors)) {
$_productCollection->addAttributeToFilter('color',$attributes_colors);
}
if(count($attributes_sizes)>0 and !in_array("ALL",$attributes_sizes)) {
$_productCollection->addAttributeToFilter('size',$attributes_sizes);
}
if(isset($_GET['order'])) $_productCollection->setOrder($this->getRequest()->getParam('order'), $this->getRequest()->getParam('dir'));
$_productCollection->load();
Unfortunately I’m unable to get the attribute colour and size working, since they are not set on the configurable product, but it’s children.
Does anyone have an idea how to get this working?
Thanks in advance

Two things:
I assume you know this, but just to make sure: You can easily make any of your attributes sortable by editing the attribute in Catalog >> Attributes >> Manage Attributes, editing one and the bottom option is called "Used for Sorting in Product Listing" - which you should set to "Yes".
As you have found out, Magento isn't going to want to sort a configurable product by any values in the simple products that have been associated to it. This actually makes plenty of sense. If you are trying to sort by color, and you have a configurable product with 2 simple products, one of which has the color of "Apple Red" and the other with "Zealot Black", then how would it sort that? It simply cannot make logical sense to do what you are hoping. It only sorts based on attributes assigned to the configurable product.

Related

How to add custom attributes to a specific category in Magento

I need to add some custom attributes to a category in Magento. I only want to use for a special category, not all.
Thanks
Do you mean that you want products in category A have a set of attributes while products in category B have another set of attributes?
If so, you should create a new attribute set in Catalog->Attributes->Manage Attribute Sets, and add all attributes you need for the specific category. And when you create products for this category, just choose the new attribute set.
Well if it is not what you mean, please give more detailed explanation.
Hope it helps

Magento : On the category page how do I display a product for all the colour options in a configurable

I have a configurable product with two configurable attributes size and colour, I would like to display on the category page one product for each colour in the configurable. These colours need to be displayed when available in different sizes.
When the customer opens the page they should see all the colours that all the products are available in, then if they filter by size they should see all the colours of all the products that are in that size.
There are two issues with this problem. 1. Displaying the appropriate products and colours and 2. Setting the Layered Navigation so that it displays all the correct options.
I have tried just displaying simple products for each colour and linking them to their parent configurable but then the Layered Navigation is all wrong. I have also tried making a configurable product visible in the backend so that it is added to the product collection and used in the filters then just hiding it on the category page, this kind of works but the Layered Navigation counts all the simple products as well. Another problem is that if I try and use simple products and pick one of each colour then these also have a specific size so that if a user changes sizes in the filter these won't be shown.
Does anyone know a way to do this?
In your list.phtml (or any new template you'd like to create) (edit: or better : in a Block) try this :
$colors = array();
if ($_product->isConfigurable()) {
$allProducts = $_product->getTypeInstance(true)->getUsedProducts(null, $_product);
foreach ($allProducts as $subproduct) {
if ($subproduct->isSaleable()) {
$colors[$subproduct->getColor()] = $subproduct->getAttributeText('Color');
}
}
}
and iterate over $colors to construct your custom HTML list of colors

Adding a custom attribute selector to a Magento product with text values, not dropdown

Magento offers Configurable Products so that it lets buyer selects attributes for a given product, like Size for Shirt, or Color for a Phone.
Problem is, you must add each possible single combination as a simple product, and that Configurable Product works merely as a container. This is impractical for attributes with too many values, and unexpected values.
For example it does not allow text values. What if a buyer wants to print his name on a Shirt?
What if I wanted to add a selectable attribute of tens of values? It doesn't have to be a added through the admin area, hardcoded solutions are OK.
Something like Cart Item Annotation is there?
Configurable products should not be used for products that doesn't have a physical definition, for instance Drawing and Designs. Instead it's better to use Custom Options instead for these cases, where you don't care about inventory of products nor attribute based statistics. This could be done through the Custom Options tab at Manage Product screen. Surely this eliminates the need for configurable products for a variety of cases.

is it possible to show custom attributes of associated products under a grouped product in front end? (Magento)

I have a typical condition in my magento Grouped product.
Is it possible to show Custom attribute (color dropdown) of associated product under Grouped products in the fronted.. as shown below
Consider the sample blanket product
Let me know if i am not clear.
Thanks
It's not clear your question but I would give you a small example to get text field, multiple select or drop-down listbox value.
First, we should load the product collection :
<?php
// load the product that id 125, then show attributes of the product
$product = Mage::getModel('catalog/product')->load($this->getProduct()->getId(125));
echo $product->getCustomAttribute();
// lets say your custom attributes name is "size" and type is text field
echo $product->getSize();
// lets assume your custom attributes name is "product_size then
echo $product->getProductSize();
// lets assume your attribute type is drop-down, this will get array of attribute options instead of value that you selected
echo $product->getAttributeText(product_size);
// to get drop-down value that you selected
$attribute = $product->getAttributes();
$productSize = $attribute['product_size']->getFrontend()->getValue($product);
let me know if it's not meet your request.
I have found a solution for this, 3 edited files.
But these files are edited for a previous version of Magento, I don't know which version.
I have uploaded this 3 files on my Magento 1.7 and it works but when add the product to the cart it give's a error with app/code/core/Mage/Sales/Model/Quote.php
This file: Quote.php is one of the edited files, when i upload the original Quote.php it works.
Look at this pic: http://s8.postimage.org/g8bvbth0z/Naamloos.png
But maybe i get more errors in the future, i don't have any ideas..
I am a noob with this, if someone can look at the edited files and chek how they have do this and compare this with the newest files for Magento 1.7 maybe we can help to many peoples with this problem.

Magento grouped product options

I want to show a set of products as a table inside one product with these attributes.
Dimensions Width x Gusset x Height Code Price/Case Bags/Case Weight
So i chosen grouped product option but it does not match the requirement. How can i design a table like format from the grouped product option with radio button to choose only one product from it. So using grouped product or configurable product or by any way how can i achieve this.
Here am attaching the screen-shot which i actually wanted
I can think of two ways to represent this in code. If the dimensions tend to be from a limited set of choices, you could use a configurable product to represent this choice, simply displaying all possible sub-products in the table. This would let you reuse the existing catalog product page with a little retrofitting.
If they do not fit well, you could place the items in a category hidden from the public categories and loop through each of the products in the category to display the table. This would require more work to tie back to putting into the cart, etc.
Importantly, it looks like each of your options has an entirely uncorrelated price, so it seems to me that you need to have a simple product underpinning these options at some point. (I'm sure you could get more clever, I'm just not sure that's a good idea.)
You can easily solve this with a plugin for Magento. There is a plugin here which will do exactly what you want. It will display product options in a grid: http://www.magemechanics.com/product-grid-options.html

Resources