2

I have a shop with many SKU's. I've recently added the manufacturer name attribute (e.g. Nike) to the catalog/product/list.phtml. As a result I now have duplication as the manufacturer shows before the product name, which also contains the manufacturer name (e.g. Nike Nike Shoes).

I wonder if anyone can advise of a PHP function where by I can trim the 'name' attribute by the 'manufacturer' attribute.

For example, if 'manufacturer' attribute = 'Nike' then remove 'Nike ' from 'name' attribute.

Here's the current code I have in list.phtml:

<?php
    echo $_product->getAttributeText('manufacturer');
    echo $_helper->productAttribute($_product, $_product->getName(), 'name')
?>
  • I don't understand why to add the Manufacturer name in the name of the product .. I think you are fighting against a self-created problem – drAlberT Mar 8 '16 at 11:39
  • You're correct but we have 1000's of SKU's, and the alternative is going through each product and removing the manufacturer reference in the product name. – YorkieMagento Mar 8 '16 at 11:53
  • what about doing the job directly in mysql (remove the manufacturer name in the product name)? .. it would be done in a single query once forever .. – drAlberT Mar 8 '16 at 12:08
  • see my modified answer .. it should do your job – drAlberT Mar 8 '16 at 12:16
  • But presumably I would have to do a separate query for each brand (e.g. Nike, Adidas, Puma and so on...)? – YorkieMagento Mar 8 '16 at 12:23
2

use str_repalce()

str_replace('//menufacture name ','//replace value', $_product->getName());

update code

$lowermenu=strtolower($_product->getAttributeText('manufacturer'));
$menufacture=array($lowermenu,$_product->getAttributeText('manufacturer'));

    echo str_replace($menufacture,' ',$_helper->productAttribute($_product, $_product->getName(), 'name'));

you can reference example here

| improve this answer | |
  • Thank you Qaisar. But I have many manufacturer names. Within this argument is there a way I can automate the picking up of the 'manufacturer' attribute and subsequent removal from the 'name' attribute? – YorkieMagento Mar 8 '16 at 11:56
  • how you are showing.paste that code i write full code for you. – Qaisar Satti Mar 8 '16 at 12:00
  • I've added my current code to the original question Qaisar. Showing how I am currently picking up the manufacturer and product name. – YorkieMagento Mar 8 '16 at 12:10
  • updated the code... – Qaisar Satti Mar 8 '16 at 12:15
  • Seem to get an error with this whereby only one product now shows on the listings page. – YorkieMagento Mar 8 '16 at 12:20
1

Use this code:

<?php

 if($_Product->getManufacturer())
 {
    str_replace($_Product->getManufacturer()," ",$_Product->getName());
 }
| improve this answer | |
  • Hi Arunendra - this results in an error for me where only one product shows on the listing page (there are 100's). I've added my current code to the original question. – YorkieMagento Mar 8 '16 at 12:09
  • I think you should assure to remove the Manufacturer only at the very beginning of the Product name .. otherwise you could make "ThenikeShoe" look like "TheShoe"" – drAlberT Mar 8 '16 at 12:11
1

I'd make the opposite. "if name begins with 'Nike'" then don't print the manufacturer ...

$_product_name = $_helper->productAttribute($_product, $_product->getName(), 'name');
$_manufacturer = $_product->getAttributeText('manufacturer');

if (0!==strpos($_product_name, $_manufacturer)) {
    echo $_manufacturer;
}
echo $_product_name);

But see my comment ..

Edited as per your current code

| improve this answer | |

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.