Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

[SOLVED] getPrice() doesn’t return a usable value
 
Zerg164
Member
 
Avatar
Total Posts:  31
Joined:  2009-05-31
 

Hi,

I’m trying to create a backend module to change prices; when I attempt to extract the prices to modify them, they are not a usable variable.

$model Mage::getModel('catalog/category');

                    if(
$data['root']=="all"){
                        $m_array 
$model->getProductCollection();
                        foreach(
$m_array as $m){
                            $price 
=$m->getPrice();
                            
$websites $m->getWebsiteIds();
                            
array_push($websites,$link->getStoreId());
                            
$m->setWebsiteIds($websites);
                            
$m->setStoreId($link->getStoreId());
                            
$m->setPrice($price);
                            
$m->save();
                        
}
                    }
With this code, $price is a variable that cannot be modified. I would like to be able change it, but it doesn’t work. I have looked at other threads for an explanation, and the best I can come up with is this thread:
http://www.magentocommerce.com/boards/viewthread/13298/
which doesn’t seem to help any.
Could someone maybe explain what is needed to get the price as a decimal number? Type-casting doesn’t work either.
 
Magento Community Magento Community
Magento Community
Magento Community
 
Zerg164
Member
 
Avatar
Total Posts:  31
Joined:  2009-05-31
 

Figured it out—using the “getProductCollection()” method doesn’t return a collection of products like I thought it did. This means that trying to get the price resulted in a null value. All it does is return a list of IDs. This is easily bypassed by using the ID to get a new model.

Zerg164 - 23 July 2009 11:46 AM

Hi,

$model Mage::getModel('catalog/category');

                    if(
$data['root']=="all"){
                        $m_array 
$model->getProductCollection();
                        foreach(
$m_array as $m){
                            $m 
Mage::getModel('product/catalog')->load($m->getId());
                            
$price =$m->getPrice();
                            
$websites $m->getWebsiteIds();
                            
array_push($websites,$link->getStoreId());
                            
$m->setWebsiteIds($websites);
                            
$m->setStoreId($link->getStoreId());
                            
$m->setPrice($price);
                            
$m->save();
                        
}
                    }

Hope this helps someone else in the future!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top