0

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.

1 Answer 1

0

Try below code

try {
$product1 = $product2 = Mage::getModel('catalog/product')->setStoreId(1)->load(34);
$product1->setData('group_price', array());
$product1->save();

$product2->setData('group_price',array (
    array (
        "website_id" => 0,
        "cust_group" => 1,
        "price" => 101
    )));
$product2->save();
} catch (Exception $ex) {
    echo $ex->getMessage();
} catch (Mage_Core_Exception $e) {
    echo $e->getMessage();
}
1
  • Thanks for the quick reply. I've tried this multiple times, but it still does not solve my problem. Commented Nov 28, 2017 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.