Magento - category products by attribute - magento

When I create categories in Magento, I currently add all the products manually.
Problem is that we are getting more and more products and that some of our products change quite often.
So is it possible to dynamically change the category products depending on the product attributes?
i.e. to create categories that each contain all the products with a specific attribute value.
For example the category "blue", dynamically containing all the products where the attribute "color" is set to "blue".
Thanks.

$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('color', 'blue');
$_category = Mage::getModel('catalog/category')->loadByAttribute('name', 'blue');
foreach ($collection as $_item){
$_item->setCategoryIds(array($_category->getId()));
$_item->save();
}
Its just a stupid dummy you may need another foreach loop for all colors....but it shows what needs to be done...

Why are you doing data entry Manually?.
Magento has an inbuilt stable product import export system.Did you try this?
If this import export system does not solve your purpose then you will have to write a script and run it via cron once every day.

See www.proxiblue.com.au, there is a module that does exactly this.
Products can Be Assigned to categories, using any attribute combination.
Disclaimer: this is my site and module.

Related

Magento category and attributes

In Magento Community Ed., my structure of products is such that there are a set of 100 attributes that some products are assigned to and some are not. These attributes values are common to all products. So if Product A has attribute X with value 360, if Product B has that attribute, its value will also be 360. Now these attribute values would need to be updated every hour or so. Is there a way that I can update these at the back end in one csv/excel file and the changes apply to all products that have subscribed to this attribute?
Also, is there a way to create attributes for categories ?
Yes, you can create and use your own import in Magento. You find the module using System Menu ~ Import/Export ~ Import.
Oh, and refer to this question for Attributes on a Category
Good luck!

Filter one specific attribute values from products in magento

I'm new in magento, I'm working on http://www.theartworkgallery24.com/stage/ website. Please check beneath flash banner, there are 4 big images that are links to attributes value from which user can directly go to a product.
I need a page that display on one specific attribute values like in case of artist, it should be Gustav Klimt, Leonardo Da Vinci etc. These should be links to actual product related to the attribute values.
Please tell me how to make your own PHTML or PHP file, which code to use and how, and in last how to call your code in your magento website.
Any ideas will be appreciated, thanks.
You please create an attribute (davinchi) in admin side for these functionality. You can create products attributes from catalog->attributes->menu.After that you can see these attribute value in product creation page.You just assign it to different products
After that you can either create a module for this. Otherwise just create a phtml file in catalog/product/ folder.
then enter the below custom collection code in it.
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('*');
//filter codition
$collection->addFieldToFilter(array(
array('attribute'=>'davinchi','eq'=>1),
));
This will load products having attribute value davinchi=1.

How Do I Show All Products From All Categories Which Have a Certain Attribute = a Certain Value?

So basically my Magento store sells t-shirts (not really) in a bunch of different categories. All t-shirts, regardless of category, have the color attribute = to either red, blue, green, etc.
I want to be able to link to a page for blue products, or red products, etc, and show them all regardless of parent category.
Thoughts? Thanks. I'm really not trying to add them all to another category manually.
Give the Yoast's Landing Pages extension a try. As explained in their blog, you'll be able to create CMS pages that contains products listings filtered by any attribute you have created.
For example, to list all black products, you'd use something like (here the value "black" has id of 24):
{{block type="Yoast_Filter/Result"
name="filter_result"
template="catalog/product/list.phtml"
attribute_name="color"
value="24" }}
And as it is a CMS page, you'll also can customize the url to have something like: http:/www.yourdomain.com/all-black-products.html.
The description in magentoconnect says it's only compatible with 1.4, but I'm using with a 1.5, I can't remember if I had to change the code or not though.
HTH
link them all to specific category and use navigation filters
You can filter products by attribute value.. simply by using addAttributeToFilter
$attributeValue = 'red';
$attributeCode = 'color';
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToFilter($attributeCode, $attributeValue);
Hope this helps. Thanks.

How to change the product display order in magento

How can I change the product display order in the front end (grid or list) by setting some preferences from back-end? I guess it should be other than best value and name from the default Magento display order property.
I tried by creating a new attribute called display_order, and each product holds a value based on its value the product needs to shown in front end. However, it is not working. Please help me fix this.
You'll need to extend the Mage_Catalog_Block_Product_List block to provide your own functionality for the getProductCollection() method. Probably something along the lines of:
class ... extends Mage_Catalog_Block_Product_List {
function getProductCollection() {
parent::getProductCollection()->addAttributeToSort('display_order', 'ASC')
}
}
Then, of course, you'll have to update you layout xml file on your, presumably, custom controller (unless you want all of the product listing screens to act like this) to use your new block instead of the Magento default of catalog/product_list.
Why don't you use the Magento sorting thing ?
In your category, under Category Product you have the possibility to choose the sorting order in the last column. To do it through php, just make a custom script that you'll need to launch once.
$collection = 'Your product collection';
$result = array();
foreach ($collection as $product) {
$sort = 'Your way of calculating the desired sorting';
$result[$product->getId()]=$sort;
}
Mage::getModel('catalog/category')->load('your category id')->setPostedProducts($result)->save();
And that's it :)
To change the display order , first you need to set the default sort by option to position.This can be done from the magento admin configuration.After that you need to set position for all the products starting with the value 1.
I come across the following module which will make this task very easy, just by drag and drop the products from the manage categories itself.Please check the following extension
http://www.blackqubers.com/extensions/product-sorting-drag-and-drop.html
Hope this will helps you

Magento - Programmatically added products don't show up

I am trying to import products using a custom made import profile. Here I set some values on the product and then save it, like this:
$product = Mage::getModel('catalog/product');
$data = array();
// Inbetween I fill $data with some values
$product->addData($data);
$product->save();
However, the products do show up in the admin, but do not show up on the frontend (I did add them to categories).
The odd thing is, they do appear on the frontend once I open them in the admin and save them again (without modifying anything). Am I forgetting something, or some value that is somehow set by that action?
I tried to rebuild all indices in the backend and to clear the cache, but this does not work, contrary to Magento API: Rebuild Indexes after adding new products.
I had the same problem and solved it by adding the Website ID to the product:
$newProduct ->setWebsiteIds(array(1))
Keep in mind that the parameter is an array, so you can add multiple website td's
Some guesses, since this comes up from time to time. See also here.

Resources