cancel
Showing results for 
Search instead for 
Did you mean: 

Where in the code does Magento update product attributes?

SOLVED

Where in the code does Magento update product attributes?

Where in the code does Magento update product attributes?

 

I'm trying for a workaround to functionality that doesn't exist yet in m2epro. I use Magento to manage my ebay store and listings. m2epro is lacking the ability to create a description with PHP (confirmed from support). My solution is to create an attribute called ebay_description, and then anytime product attributes are updated, it calls a php function that updates ebay_description before saving it to the database.

 

This is the best solution I can think of at the moment, unless anyone has a better idea. But I have exhausted every option with m2epro including calling phtml files from a static block.

 

I'm a 20 year php programmer (which means I'm doing my best in this object oriented world), but fairly new to Magento, so please be specific.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Where in the code does Magento update product attributes?

Hi,

 

What i would do is use the event catalog_product_save_after observer. If you are going to rebuild the ebay_description each time attributes change then it would be safe to just rebuild it everytime a product is saved.

 

If you need help setting up an observer to do this just let me know.

 

Regards,

Andy

Problem solved? Click Accept as Solution!
www.iwebsolutions.co.uk | Magento Small Business Partner

View solution in original post

5 REPLIES 5

Re: Where in the code does Magento update product attributes?

Hi,

 

What i would do is use the event catalog_product_save_after observer. If you are going to rebuild the ebay_description each time attributes change then it would be safe to just rebuild it everytime a product is saved.

 

If you need help setting up an observer to do this just let me know.

 

Regards,

Andy

Problem solved? Click Accept as Solution!
www.iwebsolutions.co.uk | Magento Small Business Partner

Re: Where in the code does Magento update product attributes?

I could use help setting that up. Will that catch changes made by importing data?

 

Been doing some research on your suggestion. Haven't yet completely figured out how to set it up, but do you think the catalog_product_prepare_save event would be a better place to put this, then I could simply set a new attribute value for ebay_description and let magento handle saving everything to the db?

Re: Where in the code does Magento update product attributes?

 

You can you use that but whatever you decide you need to do the following in your config.xml

 

<?xml version="1.0"?>
<global>
... <events> <catalog_product_save_before> <observers> <attribute_observer> <type>singleton</type> <class>[Vendor]_[Namespace]_Model_Observer</class> <method>[methodName]</method> </attribute_observer> </observers> </catalog_product_save_before> </events>
... </global>

 

Then create an observer class in your module

 

<?php
 
class [Vendor]_[Namespace]_Model_Observer
{
    public function [methodName]()
    {
        // do things here
    }
}

 

Regards,

Andy

Problem solved? Click Accept as Solution!
www.iwebsolutions.co.uk | Magento Small Business Partner

Re: Where in the code does Magento update product attributes?

Andy, thank you very much for your help. I successfully created an observer that writes a log file, so the rest should be easy. I can test this easy enough, but do you happen to know if this event will also be fired when using the import function?

Re: Where in the code does Magento update product attributes?

Hi.

 

No Problem Smiley Happy

 

Yes it will. Magento uses the same methods for saving across the board. It does make importing slower than say going direct to database but it means you can rely on everything you would expect to fire; observers in this case.

 

Regards,

Andy

 

Problem solved? Click Accept as Solution!
www.iwebsolutions.co.uk | Magento Small Business Partner