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

A big problem! 
 
yugyn_lonewolf
Sr. Member
 
Total Posts:  108
Joined:  2008-05-31
 

Hi, i have a big problem!

please, see the attached file…

I have created a new cash on delivery payment module.
Into the “Quote.php file”, into the “getTotals()” function, I add a new total into the totals array, I update the tax if available and I update the grand total.
If you see the attach, the totals it’s ok, but i have this problems:

- the tax is OK, but the tax information view the total without the cash on delivery tax amount; if you see the top of this attach, you can see the “var_dump” of total element with the code tax ($tax_code = ‘US-CA-*-Rate 1’ in this order).

But the big problem isn’t this!

I have an other problem:

- if I place the order, in admin panel the order hasn’t the “cash on delivery total”, and the order hasn’t the cash on delivery amount in the tax and grand total; if I open the order for print (if I’m customer user), i see the same order without the cash on delivery amount as well as in admin panel.

This is the code of getTotals() function:

public function getTotals() {
        
        $totals 
parent::getTotals();
        
$model Mage::getModel('cashOnDelivery/cashOnDelivery');

        if (isset(
$totals['shipping']) && is_object($totals['shipping'])) {
            
if (!is_null($this->_payments) && 
                
$this->getPayment()->hasMethodInstance() && 
                
$this->getPayment()->getMethodInstance()->getCode() == 'cashOnDelivery'{
                    
                    
// Retriev the tax code for this module
                    
$tax_code $model->getTaxCode();
                                        
                    
// Retriew the amount
                    
$model->setAmount();
                    
$amount $model->getAmount();
                    
$amount_base $amount;
                    
                    
// Verify if this module has a tax
                    
$tax_flag false;        
                    if (isset(
$totals['tax']) && is_object($totals['tax']) && $tax_code!=''{
                        $tax_array 
$totals['tax']->getData('full_info');

                        if (isset(
$tax_array[$tax_code])) {
                            
// This module has a tax
                            
$tax_flag true;
                            
$tax_apply $tax_array[$tax_code];
                            
                            
// Calculate the base and tax of amount
                            
$amount_base number_format(($amount 100) / (100 $tax_apply['percent']), 2);
                            
$amount_tax $amount $amount_base

                            
// Update the tax into the totals array
                            
$tax_apply['amount'+= $amount_tax;
                            
$tax_apply['base_amount'+= $amount_tax;
                            echo 
$tax_apply['amount'];
                            echo 
'<br>';
                            
var_dump($tax_apply);
                            
$totals['tax']->setData('value'$totals['tax']->getData('value') + $amount_tax);
                        
}
                    }

                    
// Create a new total to insert into totals array
                    
$cash_ondelivery Mage::getModel('sales/quote_address_total');
                    
$cash_ondelivery->setData('code''cash_ondelivery_amount');
                    
$cash_ondelivery->setData('title''Cash on delivery amount');
                    
$cash_ondelivery->setData('value'$amount_base);

                    
// Update the gran total into the totals array
                    
$totals['grand_total']->setData('value'$totals['grand_total']->getData('value') +
                    
$amount);
                    
                    
// Swith the position of totals
                    
if ($tax_flag{
                        
// The new total will be inserted become the tax total
                        
$tmp $totals['grand_total'];    
                        
array_push($totals$tmp);
                        
$totals['grand_total'$totals['tax'];
                        
$totals['tax'$cash_ondelivery;
                    
else {
                        
// The new total will be inserted become the grand total 
                        
$tmp $totals['grand_total'];    
                        
array_push($totals$tmp);
                        
$totals['grand_total'$cash_ondelivery;                        
                    
}
                    
            }
        }
        
        
return $totals;
        
    
}

Any idea for help me?

Thank you.

Image Attachments
Screen.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

iam also looking for the same solution.

if you replace

if (!is_null($this->_payments) && 
                
$this->getPayment()->hasMethodInstance() && 
                
$this->getPayment()->getMethodInstance()->getCode() == 'cashOnDelivery'{

by

if (!is_null($this->_payments) && $this->getPayment()->getMethodInstance()->getCode() == 'cashOnDelivery'{

you have no problem within the admin. but in frontend cart. Iam looking for a solution to check if model is called by frontend or backend so we could manage that.

sorry for my bad english

cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
yugyn_lonewolf
Sr. Member
 
Total Posts:  108
Joined:  2008-05-31
 

Hi,

if I replace the condition with your code, my situation is the same:

- in admin, if I open the order, this is without cash on delivery
- in myAccount, if I open the order (for print, for example) I have the order without cash on delivery
- the report of tax, before placed the order, is incorrect.

Finally, the order (see my attach) is € 110:
- items: 100
- shipping: 7
- cash on delivery: 3

but, after to placed it, the order is 107 €:
- items: 100
- shipping: 7

I don’t understand where is the problem…

See you soon…

P.S. sorry for my terrible english!

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