Magento – Add/Edit Product – Append selected attribute value to product title

productproduct-attributeproduct-edit

I would like to Add selected attribute values to product title while adding/editing a product in admin.

eg. Product Name entered: Laptop

Attributes Selected
1) Brand – Toshiba
2) Colour- White
3) other attribute value

When a product added/edited from admin, the above selected attribute value concatenate to the title and then save in database.

Final Output: Product Name: Toshiba Laptop White (attribute sequence doesn't matter)

While writing this question: other issue, while editing product the attribute values saved in database will be shown in product name field. So while submitting the revised item, ideally it should check if product name contains attribute value if so ignore attribute values.

Basically, I want product name based on selected attributes values of a certain product.

By this, custom attributes are not required to manually add on places like catalog list/view, cart, invoices, pdf, email, customer account, breadcrumb, and other relative places.

[The other solution would be manually echo of attribute values on required locations (invoices, pdf, email, catalog and so on) which means editing lots of files which in opinion would be cumbersome!]

I am open to paid extension/work or customise code which could resolve this issue.

Please anyone who could help ?

Thank you

Best Answer

I have Create An Module For This Purpose. It May be help full for you.

 app\etc\modules\Designo_Productname.xml

<?xml version="1.0"?>
    <config>
        <modules>
            <Designo_Productname>
                <active>true</active>
                <codePool>local</codePool>
                <version>0.1.0</version>
            </Designo_Productname>
        </modules>
</config>

app\code\local\Designo\Productname\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Designo_Productname>
             <version>0.1.0</version>
        </Designo_Productname>
    </modules>
    <global>
        <helpers>
            <productname>
                <class>Designo_Productname_Helper</class>
            </productname>
        </helpers>
    </global>
    <admin>
        <routers>
             <adminhtml>
                  <args>
                      <modules>
                          <Designo_Productname before="Mage_Adminhtml">Designo_Productname_Adminhtml</Designo_Productname>
                      </modules>
                 </args>
            </adminhtml>
         </routers>
     </admin>
  </config> 

 app\code\local\Designo\Productname\Helper\Data.php

<?php
 class Designo_Productname_Helper_Data extends Mage_Core_Helper_Abstract
 {
 }

app\code\local\Designo\Productname\controllers\Adminhtml\Catalog\ProductController.php

 <?php
 require_once 'Mage/Adminhtml/controllers/Catalog/ProductController.php';
 class Designo_Productname_Adminhtml_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController
 {

 public function editAction()
 {
    $productId  = (int) $this->getRequest()->getParam('id');
    $product = $this->_initProduct();
    $productName = $product->getData('name');
    Mage::register('previous_name',$productName);
    $productColor = $product->getAttributeText('color');
    $productBrand = $product->getAttributeText('computer_manufacturers');
    $ProductCompleteName = $productName.' '.$productBrand.' '.$productColor;

    $product->setData('name',$ProductCompleteName);
    if ($productId && !$product->getId()) {
        $this->_getSession()->addError(Mage::helper('catalog')->__('This product no longer exists.'));
        $this->_redirect('*/*/');
        return;
    }

    $this->_title($product->getName());

    Mage::dispatchEvent('catalog_product_edit_action', array('product' => $product));

    $_additionalLayoutPart = '';
    if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE
        && !($product->getTypeInstance()->getUsedProductAttributeIds()))
    {
        $_additionalLayoutPart = '_new';
    }

    $this->loadLayout(array(
        'default',
        strtolower($this->getFullActionName()),
        'adminhtml_catalog_product_'.$product->getTypeId() . $_additionalLayoutPart
    ));

    $this->_setActiveMenu('catalog/products');

    if (!Mage::app()->isSingleStoreMode() && ($switchBlock = $this->getLayout()->getBlock('store_switcher'))) {
        $switchBlock->setDefaultStoreName($this->__('Default Values'))
            ->setWebsiteIds($product->getWebsiteIds())
            ->setSwitchUrl(
                $this->getUrl('*/*/*', array('_current'=>true, 'active_tab'=>null, 'tab' => null, 'store'=>null))
            );
    }

    $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);

    $block = $this->getLayout()->getBlock('catalog.wysiwyg.js');
    if ($block) {
        $block->setStoreId($product->getStoreId());
    }

    $this->renderLayout();
}
/**
 * Save product action
 */
public function saveAction()
{
    $storeId        = $this->getRequest()->getParam('store');
    $redirectBack   = $this->getRequest()->getParam('back', false);
    $productId      = $this->getRequest()->getParam('id');
    $isEdit         = (int)($this->getRequest()->getParam('id') != null);

    $data = $this->getRequest()->getPost();
    $data['name'] = Mage::registry('previous_name');
    if ($data) {
        $this->_filterStockData($data['product']['stock_data']);

        $product = $this->_initProductSave();

        try {
            $product->save();
            $productId = $product->getId();

            /**
             * Do copying data to stores
             */
            if (isset($data['copy_to_stores'])) {
                foreach ($data['copy_to_stores'] as $storeTo=>$storeFrom) {
                    $newProduct = Mage::getModel('catalog/product')
                        ->setStoreId($storeFrom)
                        ->load($productId)
                        ->setStoreId($storeTo)
                        ->save();
                }
            }

            $this->_getSession()->addSuccess($this->__('The product has been saved.'));
        } catch (Mage_Core_Exception $e) {
            $this->_getSession()->addError($e->getMessage())
                ->setProductData($data);
            $redirectBack = true;
        } catch (Exception $e) {
            Mage::logException($e);
            $this->_getSession()->addError($e->getMessage());
            $redirectBack = true;
        }
    }

    if ($redirectBack) {
        $this->_redirect('*/*/edit', array(
            'id'    => $productId,
            '_current'=>true
        ));
    } elseif($this->getRequest()->getParam('popup')) {
        $this->_redirect('*/*/created', array(
            '_current'   => true,
            'id'         => $productId,
            'edit'       => $isEdit
        ));
    } else {
        $this->_redirect('*/*/', array('store'=>$storeId));
    }
}

}

Before Install this Module Create Backup of your site and Database. After Install this Module Flush All Cache.

It May be helpfull for you.

Related Topic