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

Event Observer - Wholesale Price using custom attribute
 
Auriferous
Jr. Member
 
Total Posts:  26
Joined:  2008-05-22
 

I am trying to create an observer to change the final price. The code checks the customer groupid and then switches what price field to gather the price from. I am having trouble though as it works only on the product view page but not on the catalog pages or in the shopping cart.

Again.. all i’m trying to accomplish is to switch all the existing logic from the existing product price field to a custom product attribute field I created called “dealer_price”

Here is the code I have so far:

app/etc/modules/DealerPrice.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
DealerPrice_Catalog>
            <
codePool>local</codePool>
            <
active>true</active>
        </
DealerPrice_Catalog>
    </
modules>
</
config>

app/code/local/DealerPrice/Catalog/etc/config.xml

<?xml version="1.0"?>
<config>
    <global>
      <
models>
          <
dealerpricecatalog>
               <class>
DealerPrice_Catalog_Model</class>
          </
dealerpricecatalog>
      </
models>
      <
events>
        <
catalog_product_get_final_price>
          <
observers>
            <
dealerprice_catalog_price_observer>
              <
type>singleton</type>
              <class>
dealerpricecatalog/price_observer</class>
              <
method>apply_dealer_price</method>
            </
dealerprice_catalog_price_observer>
          </
observers>
        </
catalog_product_get_final_price>     
      </
events>
    </global>
</
config>

app/code/local/DealerPrice/Catalog/Model/Price/Observer.php

<?php 
      
class DealerPrice_Catalog_Model_Price_Observer

      {

          
public function __construct(){

          }

          
public function apply_dealer_price($observer){

            $event 
$observer->getEvent();

            
$product $event->getProduct();   

            
// process dealer price for simple products     
                
if(Mage::getSingleton('customer/session')->getCustomerGroupId()==2){
               $finalPriceNow 
$product->getDealerPrice();
               
$product->setFinalPrice($finalPriceNow);
                
}                
             
return $this;
            
}   
      }

This works as I mentioned but only on the product view page.. Any Ideas?

Thanks

Bryan

 
Magento Community Magento Community
Magento Community
Magento Community
 
l781
Sr. Member
 
Total Posts:  109
Joined:  2008-11-09
 

@Auriferous - i’m looking the same - did you find solution?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Auriferous
Jr. Member
 
Total Posts:  26
Joined:  2008-05-22
 

Nothing yet.. was hoping Mosche would pick up on this one smile

This is something I’ve been trying to solve for over a year now (on and off) I keep hoping that a core update would come along and provide this functionality.

For me it goes much deeper then the original inquiry here as I need Retail Price, Dealer Price, WD Price (warehouse distributor pricing), special price, tier price, and a Map price to insure special prices don’t fall below map and as well to advertise map price to our customers. I’ve already had Pioneer call us up and complain that we had prices up under map. I really need some custom logic to ensure against such things.

Anybody else here have any Ideas? This seems like a relatively easy feature to add to the core.. could this be part of the next release?

 
Magento Community Magento Community
Magento Community
Magento Community
 
mageconsult
Jr. Member
 
Total Posts:  11
Joined:  2009-03-12
Germany, Rheine
 

I also had the same problem. I used the Event-Observer wiki and the price will be correct in detail-view AND in the basket. Only in list-view the price is wrong. If anyone has a solution, that would make me happy.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ecohen
Jr. Member
 
Total Posts:  1
Joined:  2009-03-07
 

Hey guys,

I don’t have a solution to this problem.  However, i do have a similar need.  I have a customer who wants to use Magento for wholesale.  In general I think Magento is ideal for any shopping cart solution however right now it does not have as flexible a pricing rules as i would like.

Ideally I want to be able to specify the price by customer group and product.  I think this is actually possible using Catalog Pricing Rules.  As far as i understand the pricing rules, they can be used to set the price to a specific amount AND they can be used to do so for a specific customer group.

The main problem as far as I can tell is that to enter this information would be so tedious for a client to do that it would be nearly impossible.  I am thinking of building a new module that adds a “Pricing” tab to the admin area which lets the client easily specify the pricing for each product/customer group in a spreadsheet style form. 

Is anyone interested in collaborating on this?  I have not thought about the design in detail and am very open to suggestions about a different design or additional features.

Thanks,

Elliot

 
Magento Community Magento Community
Magento Community
Magento Community
 
mweather
Member
 
Total Posts:  33
Joined:  2007-08-31
 

I’m also having the same problem, using slightly modified code from the wiki (Mine’s a shipping surcharge, though).

Anyone ever solve this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Sabin_33
Jr. Member
 
Total Posts:  27
Joined:  2009-06-16
 

I’m not sure who if anybody is following this post anymore.

I didn’t write a module for it but by modifying the a little bit of the core code I was able to achieve the results.

I did have to create a customer group for each type : ‘wholesale’ / ‘dealer’
And input each price in the prices ‘ tier price’ on the products page for each product

I figured out how to only show the correct pricing for each customer group

changing template/catalog/product/price.phtml line 66

<?php 
        
/* FOR TIER */ $_price1 $_taxHelper->getPrice($_product$_product->getPrice()) 
        
$_tierPrices $this->getTierPrices(); 
    
        if (
count($_tierPrices) > 0)
        
{
            $MyPrice 
1000000000.00;
        
}
        
else
        
{
            
//$MyPrice = '<span class="price">'.$_price.'</span>';
            
$MyPrice $_coreHelper->currency($_price,true,true);
        
}
    
    ?>
    
    <?php 
foreach ($_tierPrices as $_price1): ?>
    
        <?php 
            
/* Find the Lowest Price AT QTY 1 */
            
if ($_price1['price_qty'== 1)
            
{
                
if ($_price1['formated_price'$MyPrice)
                
{
                    $MyPrice 
$_price1['formated_price'];
                
}
            }
        ?>
    
    <?php 
endforeach; ?>

line 236

<span class="regular-price" id="product-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
                    
<?php /* DM EDITS */
                        /* echo $_coreHelper->currency($_price,true,true) */
                        /* echo $_coreHelper->currency($_price,true,true);*/
                        
echo $MyPrice;
                    
?>
                
</span>

template/catalog/product/view/tierprices.phtml line 43

<ul class="no-display">
    <!-- <
ul class="<?php /* echo ($this->getInGrouped() ? 'product-pricing-grouped' : 'product-pricing'); */ ?>"> -->
    
    
<?php 
        
/* DM EDITS */
            
$MyPrice 100000000.00;
        
/* DM EDITS */
    
?>
    
    <?php 
if ($this->getInGrouped()): ?>
        <?php $_tierPrices 
$this->getTierPrices($_product); ?>
    <?php 
endif; ?>
    
    
    <?php Mage
::helper('weee')->processTierPrices($_product$_tierPrices); ?>
    
    <?php 
foreach ($_tierPrices as $_price): ?>
        
        <?php 
            
/* Find the Lowest Price  */
            
if ($_price['formated_price'$MyPrice)
            
{
                $MyPrice 
$_price;
                echo 
'<br />'.$MyPrice['formated_price'].'<br />';
            
}
        ?>
template/catalog/product/view/tierprices.phtml line 193
<?php if (!$this->getInGrouped()): ?>
            <?php 
if(($_product->getPrice() == $_product->getFinalPrice() && $_product->getPrice() > $_price['price'])
            || (
$_product->getPrice() != $_product->getFinalPrice() &&  $_product->getFinalPrice() > $_price['price'])): ?>
                
                <?php 
                    
/* DM EDITS */
                
?>
                
                
<!--
                
<?php /* echo $this->__('and') ?>&nbsp;
                <strong class="benefit">
                <?php echo $this->__('save')?>&nbsp;
                <?php echo $_price['savePercent'] */
?>%
                -->
                
            
<?php endif ?>
            
</strong>
        
<?php endif; ?>

from the core files Mage/catalog/block/product/view.php

$_tierPrices $this->getTierPrices(); 
                    
        if (
count($_tierPrices) > 0)
        
{
            $MyPrice 
10000000000.00;
            foreach (
$_tierPrices as $_price1)
            
{
                
/* Find the Lowest Price AT QTY 1 */
                
if ($_price1['price_qty'== 1)
                
{
                    
if ($_price1['price'$MyPrice)
                    
{
                        $MyPrice 
$_price1['price'];
                    
}
                }
            }
;
            
$_finalPrice $MyPrice;
        
};
 
Magento Community Magento Community
Magento Community
Magento Community
 
Gopinath
Jr. Member
 
Avatar
Total Posts:  2
Joined:  2008-10-06
 

i have the same issue. any body got the solution? If it is can you plz share?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Auriferous
Jr. Member
 
Total Posts:  26
Joined:  2008-05-22
 

I finally wrote an extension for this… I still need to fix a few things and am going to add some features such as “Price Name” so that if you name it “Wholesale” or “Distributor Price” it will display this on the front end based on which rule it uses..

http://www.magentocommerce.com/magento-connect/Auriferous/extension/3757/wildcardbi_rulepriceattribute

 
Magento Community Magento Community
Magento Community
Magento Community
 
Gopinath
Jr. Member
 
Avatar
Total Posts:  2
Joined:  2008-10-06
 

Thank you Auriferous. We will check it. Again thank you for share.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ryankeen
Jr. Member
 
Total Posts:  12
Joined:  2010-03-24
 

Thanks, Auriferous!  I was looking for some module that provides the same functionality as yours does.  Do you know how it has been working on a live site?  We are using 1.4.0.1

 
Magento Community Magento Community
Magento Community
Magento Community
 
jadu
Jr. Member
 
Total Posts:  2
Joined:  2011-04-15
 

To set the custom product price in the catalog page you need to edit this code under <event> tab in your config.xml

<catalog_product_collection_load_after>
<observers>
<YOURNAMESPACE_YOURMODULE_price_Observer>
<type>singleton</type>
<class>YOURNAMESPACE_YOURMODULE_Model_Price_Observer</class>
<method>updateProductCollectionPrice</method>
</YOURNAMESPACE_YOURMODULE_price_Observer>
</observers>
</catalog_product_collection_load_after>



add this code in observer.php in the folder app/code/local/YOURNAMESPACE/YOURMODULE/Price//Model/
class YOURNAMESPACE_YOURMODULE_Model_Price_Observer{
public function updateProductCollectionPrice($observer) {
foreach($observer->getEvent()->getCollection() as $product) {
if(!$product->isGrouped()) {
$price = $product->getPrice();
$finalPriceNow = Mage::getModel(’catalogrule/rule’)->calcProductPriceRule($product,$price);
if(empty($finalPriceNow)) {
$finalPriceNow = $product->getFinalPrice();
}
$specialPrice = $product->getSpecialPrice();
if($finalPriceNow && $finalPriceNow < $price) {
if ($newPrice < 0){
$newPrice = $finalPriceNow;
}

if(Mage::getSingleton(’customer/session’)->getCustomerGroupId()==2){ //if customer is wholesaler
$finalPrice = $product->getDealerPrice();
$product->setFinalPrice($finalPrice);
}

}
}
}
return $this;
}
}

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