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

Get Different Customer Group Price in Cart
 
johnny_n
Jr. Member
 
Total Posts:  13
Joined:  2012-06-12
 

In the cart, I’m trying to get customer pricing for a different group—to publicize the discounts offered by paying to join another group (members).

I’ve used the code here as a base: http://stackoverflow.com/questions/12326814/magento-get-product-price-given-a-customer-group but I’m not getting very far… the code always seems to return null.  I’ve been through it many times.

$now Mage::getModel('core/date')->timestamptime() );
$websiteId Mage::app()->getStore()->getWebsiteId();
$customerGroup 4;

$nonmembersaved = array();
foreach(
$this->getItems() as $_item):
$msrp_amt $_item->getProduct()->getData('msrp');
$id $_item->getId();
$memberprice Mage::getResourceModel('catalogrule/rule')->getRulePrice$now$websiteId$customerGroup$id );
$nonmembersaved[] $msrp_amt-$memberprice;
$nonmembersavedclean = (abs(array_sum($nonmembersaved))) ;

....

What is the best way to do this?  I’ve searched high and low and can’t find a solid solution anywhere…

 
Magento Community Magento Community
Magento Community
Magento Community
 
johnny_n
Jr. Member
 
Total Posts:  13
Joined:  2012-06-12
 

Bumping this, hoping for a reply… grin

 
Magento Community Magento Community
Magento Community
Magento Community
 
Siggi_Schmitz
Enthusiast
 
Avatar
Total Posts:  811
Joined:  2011-07-03
 

I don`t have tested it but try

$id $_item->getProductId();
or
$id $_item->getProduct()->getId();

instead of

$id $_item->getId();

because i think that getRulePrice() needs the real product id not the item id.

 
Magento Community Magento Community
Magento Community
Magento Community
 
johnny_n
Jr. Member
 
Total Posts:  13
Joined:  2012-06-12
 

@Siggi, that was an excellent suggestion—you are absolutely right, the proper ID wasn’t being pulled for each product.  Now it is.

I used:

$id $_item->getProduct()->getId();

The problem is it’s still not working—I’ve echoed all of the parameters separately:

$now
$websiteId
$customerGroup
$id

And they are all passing correct values… but it still doesn’t work.  This doesn’t even work if I plug it straight into where I’m echoing it instead of assigning it to a variable and echoing that:

Mage::getResourceModel('catalogrule/rule')->getRulePrice$now$websiteId$customerGroup$id )

I’m at a loss here.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Siggi_Schmitz
Enthusiast
 
Avatar
Total Posts:  811
Joined:  2011-07-03
 

Have a look in the function getRulePrice() and put some debug logs into, perhaps you find out why it doesn`t return the price?

 
Magento Community Magento Community
Magento Community
Magento Community
 
johnny_n
Jr. Member
 
Total Posts:  13
Joined:  2012-06-12
 

Well, I just spent a while longer on this - there’s no error, it’s doing what it should.  What I’m confused about now is that technically this isn’t a catalog price rule.  It’s not setup that way in admin (Rules - Catalog Price Rules).  This is a group price - under price in the product pages.  So I’m not sure if in the end this is the correct way or not.  I went over some of the functions, and it looks like this is what Magento is using in price.phtml but there must be an easier way.

http://freegento.com/doc/d6/d54/class_mage___catalog___model___product___type___price.html

http://freegento.com/doc/d9/dc9/_catalog_2_model_2_product_2_type_2_price_8php-source.html

I guess my next step is to try to see what sort of array I get when I call getPrice() or getFinalPrice()…

I also thought maybe it had something to do with retrieving the price in the cart so I tried the same code in the product page with the same result - it returns null.

So this is just an update, sadly no joy.

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