0

I am trying to figure out how to implement this feature, and I am looking for ideas. This is not specifically a programming question, though. Here are the specs:

  1. The project is a T Shirt store for companies. Employees from various companies can come and order T-Shirts for their company.
  2. We have just 4 designs. I am planning to set these up as 4 configurable SKUs, each with two attributes - gender (man, woman) and size (S,M,L, XL etc). When you choose a T Shirt for a particular company, we just emboss the logo on the T Shirt. We also offer an option of not having the logo embossed on the T Shirt.
  3. I am planning to set a category for each company, and show the 4 configurable products on each of category(company) page.

If I follow the above scenario, my order details will have the purchased products with all the correct attributes, except for the category - so I end up without knowing which company the product was ordered for.

Another worry is that if we keep adding companies, the number of categories may get unwieldy...

Any ideas on how to tackle this will be welcome! Thanks!

2 Answers 2

1

Another way to do this task, you should track product category and set additional options for its category while adding to cart, using event/observers. See my solution:

1. Every "add to cart form" or "add to cart button" you should add category param to url:
/app/design/frontend/base/default/template/catalog/product/view.phtml:

<form action="<?php echo $this->getSubmitUrl($_product,array('category'=>$_product->getCategory()->getId())) ?>"
method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>

/app/design/frontend/base/default/template/catalog/product/list.phtml:

<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" 
onclick="setLocation('<?php echo $this->getAddToCartUrl($_product,array('category'=>$_product->getCategory()->getId())) ?>')">
    <span><span><?php echo $this->__('Add to Cart') ?></span></span>
</button>

2.Add these observers to your config.xml:

<frontend>
      <events>
            <sales_quote_add_item>
                <observers>
                    <your_module>
                        <method>salesQuoteAddItem</method>
                        <class>Your_Module_Model_Observer</class>
                    </your_module>
                </observers>
            </sales_quote_add_item>
            <sales_convert_quote_item_to_order_item>
                <observers>
                    <your_module>
                        <method>salesConvertQuoteItemToOrderItem</method>
                        <class>Your_Module_Model_Observer</class>
                    </your_module>
                </observers>
            </sales_convert_quote_item_to_order_item>
      <events>
      <!-- other nodes -->
<frontend>

3.And your Observer.php:

class Your_Module_Model_Observer
{
    public function salesQuoteAddItem($observer)
    {
        /**
         * here we save category id and name to quote item option as 'additional_options'
         * @var $item Mage_Sales_Model_Quote_Item
         */
        $item = $observer->getEvent()->getQuoteItem();
        if ($categoryId = Mage::app()->getRequest()->getParam('category')) {
            $name           = Mage::getModel('catalog/category')->load($categoryId)->getName();
            $option         = $item->getOptionByCode('additional_options');
            $categoryOption = array(
                'label'                    => 'Category',
                'option_value'             => $categoryId,
                'value'                    => $name,
                'print_value'              => $name,
            );
            if ($option == null) {
                $value = array('category'=> $categoryOption);
                $value = serialize($value);
                $item->addOption(array('code'=> 'additional_options', 'product_id'=> $item->getProductId(), 'value'=> $value));
            } else {
                $additional             = unserialize($option->getValue());
                $additional['category'] = $categoryOption;
                $option->setValue(serialize($additional));
            }
        }
    }

    public function salesConvertQuoteItemToOrderItem($observer)
    {
        /**
         * here we convert previous saved category option to order item option
         * @var $quoteItem Mage_Sales_Model_Quote_Item
         */
        $orderItem    = $observer->getEvent()->getOrderItem();
        $quoteItem    = $observer->getEvent()->getItem();
        $orderOptions = $orderItem->getProductOptions();
        if ($additional = $quoteItem->getOptionByCode('additional_options')) {
            $additional = unserialize($additional->getValue());
            if (isset($orderOptions['attributes_info'])) {
                $orderOptions['attributes_info'][] = $additional['category'];
            } else {
                $orderOptions['attributes_info'] = array($additional['category']);
            }
            $orderItem->setProductOptions($orderOptions);
        }

    }  
}

Here is my final result: enter image description here

4
  • Fantastic. Thank you for your time and patience. This should work. I am wondering if this would also work:
    – GKRP
    Commented Oct 13, 2013 at 5:39
  • Don't forgot to accept or upvote if it works.
    – mageUz
    Commented Oct 14, 2013 at 0:11
  • Tested this out, and it works! Thank you. However, this solution would cause the number of categories to proliferate wildly. So instead of using the category, and saving it as an additional_option, I am thinking of using a select box containing the names of the companies, and use ajax to set the the option_value. That would work too, right?
    – GKRP
    Commented Oct 15, 2013 at 11:32
  • Yes, it is also make sense
    – mageUz
    Commented Oct 15, 2013 at 13:15
0

You can use company as one configurable option. And you configurable product will be have company, gender and size options. This prevent you to add many companies as a category and attach its products. And in your order details it will be showed properly.

1
  • Thanks. Yes, while this solves the problem of not creating too many categories, it would also mean creating the same configurable products over and over again for each company, although the products are exactly the same. Is there
    – GKRP
    Commented Oct 10, 2013 at 9:44

Your Answer

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

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