Magento 1.7 - software setting the price of a group of customers

In the latest version (1.7), magento has the ability to set prices for groups of clients, however I can not find documentation on how to do this programmatically. I tried the following code, but that didn't work. Does anyone know how to set the price of a customer group?

$_product->setCustomerGroupId($_price->getCustomerGroupId()); $_product->setGroupPrice($price); $_product->save(); 
+7
source share
2 answers

If you are actually using a magento object (not api), this is the behavior I found. We hope that the application makes sense, regardless of how you acquire data.

 // get my product $product = Mage::getModel('catalog/product')->load(x); // the group data is expecting an array of arrays that look like.. // array ('website_id'=>y, 'cust_group'=>z, 'price'=>n) $groupPricingData = array ( // for website 2, customer group 2 array ('website_id'=>2, 'cust_group'=>2, 'price'=>10), // for all websites, not logged in array ('website_id'=>0, 'cust_group'=>0, 'price'=>15) ); $product->setData('group_price',$groupPricingData); $product->save(); 

In this example, it will replace all previous group prices for the product, as wise.

 $product->setData('group_price',array()); $product->save(); 

will remove group pricing.

Another behavior that I noticed related to setting the store ID on the updated product will lead to the addition of a group price. Thus, if you download a group pricing group for a particular store, you don’t have to worry about losing the group price set against another store.

 // add a pricing to store 4 $product = Mage::getModel('catalog/product')->setStoreId(4)->load(1234); $product->setData('group_price',array ( array ( "website_id" => 3, "cust_group" => 4, "price" => 99 ))); $product->save(); // add a pricing to store 1 $product = Mage::getModel('catalog/product')->setStoreId(1)->load(1234); $product->setData('group_price',array ( array ( "website_id" => 1, "cust_group" => 2, "price" => 105 ))); $product->save(); // remove group pricing from store 2 $product = Mage::getModel('catalog/product')->setStoreId(2)->load(1234); $product->setData('group_price',array ()); $product->save(); 

This is convenient if you are dealing with group pricing lots in one store, but cannot influence other prices of store groups. I do not know if this is the simplest mechanism, but it still worked for me.

+18
source

Well, finally, I realized, for those who are looking for a solution: you need to make an array of data, including site_id, cust_group, the price and, if necessary, delete. It is available in the new magento release (v1.7)

  $group_prices = array(); if(isset($price_data['delete'])) { $group_prices[] = array( "website_id" => Mage::getModel('core/store')->load($price_data['store_id'])->getWebsiteId(), "cust_group" => $price_data['customer_group_id'], "all_groups" => false, "delete" => true ); } else { $group_prices[] = array( "website_id" => Mage::getModel('core/store')->load($price_data['store_id'])->getWebsiteId(), "cust_group" => $price_data['customer_group_id'], "all_groups" => false, "price" => $price_data["price"] ); } 
+4
source

All Articles