cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 1.9.3 wont save group prices

Magento 1.9.3 wont save group prices

Hi there,

 

I was assigned a Magento 1.9.3 project that would take in products in JSON format, and save customer group prices. However, even though there are no errors, nothing gets saved. The group prices won't show in the admin panel nor in the catalogue as expected.

Why is this? I've looked up every single article or stackexchange cases concerning group prices, but none of these seem to solve my problem.

Currently using the catalog_block_product_list_collection event.

 

$group_prices = $theProduct->getData('group_price');
if (is_null($group_prices)) {
    $attribute = $theProduct->getResource()->getAttribute('group_price');
    if ($attribute) {
        $attribute->getBackend()->afterLoad($theProduct);
        $group_prices = $theProduct->getData('group_price');
    }
}

if(!is_array($group_prices)){
    $group_prices = array();
    $theProduct->addData(array('group_price' => $group_prices));
    $theProduct->save();
}

$new_price = array(array (
    'website_id'=>Mage_Core_Model_App::ADMIN_STORE_ID,
    'customer_group_id'=>$customerGroupId,
    'price'=> $singleProduct->Price));
$group_prices = array_merge($group_prices, $new_price);

$currentStore = Mage::app()->getStore()->getId();
try{
    Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
    $size = count($group_prices);

    // First Delete all the group prices of product
    $theProduct->setData('group_price', array());
    $theProduct->save();
    // Again save the old prices and new prices
    $theProduct->setData('group_price', $group_prices);
    $theProduct->save();
} catch(Exception $e) {
    echo $e->getMessage();
}
Mage::app()->getStore()->setId($currentStore); 

And yet, no group prices are saved when checking in the admin panel. Any help is appreciated.