Well I”ve bitten the bullet and taken the step from the safety of ZenCart to the brave new world of Magento.
Boy is it complex!? The thing I love about Zen Cart is that you can hack it about to get it to do pretty much what ever you want. Magento seems just too clever for its own good…
Hopefully my attitude will change towards it – esp as I”ve agreed to do our latest ecommerce project in it!
So I”ve managed to set up some products and import some categories – but try to get list of products categorised by manufacturer? That seems a step too far for the basic Magento install, so I have been trawling through forums and blog posts on ways to achieve this. (Another plus to using Zen Cart is that because it has been around for so long the forums are teeming with solutions to most every problem)
My first starting point was to install the “Landing pages module for Magento” from yoast.com
A nice module that gives you a great little tool in the form of a CMS block that you can use on your static pages eg:
{{block type="Yoast_Filter/Result"
name="filter_result"
template="catalog/product/list.phtml"
attribute="manufacturer"
value="24" }}
This will show you all products with a manufacturer id set to 24
(I”ll show you a neat way to find out these ids later – couldn”t see it when I looked in Magentos admin panel for attributes..)
Then I found this post about how to iterate through the list of Manufacturers
http://www.magentocommerce.com/boards/viewthread/19982/
To make this appear on a static CMS page:
edit the app\code\core\Mage\Catalog\Block\Product.php
//new LJ 11/10/10
public function getAllManufacturers()
{
$product = Mage::getModel(“catalog/product”);
$attributes = Mage::getResourceModel(“eav/entity_attribute_collection”)
->setEntityTypeFilter($product->getResource()->getTypeId())
->addFieldToFilter(“attribute_code”, “manufacturer”);
$attribute = $attributes->getFirstItem()->setEntity($product->getResource());
$manufacturers = $attribute->getSource()->getAllOptions(false);
return $manufacturers;
}
This will get you an array of the manufacturer names & ids
To make the list appear on a CMS page you will need to create a new .phtml file.
I created mine at app\design\frontend\MY_THEME\default\template\catalog\brand\view_one.phtml
<ul id="manufacturer_list">
foreach ($this->
getAllManufacturers() as $manufacturer): ?>
<li>echo $manufacturer["label"] ?>li>
endforeach; ?>ul>
Then I created a page in the CMS with the following code block:
Et voila – I can see all the manufacturers in a list
But I need more – I need to be able to click on each Manf. name and it take me to a landing page giving some info about the Manf. and listing their products obviously
The Yoast module above claims to be able to dynamically generate the brand pages – however I cannot get this to work on Magento v1.4.1.1
So a more brute force method is required.
I will have to manually create CMS pages for each of my manufacturers, each page having the code snippet above to show all their products.
Not ideal – but we can use some nifty MySQL to make the initial task less daunting.
The insert statement for adding a new Manufactureur Landing page is as follows:
(the 2nd insert statement makes the page active on all stores. Note also that I want my landing pages to follow the “two_columns_right” layout which may not hold true for your site)
You can use the test CMS Except Mon best-horoscope.com afternoon, when your luck might falter. page you created above to generate these INSERT Statements for you (or generate just a list of ids & value pairs as I mentioend above)
Just edit app\design\frontend\MY_THEME\default\template\catalog\brand\view_one.phtml to say this:
<?php
//before running this find the last ID inserted into the CMS and make this one larger
$i=14;
foreach ($this->getAllManufacturers() as $manufacturer): ?>
INSERT INTO `cms_page` VALUES (<?=$i?>, “<?php echo $manufacturer[“label”] ?>”, “two_columns_right”, “”, “”, “brands/<?php echo $manufacturer[“label”] ?>”, “<?php echo $manufacturer[“label”] ?>”, “<p>Info about <?php echo $manufacturer[“label”] ?> Brand goes here…</p>\r\n<p>{{block type=”Yoast_Filter/Result” name=”filter_result” template=”catalog/product/list.phtml” attribute=”manufacturer” value=”<?php echo $manufacturer[“value”] ?>” }}</p>”, “2010-10-11 10:34:41”, “2010-10-11 10:35:06”, 1, 0, “”, “”, “”, “”, NULL, NULL);
<br />
INSERT INTO `cms_page_store` VALUES (<?=$i?>, 0);
<br />
<?php $i ;
endforeach; ?>
When you view the page you should see some nice rows of MySQL which you can copy & paste into phpAdmin (or whichever MySQL administrator you are using)
Now how to add the navigation to go to these landing pages?
You need to move (or copy) the function getAllManufacturers() from the app\code\core\Mage\Catalog\Block\Product.php code to the app\code\core\Mage\Catalog\Block\Navigation.php block
Edit the navigation file: app\design\frontend\YOURTEMPLATE\default\tempate\catalog\navigation\top.phtml
and include the following code where you want your Manufacturers drop down to be
Tada – you shoudl have a drop down navigation list similar to teh dropdown Categories list!
I can think of a few things to improve this.
1) Not having to manually create teh CMS pages woudl be nice (but the client does need to add her own descriptions for each Brand so I guess that is inevitable – if a highly manual task)
2) There is no way of hiding certaing Manufacturers if for eaxmple there are no products in stock
Any feedback/input from other Magento developers out tehre woudl be appreciated! I”ll post a link to this site when it finally goes live!
It' really superb blog with full of wonderful articles.Thanks
Magento has very good API but I want to see some more improvements of Magento pretty soon.