magento

Baobaz at Meet Magento Poland

For the first time Magento community in Poland has the opportunity to meet and share their experiences with the most dynamically evolving e-commerce solution in the world on the Meet Magento Poland conference at Warsow on 23-24 of November (agenda).

Meet Magento Polska

Baobaz has joined this event as one of the partners. You will also find us among the speakers. Authors of the presentation titled "Works for me - about code repositories and automatic deployment in Magento projects" are Magento Certified Developers - Maciej Krasuski and Kamil Węgrzynowicz.

We encourage everybody to join the event and meet us there!

Magento 1.5 new features

After Magento Enterprise Edition 1.9 release, a new Magento Community Edition release just came out: 1.5 alpha.

This 1.5 version includes 3 new features that may be very useful for your Magento website:

  1. A new customers import/export module

    You may now export your customers and product from Magento backend with an advanced attribute filter feature.
    The good old dataflow profile feature is still available.
    Magento 1.5 product export
    Magento 1.5 customer export

  2. Order State and Status can be modified from Magento backend

    Now you don't have to edit XML files to modify order state and status as this can be done from the backend.
    Magento 1.5 order status
    Magento 1.5 order status edit

  3. Modify order adresses after an order has been made

    This will be very useful to customer services: you may now edit an address without having to create another order.
    Be careful though: this will not recalculate order amount nor shipping fees.
    Magento 1.5 order edit
    Magento 1.5 order address edit

More information on Magento 1.5 on Magento official website

Https + Magento Cache + Internet Explorer = No image

Magento uses by default an advanced cache system in order to display templates content faster. But default configuration of this cache can sometime creates some issues.

Recently, we had some images that were not displayed in the top menu when we switch from an http page to a https page using Internet Explorer browser. Images in this menu still have a non secured (http) URI. Internet Explorer is not pleased with such content. By default, this browser does not display unsecured content on a secured page. We have this security warning displayed when some image have http URI on a https page:

Internet Explorer Security Warning

Block displaying top menu was using cache system but this cache was not regenerated when we switch from a http to a https page. That's why images were still having http URI.

For fixing this problem, we must rewrite getCacheKey method from Mage_Catalog_Block_Navigation class. A new parameter telling if page use http or https should be included in cache key. Cache will then be different for this 2 types of pages. This parameter is added with getSkinUrl method

Default code of getCacheKey

public function getCacheKey()
{
    return 'CATALOG_NAVIGATION_' . Mage::app()->getStore()->getId()
        . '_' . Mage::getDesign()->getPackageName()
        . '_' . Mage::getDesign()->getTheme('template')
        . '_' . Mage::getSingleton('customer/session')->getCustomerGroupId()
        . '_' . md5($this->getTemplate() . $this->getCurrenCategoryKey());
}

is then replaced by following code

public function getCacheKey()
{
    return 'CATALOG_NAVIGATION_' . Mage::app()->getStore()->getId()
        . '_' . Mage::getDesign()->getPackageName()
        . '_' . Mage::getDesign()->getTheme('template')
        . '_' . Mage::getSingleton('customer/session')->getCustomerGroupId()
        . '_' . md5($this->getTemplate() . $this->getCurrenCategoryKey())
        . '_' . md5($this->getSkinUrl()); /*** FIX IN THIS LINE ***/
}

This is it. You can now use peacefully https on Internet Explorer.

For more details about Magento cache system you can read this article.

Bag-story launched !

Bag-story launched !

We're excited to announce the launch of a new webshop created by the Baobaz team ! Bag-story is a website offering a wide variety of bags, pouches and wallets. It's built using the Magento Enterprise Edition.

For more details, check out the site: www.bag-story.fr. Enjoy your shopping !

Bestsellers list vs flat product catalog in Magento

Magento uses the EAV database model by default, but it's also possible to use a flat product catalog in your shop. Enabling this option can result in improved performance, but it also may cause some of the sites to display unproperly. A best selling products list could be an example of that.

A best-seller list can be built using collections:

$collection = Mage::getResourceModel('reports/product_collection');

$collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());

$collection = $this->_addProductAttributesAndPrices($collection)
    ->addOrderedQty()
    ->addStoreFilter()
    ->setOrder('ordered_qty', 'desc')
    ->setPageSize(5)
    ->setCurPage(1);

$this->setProductCollection($collection);

This way we create a collection of products ordered by the quantity of orders. However - when diplaying the collection in the template you may find that some of the data (product name, image) was not properly fetched and are not displayed. This is a result of the addOrderedQty method performing a wrong query. Here's the solution.

The addOrderedQty method is a part of the Mage/Reports module - you can find it in Magento's app/code/core/Mage/Reports/Model/Mysql4/Product/Collection.php. The interesting part lies at the very bottom of this function:

$this->getSelect()
    ->joinInner(
        array('e' => $this->getProductEntityTableName()),
        "e.entity_id = order_items.{$productIdFieldName} AND e.entity_type_id = {$this->getProductEntityTypeId()}{$productTypes}"
    )
    ->group('e.entity_id')
    ->having('ordered_qty > 0');

To resolve the problem with the flat catalog, simply rewrite the model and modify this function by replacing the last part with:

if ($this->isEnabledFlat()) {
    $this->getSelect()->joinInner(
        array('e' => $this->getResource()->getFlatTableName()),
        "e.entity_id = order_items.{$productIdFieldName}{$productTypes}"
    );
}
else {
    $this->getSelect()
        ->joinInner(
            array('e' => $this->getProductEntityTableName()),
            "e.entity_id = order_items.{$productIdFieldName} AND e.entity_type_id = {$this->getProductEntityTypeId()}{$productTypes}"
        );
}

$this->getSelect()
    ->group('e.entity_id')
    ->having('ordered_qty > 0');

That should fix the problem.

Increase your sales! - Promotions rules in your Magento

Magento system, offers users an excellent tool for creating rules of special prices for multiply products at the same time. We have 2 types of rules: the first refers to a catalog of products, while the other to the contents of customers shopping cart. Let's look little bit closer at this first one.

In this example, we'll create a rule of reducing 50% of the price of each product in a specific category in our catalog.

Go to Promotions -> Catalog Price Rules -> Add New Rule

At the beginning we give the name of the rule, then we mark stores to take effect in (obviously, if we have more than 1) and select group of clients. Remember to include the start date and end date of promotion period, You can also enter a From/To Time to be more specific.

On the Conditions Tab, set a condition to define the category of products: if the product is equal category id 44 (Sacs enfants) then...

..then perform the action: apply a percentage discount of the original price by 50 (50%).
Accept a new rule by click on "Save & Apply"

From now on, prices of all products from category 'Sacs enfants' ( category_id = 44) will be reduced by 50%. Products will display the original price (crossed out) and promotion one (as a rule).

Please note, prices usually refer to the standard price of the product. So if the product is set to individual special price it will be superior, depending on how we set the condition in price rule.

Enjoy your sales!:)

Magento dropdown attributes

Let's say you want to create a new attribute for a product, e.g. 'color'.
There should be a set of possible values for this attribute. So what you do is create
an attribute of 'Dropdown' type. You set all its properties, give it a title and create its options, e.g. 'black', 'white', 'red' and 'yellow'.
But there is still one surprise that you may have. When you try to obtain the color simply by:

$product->getColor()

all you get is a numeric value corresponding to an option value in the dropdown.
But you probably would like to get a color name.
Fortunately you don't need to construct database queries, as Magento already thought about it.
So to get the name of the color selected for a product you need to use a method:
$product->getAttributeText('color');

where 'color' is the text that you have set as attribute code. Remember that you cannot
change attribute code nor its type after you create it.

Setting-up Ruled-Based Product Relations for automatic cross-sell with Magento Enterprise Edition 1.7

Managing cross-sell relations can take a long time with Magento Community Edition if you have many products in you catalog.

Product Relations with Magento Community Edition

With Magento Community Edition, you used to have to create relations between each product (cross-sell, up-sell and related products), product after product. Making this automatic required to develop a specific module or to import links from another system.

Setting-up Ruled-Based Product Relations for automatic cross-sell with Magento Enterprise Edition 1.7

Today Magento Enterprise Edition 1.7 allows you to create Ruled-Based Product Relations for automatic cross-sell links between your products.

Setting-up Ruled-Based Product Relations for automatic cross-sell with Magento Enterprise Edition 1.7

You can create several rules, define a priority so that you know which rule will be used if several ones apply.

Rules can be permanant or apply from a specific date to another.

These rules handle the 3 basic relations: cross-sell, up-sell and related products.

Setting-up Ruled-Based Product Relations for automatic cross-sell with Magento Enterprise Edition 1.7

Next you define if the rule applies to every products or just to some of them. What you can see here is the standard Magento attribute filter Rule engine.

Setting-up Ruled-Based Product Relations for automatic cross-sell with Magento Enterprise Edition 1.7

Then you define which product will be displayed. This Rule engine is slightly different since it allows to select an attribute value that will be equal to the main product.

At last you just have to save the rule so that it is applied and that linked products are displayed on the right blocks (cross-sell, up-sell and related products).

Bargento 4 announced

Bargento

Bargento 4 was announced. The event will take place Monday 22nd March Friday 28th March 2010 at Paris.

Program and Bargento place will be revealed soon.

Official announce in bargento.fr site (in french)

Magento: reload color images for configurable product

Let's talk about one situation. We are in shop made in Magento.

We are on configurable product page. One of configurable attributes is color. Wouldn't it be good idea, after color is chosen show only images of this color? It can be... and it's not hard to achieve.

First we must do some preparations:

Create attribute "image_storing" type boolean and add it to your attribute sets. Can be limited only to simple products.

For each color of superproduct (configurable+simples) choose one simple product and set value to yes, also to this product upload images of this color.

Now create new module called "imageswitch" (or whatever you want, just remember to change it in the following code).

In it you must have a controller looking like this:

class Baobaz_Imageswitch_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        $prod_id  = (int) $this->getRequest()->getParam('prod_id');
        $color_value  = (int) $this->getRequest()->getParam('color_id');
        $product=Mage::getModel('catalog/product')->load($prod_id);
        if($color_value) {
            $allProducts = $product->getTypeInstance(true)->getUsedProducts(null, $product);      
            foreach ($allProducts as $prod) {
                if ($prod->getData('image_storing') && $prod->getColor()==$color_value) { // && $prod->isSaleable()
                    break;
                }
            }          
            $prod_full=Mage::getModel('catalog/product')->load($prod->getId());
            Mage::register('product', $prod_full);
        }
        else {
            Mage::register('product', $product);
        }
        $this->loadLayout();    
        $this->renderLayout();
    }
}

This controller will reload the whole media block, but for that we also need proper layout xml file

imageswitch.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <imageswitch_index_index>
        <reference name="root">
            <action method="setTemplate"><template>page/empty.phtml</template></action>
        </reference>
        <reference name="content">
            <block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml" />
        </reference>
    </imageswitch_index_index>
</layout>

and a layout html file - page/empty.phtml

<!-- start content -->
    <?php echo $this->getChildHtml('content') ?>
<!-- end content -->

Then we need to add some observer to catalog/product/view.phtml so we can reload it when the value of color is changed (attribute76 is the id of select for attribute color, it's default id if we use standard Magento attribute, if changed, may need adjusting)

<script>
function runajax() {
    product_id=$('product_id').value
    color_id=$('attribute76').value;
   
    new Ajax.Updater('product_media_content', '<?php echo Mage::getBaseUrl(); ?>imageswitch/index/index/prod_id/'+product_id+'/color_id/'+color_id, { method: 'get', evalScripts: true });
}

if ($('attribute76')) {
    Event.observe('attribute76', 'change', runajax);  
}
</script>

and add in the same file id of block to be added by changing :

<div class="product-img-box">
    <?php echo $this->getChildHtml('media') ?>
</div>

<div class="product-img-box" id="product_media_content">
    <?php echo $this->getChildHtml('media') ?>
</div>

and if all is done properly, now you should be able to see the effect. enjoy!