0

I have a DB with many products. (Magento ver. 1.7.0.2)

Some products are linked to a specific designer (a custom sub-category configured in magento). I would like to snatch the designer name from the related designer of a product and prepend this to the product title.

From which table/field should I grab the designer(category) name? Where within the product row would the ID of the relevant category be stored?

To which field would I prepend the data?

Are there multiple fields I would need to update for DB integrity?

I would use PHP to perform an automated query, one product at a time.

Thanks in advance for any guidance offered :)

1

I would suggest not to modify the Product Name in the Database (to preserve your data as it is, as attaching temporary Category Names makes editing more difficult later) but change the display in the frontend. You can do this in several ways, i suggest you fetch your category first (extend a Block from Mage_Catalog_Block_Product_View):

public function getFirstCat(){
    $categoryIDs = $this->getProduct()->getCategoryIds();
    if(count($categoryIDs)){
        $_category = Mage::getModel('catalog/category')->load($categoryIDs[0]);
        return $_category->getName();
    }
}

This returns you the Subcategory of your Product. Depending if you have more complex Categories (a specific "Designers" Category for example), you have to check if the found Category is a subcategory of a given Parent (Have a look at this answer: How to get top parent Category from current category object?

In your template, i.e. product/view.phtml, insert this where needed (before your Product Name):

<?php echo $this->getFirstCat() ?>

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.