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

$request->getBaseSubtotalInclTax() returns null
 
arcanine9
Jr. Member
 
Total Posts:  1
Joined:  2012-09-09
 

Hi all,

I just started customizing a Magento 1.5.1 shop and realized that the FreeShipping module uses the subtotal without tax. I want to include the tax and after looking around, I discovered the $request->getBaseSubtotalInclTax() is being used in Magento 1.6 but it keeps returning null in Magento 1.5.

public function collectRates(Mage_Shipping_Model_Rate_Request $request)
    
{
        
if (!$this->getConfigFlag(\\\'active\\\')) {
            
return false;
        
}

        $result 
Mage::getModel(\\\'shipping/rate_result\\\');
        
$packageValue $request->getPackageValue();

        
$this->_updateFreeMethodQuote($request);

        
$allow = ($request->getFreeShipping())
            || (
$request->getBaseSubtotalInclTax() >= $this->getConfigData(\\\'free_shipping_subtotal\\\'));

I see that this method getBaseSubtotalInclTax is apart of the Checkout Data helper and so I thought of creating my own method. However, I can\\\’t find where they have defined getPackageValue and setPackageValue. For example, in the Sales\\\\Model\\\\Quote\\\\Address.php I see:

$request->setPackageValue($item $item->getBaseRowTotal() : $this->getBaseSubtotal());
        
$packageValueWithDiscount $item
            
$item->getBaseRowTotal() - $item->getBaseDiscountAmount()
            : 
$this->getBaseSubtotalWithDiscount();

I was thinking of adding setPackageValueWithTax, but I have no idea where they have defined setPackageValue and getPackageValue.

Any help would be much appreciated, losing my mind with this…

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lyonscg
Sr. Member
 
Avatar
Total Posts:  173
Joined:  2009-11-13
Chicago IL
 

I had a few minutes to spare so I started looking around to see if I could help. I immediately found myself looking at this function:

//lib/Varien/Object.php
class Varien_Object
{
    
/**
     * Set/Get attribute wrapper
     *
     * @param   string $method
     * @param   array $args
     * @return  mixed
     */
    
public function __call($method$args)
    
{
        
switch (substr($method03)) {
            
case 'get' :
                
//Varien_Profiler::start('GETTER: '.get_class($this).'::'.$method);
                
$key $this->_underscore(substr($method,3));
                
$data $this->getData($key, isset($args[0]) ? $args[0] null);
                
//Varien_Profiler::stop('GETTER: '.get_class($this).'::'.$method);
                
return $data;

            case 
'set' :
                
//Varien_Profiler::start('SETTER: '.get_class($this).'::'.$method);
                
$key $this->_underscore(substr($method,3));
                
$result $this->setData($key, isset($args[0]) ? $args[0] null);
                
//Varien_Profiler::stop('SETTER: '.get_class($this).'::'.$method);
                
return $result;

            case 
'uns' :
                
//Varien_Profiler::start('UNS: '.get_class($this).'::'.$method);
                
$key $this->_underscore(substr($method,3));
                
$result $this->unsetData($key);
                
//Varien_Profiler::stop('UNS: '.get_class($this).'::'.$method);
                
return $result;

            case 
'has' :
                
//Varien_Profiler::start('HAS: '.get_class($this).'::'.$method);
                
$key $this->_underscore(substr($method,3));
                
//Varien_Profiler::stop('HAS: '.get_class($this).'::'.$method);
                
return isset($this->_data[$key]);
        
}
        
throw new Varien_Exception("Invalid method ".get_class($this)."::".$method."(".print_r($args,1).")");
    
}
}

I still don’t know where exactly in the code setPackageValue is initially being called, but I do know that when that happens, it passes through this _call method which is what sets it in the $_data array. I would suggest starting your debugging there. If I get time later tonight I will also debug this and try to see where the initial set is happening.

Interesting side note, a quick full project search didn’t return anything for setPackageValue on my Enterprise 1.12 installation which was surprising. I’ll setup community later and see if that still returns nothing.

I also noticed that getPackageValue is listed as a method in Mage_Shipping_Model_Rate_Request on line 92 which is also surprising.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lyonscg
Sr. Member
 
Avatar
Total Posts:  173
Joined:  2009-11-13
Chicago IL
 

So as I was closing eclipse, I realized, I was searching only phtml files which is why I wasn’t finding where setPackageValue was being called. Please excuse my brief lapse of retardation.

Anyway, after another search I found package_value is being set in
Mage_Shipping_Model_Carrier_Tablerate on line 149 and 155 in the condition_name and condition_short_name arrays.

I’m not sure if that’s the same package_value that is set when using setPackageValue however so this may be irrelevant.

I also found, setPackageValue being called from these locations:

Mage_Sales_Model_Quote_Address::requestShippingRates() / ln 852 and 856
Mage_Shipping_Model_Carrier_Tablerate::collectRates() / ln 68 and 72
Mage_Shipping_Model_Shipping::collectRatesByAddress() ln 375 and 376
Mage_Usa_Model_Shipping_Carrier_Dhl_International::_mapRequestToShipment() / ln 1191
Mage_Usa_Model_Shipping_Carrier_Dhl::_mapRequestToShipment / ln 1362

I’m not sure if the DHL files are in community or not but this should be enough to start your debugging at least and find what your missing.

I hope this helps

 
Magento Community Magento Community
Magento Community
Magento Community
 
arcanine9
Jr. Member
 
Total Posts:  1
Joined:  2012-09-09
 

Thanks Lyon,

I was able to find the instances of getPackageValue but not where its defined. Your Varien Object excerpt got me to thinking that we can just set our own “variables” so to speak that we can then call.

Spent another few hours trying to figure out how we can get this subtotal with the tax and after trying to utilize “Sales\Total\Quote\Subtotal.php”, “Tax\Model\Sales\Total\Subtotal.php”, I discovered a nice little method that exists in the Sales_Total_Tax class:
getSubtotalInclTax()… and voila, finally got it.

Added to Sales\Model\Quote\Address.php (around line 732 after setPackageValueWithDiscount):

$request->setPackageValueIncludingTax($this->getSubtotalInclTax());

Changed in Shipping\Model\Carrier\Freeshipping.php

$packageValue $request->getPackageValue();
To:
$packageValue $request->getPackageValueIncludingTax();

Thanks for the help, it got me on track and I hope this helps anybody else looking for the getPackageValue method that doesn’t exist =)

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