2

I've never been a fan of the naming format that the "quick simple product creation" offers you and wondered if there is a native way to tweak it without delving into the code? For example if the configurable product name is

QWERT and I create a simple product with the configurable options of Blue and XL it creates the name as

QWERT-Blue-XL

A preferred naming format would be Qwert (Blue/XL)

I know you can uncheck the name option and adjust to what you need but I'm looking for it to automatically stick to the format that I require.

1

2 Answers 2

3

Magento it makes in controller Mage_Adminhtml_Catalog_ProductController

public function quickCreateAction() {

...

if ($product->getSkuAutogenerate()) {
    $product->setSku($configurableProduct->getSku() . '-' . implode('-', $autogenerateOptions));
}

You can rewrite controller or you can do it with event/observer

<adminhtml>
    <events>
        <save_model_before>
            <observers>
                <before_save_sku>
                    <model>module/observer</model>
                    <method>updateSku</method>
                </before_save_sku>
            </observers>
        </save_model_before>
    </events>
</adminhtml>

Observer method code:

if (Mage::app()->getRequest()->getActionName() == 'quickCreate') {
    //generate sku as you like and make ->setData('sku', $yourSku)
}
0

A clean way to do this, is creating an observer for controller_action_predispatch_adminhtml_catalog_product_quickCreate and fill in the name automatically based on your logic, if the "autogenerate" checkbox is checked.

This goes into your config.xml:

<adminhtml>
    <events>
        <controller_action_predispatch_adminhtml_catalog_product_quickCreate>
            <observers>
                <quick_create_name>
                    <type>singleton</type>
                    <class>quick_create_name/observer</class>
                    <method>setQuickcreateName</method>
                </quick_create_name>
            </observers>
        </controller_action_predispatch_adminhtml_catalog_product_quickCreate>
    </events>
</adminhtml>

And this is an example for your Observer.php

class SE_QuickCreate_Model_Observer
{
    public function setQuickcreateName(Varien_Event_Observer $observer)
    {
        $request = $observer->getControllerAction()->getRequest();
        $simpleProductRequest = $request->getParam('simple_product');
        if (!empty($simpleProductRequest['name_autogenerate'])) {


            $simpleProductRequest['name_autogenerate'] = false;
            $simpleProductRequest['name'] = 'YOUR LOGIC HERE';


        }
        $request->setParam('simple_product', $simpleProductRequest);
    }
}

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.