1

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

2

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.

  • thanks for the post, I will try this. May I know what are the functionalities this module covers? – harry Oct 29 '14 at 7:13
  • this is not working properly – harry Oct 29 '14 at 10:32
1

Take a look Recreating URL keys

class MageStack_24869_Model_Observer{
  public function updateurl($observer){
    //Mage::log('My log entry', null, 'mylogfile.log');
    $_product = $observer->getEvent()->getProduct()
    if($_product){
        $name = '';
        $brand = $_product->getAttributeText('manufacturer')
        if(strpos($_product->getData('name'), 'Brand') === false)){
           $name =. $_product->getData('name') . ' ' . $brand;
        }

        .....

        $Product->setData('name', rtrim($name, '-');      
    }
  }
}

You may want to create a new attribute to store the original product title to avoid do a lot of string manipulation

See Customizing magento using event observer method

  • thanks for the response. I didn't thought about url key, now I know they also need to be updated. Looking at this and recreating URL keys post they all are updating url keys. I wonder how would I update product name as well? I am not a magento expert, this is the first time I am working with magento. It would be much helpful if you could explain a little bit more!? thanks – harry Oct 29 '14 at 3:17
  • Every time a product is save in magento it will trigger catalog_product_save_before event which can be catch using an observer. Therefore in your update product attribute before it is save ... read more – Renon Stewart Oct 29 '14 at 3:22
  • above url not working – harry Oct 29 '14 at 3:35
  • Just add the link to my answer ( Customizing magento using event observer method) – Renon Stewart Oct 29 '14 at 3:43
  • hi RS, The above method is bit complicated, when every time a product gets edited, it has to check if attribute value already added in title. Further, if we change attribute value it should first delete previous value added in product name then add new one. So, I would like to know what is the best way to add custom attribute appear along with product name on cart, invoices, pdf, almost every where. Any suggestions? Thank you – harry Oct 30 '14 at 18:16
1

If your only wish is to add the attributes to the title, why not changing the page/html/head.phtml or implement an observer which changes the title: \Mage_Page_Block_Html_Head::setTitle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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