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

Mage_Sales_Model_Quote collectTotals() issue
 
iaps
Jr. Member
 
Total Posts:  6
Joined:  2012-09-22
 

The function call to $address->collectTotals(); within the for loop of this function is causing a Maximum Nested Function exception when I switch stores.  I commented out that line (~1263) and everything loaded correctly (aside from the shopping cart totals...they were no longer being calculated).

Has anyone else had this problem, or does anyone know what I can do to fix this?

I changed xdebug.max_nesting_level = 1000, but it still throws the exception.  Anything bigger than 1000 will just time-out the page load.

Thanks in advance!

 
Magento Community Magento Community
Magento Community
Magento Community
 
iaps
Jr. Member
 
Total Posts:  6
Joined:  2012-09-22
 

I should include that this Nested Function exception only occurs when changing the store and the user is logged in.

 
Magento Community Magento Community
Magento Community
Magento Community
 
iaps
Jr. Member
 
Total Posts:  6
Joined:  2012-09-22
 

Here is a link to the exception message: http://iaps.ca/nested_function_exception.htm

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ryan Sun _Kuafu
Guru
 
Total Posts:  317
Joined:  2008-11-14
FL
 

is Mage_Catalog_Model_Product_Type_Price->_calcProductTierPricing( ) a custom method?

 
Magento Community Magento Community
Magento Community
Magento Community
 
iaps
Jr. Member
 
Total Posts:  6
Joined:  2012-09-22
 

Yes, I changed getFinalPrice, which calls _calcProductTeirPricing, slightly so I can base the product price on the overall cart qty:

public function getFinalPrice($qty null$product{
        
if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
            
return $product->getCalculatedFinalPrice();
        
}

        $finalPrice 
$this->getBasePrice($product$qty);
        
$product->setFinalPrice($finalPrice);

        
Mage::dispatchEvent(\'catalog_product_get_final_price\', array(\'product\' => $product\'qty\' => $qty));

        
$finalPrice $product->getData(\'final_price\');


        
// if tier prices are defined, also adapt them to configurable products
        // example: if a shirt is available in red and black and if you buy
        // three or more the price is eight euro, you can also buy one red and
        // two black shirts and you will get the tier price of eight euro.
        // based on https://www.magentocommerce.com/boards/viewthread/10743/
        //*
        
if ($product->getTierPriceCount() > 0{
            $tierPrice 
$this->_calcProductTierPricing($product);
            if (
$tierPrice $finalPrice{
                $finalPrice 
$tierPrice;
            
}
        }
//*/
        
        
$finalPrice $this->_applyOptionsPrice($product$qty$finalPrice);
        
$finalPrice max(0$finalPrice);
        
$product->setFinalPrice($finalPrice);
        
        return 
$finalPrice;
    
}

    
/**
     * Get product final price via configurable product\'s tier pricing structure.
     * Uses qty of parent item to determine price.
     *
     * @param Mage_Catalog_Model_Product $product
     * @return float
     */
    
protected function _calcProductTierPricing($product{
        
// CWS        
        
$tierPrice 0;
        
        if (
$items Mage::getSingleton(\'checkout/session\')->getQuote()->getItemsCollection()) {
            
// map mapping the IDs of the parent products with the quantities of the corresponding simple products
            
$qty 0;
            foreach (
$items as $item{
                $qty 
+= $item->getQty();
            
}
            
return $this->getBasePrice($product$qty);
        
}
        
return $tierPrice;
    
}

I took that change out of the equation and everything worked!  Is there a better way of getting a list of all the products in the cart to determine the total cart qty?

I\’m going to try to get the total cart qty in a different way, instead of iterating through all the cart products..too much overhead it seems.
...
I tried the following, but I\’m still getting the nested function exception:

$qty 0;
        
$cart Mage::getModel(\'checkout/cart\')->getQuote()->getData();
        if(isset(
$cart[\'items_qty\']))
            
$qty $cart[\'items_qty\'];
        
        return 
$this->getBasePrice($product$qty);
 
Magento Community Magento Community
Magento Community
Magento Community
 
iaps
Jr. Member
 
Total Posts:  6
Joined:  2012-09-22
 

Within the comments of getFinalPrice, you can see the post this solution was based on:
https://www.magentocommerce.com/boards/viewthread/10743/

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ryan Sun _Kuafu
Guru
 
Total Posts:  317
Joined:  2008-11-14
FL
 

rewrite Mage_Sales_Model_Quote_Item::getProduct()

public function getProduct()
    
{
        $product 
parent::getProduct();
        
$product->setQuoteItem($this);
        
reuturn $product;
    
}
modify your _calcTierPricing method and get quote by
if($poduct->getQuoteItem()){
        $quote 
$poduct->getQuoteItem()->getQuote();
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
Ryan Sun _Kuafu
Guru
 
Total Posts:  317
Joined:  2008-11-14
FL
 

the post your solution based on is too old to work with new version

 
Magento Community Magento Community
Magento Community
Magento Community
 
iaps
Jr. Member
 
Total Posts:  6
Joined:  2012-09-22
 

I didn’t find getProduct() within Sales/Model/Quote/Item.php but I did find it in Sales/Model/Quote/Item/Abstract.php, so I temporarily copied that model to my /local/ folder and made the addition to the bottom of that function:

public function getProduct()
    
{
        $product 
$this->_getData('product');
        if ((
$product === null) && $this->getProductId()) {
            $product 
Mage::getModel('catalog/product')
                ->
setStoreId($this->getQuote()->getStoreId())
                ->
load($this->getProductId());
            
$this->setProduct($product);
        
}

        
/**
         * Reset product final price because it related to custom options
         */
        
$product->setFinalPrice(null);
        if (
is_array($this->_optionsByCode)) {
            $product
->setCustomOptions($this->_optionsByCode);
        
}
        
        $product
->setQuoteItem($this);
        
        return 
$product;
    
}

Then I updated my _calcProductTeirPricing function:

protected function _calcProductTierPricing($product{
        
// CWS
        
if ($product->getQuoteItem()) {
            $quote 
$product->getQuoteItem()->getQuote();
            
$cart $quote->getData(); //Mage::getModel('checkout/cart')->getQuote()->getData();
            
if (isset($cart['items_qty']))
                return 
$this->getBasePrice($product$cart['items_qty']);
        
}
        
return false;
    
}

This has fixed the issue!!  Thank you very much smile

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