0

I'm trying to add a certain fixed amount to the grand total of an order through a totals collector. But, for some reason, grand_total and base_grand_total are always 0.

I've tried every <before> and <after> combination I could think of, but for some reason grand_total and base_grand_total are always 0.

Am I overlooking something obvious here? Could anybody point me into the right direction? I'm using Magento 1.9.0.1.

Thanks in advance!


config.xml

<!-- ... -->
<sales>
    <quote>
        <totals>
            <discount>
                <class>ipsum/discount_quote</class>
                <after>grand_total</after>
            </discount>
        </totals>
    </quote>
</sales>
<!-- ... -->

Quote.php (all temporary, of course ;-))

<?php
/**
 *
 */
class Lorem_Ipsum_Model_Discount_Quote
    extends Mage_Sales_Model_Quote_Address_Total_Abstract
{
    /**
     *
     */
    public function collect(Mage_Sales_Model_Quote_Address $address) {
        if ($address->getAddressType() != 'shipping') {
            return $this;
        }

        var_dump($address->getGrandTotal()); die();

        return $this;
    }

    /**
     *
     */
    public function fetch(Mage_Sales_Model_Quote_Address $address) {
        if ($address->getAddressType() != 'shipping') {
            return $this;
        }

        $address->addTotal(array(
            'code'  => 'lorem_ipsum',
            'title' => 'Lorem Ipsum',
            'value' => 0,
        ));

        return $this;
    }
}

1 Answer 1

0

this is array var_dump($address->getData()); return in collect

array (size=86)
  'address_id' => string '239' (length=3)
  'quote_id' => string '119' (length=3)
  'created_at' => string '2016-09-01 13:47:26' (length=19)
  'updated_at' => string '2016-09-01 16:17:42' (length=19)
  'customer_id' => null
  'save_in_address_book' => string '0' (length=1)
  'customer_address_id' => null
  'address_type' => string 'billing' (length=7)
  'email' => null
  'prefix' => null
  'firstname' => null
  'middlename' => null
  'lastname' => null
  'suffix' => null
  'company' => null
  'street' => null
  'city' => null
  'region' => null
  'region_id' => null
  'postcode' => null
  'country_id' => null
  'telephone' => null
  'fax' => null
  'same_as_billing' => string '0' (length=1)
  'free_shipping' => string '0' (length=1)
  'collect_shipping_rates' => string '0' (length=1)
  'shipping_method' => null
  'shipping_description' => null
  'weight' => string '0.0000' (length=6)
  'subtotal' => int 0
  'base_subtotal' => int 0
  'subtotal_with_discount' => string '0.0000' (length=6)
  'base_subtotal_with_discount' => string '0.0000' (length=6)
  'tax_amount' => string '0.0000' (length=6)
  'base_tax_amount' => string '0.0000' (length=6)
  'shipping_amount' => string '0.0000' (length=6)
  'base_shipping_amount' => string '0.0000' (length=6)
  'shipping_tax_amount' => int 0
  'base_shipping_tax_amount' => int 0
  'discount_amount' => string '0.0000' (length=6)
  'base_discount_amount' => string '0.0000' (length=6)
  'grand_total' => int 0
  'base_grand_total' => int 0
  'customer_notes' => null
  'applied_taxes' => string 'a:0:{}' (length=6)
  'discount_description' => null
  'shipping_discount_amount' => null
  'base_shipping_discount_amount' => null
  'subtotal_incl_tax' => int 0
  'base_subtotal_total_incl_tax' => null
  'hidden_tax_amount' => null
  'base_hidden_tax_amount' => null
  'shipping_hidden_tax_amount' => null
  'base_shipping_hidden_tax_amnt' => null
  'shipping_incl_tax' => string '0.0000' (length=6)
  'base_shipping_incl_tax' => string '0.0000' (length=6)
  'vat_id' => null
  'vat_is_valid' => null
  'vat_request_id' => null
  'vat_request_date' => null
  'vat_request_success' => null
  'gift_message_id' => null
  'extra_tax_amount' => int 0
  'base_extra_tax_amount' => int 0
  'recurring_initial_fee_amount' => int 0
  'base_recurring_initial_fee_amount' => int 0
  'cached_items_all' => 
    array (size=0)
      empty
  'cached_items_nominal' => 
    array (size=0)
      empty
  'cached_items_nonnominal' => 
    array (size=0)
      empty
  'recurring_trial_payment_amount' => int 0
  'base_recurring_trial_payment_amount' => int 0
  'nominal_subtotal_amount' => int 0
  'base_nominal_subtotal_amount' => int 0
  'total_qty' => int 0
  'base_virtual_amount' => int 0
  'virtual_amount' => int 0
  'base_subtotal_incl_tax' => int 0
  'nominal_discount_amount' => int 0
  'base_nominal_discount_amount' => int 0
  'applied_rule_ids' => string '' (length=0)
  'nominal_weee_amount' => int 0
  'base_nominal_weee_amount' => int 0
  'nominal_tax_amount' => int 0
  'base_nominal_tax_amount' => int 0
  'msrp_amount' => int 0
  'base_msrp_amount' => int 0

code

public function collect(Mage_Sales_Model_Quote_Address $address) {
    if ($address->getAddressType() != 'shipping') {
        return $this;
    }

    echo var_dump($address->getData());  die(); // it will show 00 the total is not set 

    return $this;
}

here is fetch result

    array (size=104)
  'address_id' => string '240' (length=3)
  'quote_id' => string '119' (length=3)
  'created_at' => string '2016-09-01 13:47:26' (length=19)
  'updated_at' => string '2016-09-01 16:24:29' (length=19)
  'customer_id' => null
  'save_in_address_book' => string '0' (length=1)
  'customer_address_id' => null
  'address_type' => string 'shipping' (length=8)
  'email' => null
  'prefix' => null
  'firstname' => null
  'middlename' => null
  'lastname' => null
  'suffix' => null
  'company' => null
  'street' => null
  'city' => null
  'region' => null
  'region_id' => null
  'postcode' => null
  'country_id' => null
  'telephone' => null
  'fax' => null
  'same_as_billing' => string '1' (length=1)
  'free_shipping' => int 0
  'collect_shipping_rates' => boolean false
  'shipping_method' => null
  'shipping_description' => null
  'weight' => float 88
  'subtotal' => float 888
  'base_subtotal' => float 888
  'subtotal_with_discount' => string '0.0000' (length=6)
  'base_subtotal_with_discount' => string '0.0000' (length=6)
  'tax_amount' => int 0
  'base_tax_amount' => int 0
  'shipping_amount' => int 0
  'base_shipping_amount' => int 0
  'shipping_tax_amount' => int 0
  'base_shipping_tax_amount' => int 0
  'discount_amount' => int 0
  'base_discount_amount' => int 0
  'grand_total' => float 888
  'base_grand_total' => float 888
  'customer_notes' => null
  'applied_taxes' => string 'a:0:{}' (length=6)
  'discount_description' => string '' (length=0)
  'shipping_discount_amount' => int 0
  'base_shipping_discount_amount' => int 0
  'subtotal_incl_tax' => float 888
  'base_subtotal_total_incl_tax' => null
  'hidden_tax_amount' => int 0
  'base_hidden_tax_amount' => int 0
  'shipping_hidden_tax_amount' => int 0
  'base_shipping_hidden_tax_amnt' => null
  'shipping_incl_tax' => int 0
  'base_shipping_incl_tax' => int 0
  'vat_id' => null
  'vat_is_valid' => null
  'vat_request_id' => null
  'vat_request_date' => null
  'vat_request_success' => null
  'gift_message_id' => null
  'extra_tax_amount' => int 0
  'base_extra_tax_amount' => int 0
  'recurring_initial_fee_amount' => int 0
  'base_recurring_initial_fee_amount' => int 0
  'cached_items_all' => 
    array (size=1)
      0 => 
        object(Mage_Sales_Model_Quote_Item)[29]
          protected '_eventPrefix' => string 'sales_quote_item' (length=16)
          protected '_eventObject' => string 'item' (length=4)
          protected '_quote' => 
            object(Mage_Sales_Model_Quote)[147]
              ...
          protected '_options' => 
            array (size=1)
              ...
          protected '_optionsByCode' => 
            array (size=1)
              ...
          protected '_notRepresentOptions' => 
            array (size=1)
              ...
          protected '_flagOptionsSaved' => boolean true
          protected '_errorInfos' => 
            object(Mage_Sales_Model_Status_List)[164]
              ...
          protected '_parentItem' => null
          protected '_children' => 
            array (size=0)
              ...
          protected '_messages' => 
            array (size=0)
              ...
          protected '_resourceName' => string 'sales/quote_item' (length=16)
          protected '_resource' => null
          protected '_resourceCollectionName' => string 'sales/quote_item_collection' (length=27)
          protected '_cacheTag' => boolean false
          protected '_dataSaveAllowed' => boolean true
          protected '_isObjectNew' => null
          protected '_data' => 
            array (size=69)
              ...
          protected '_hasDataChanges' => boolean true
          protected '_origData' => 
            array (size=53)
              ...
          protected '_idFieldName' => string 'item_id' (length=7)
          protected '_isDeleted' => boolean false
          protected '_oldFieldsMap' => 
            array (size=0)
              ...
          protected '_syncFieldsMap' => 
            array (size=0)
              ...
  'cached_items_nominal' => 
    array (size=0)
      empty
  'cached_items_nonnominal' => 
    array (size=1)
      0 => 
        object(Mage_Sales_Model_Quote_Item)[29]
          protected '_eventPrefix' => string 'sales_quote_item' (length=16)
          protected '_eventObject' => string 'item' (length=4)
          protected '_quote' => 
            object(Mage_Sales_Model_Quote)[147]
              ...
          protected '_options' => 
            array (size=1)
              ...
          protected '_optionsByCode' => 
            array (size=1)
              ...
          protected '_notRepresentOptions' => 
            array (size=1)
              ...
          protected '_flagOptionsSaved' => boolean true
          protected '_errorInfos' => 
            object(Mage_Sales_Model_Status_List)[164]
              ...
          protected '_parentItem' => null
          protected '_children' => 
            array (size=0)
              ...
          protected '_messages' => 
            array (size=0)
              ...
          protected '_resourceName' => string 'sales/quote_item' (length=16)
          protected '_resource' => null
          protected '_resourceCollectionName' => string 'sales/quote_item_collection' (length=27)
          protected '_cacheTag' => boolean false
          protected '_dataSaveAllowed' => boolean true
          protected '_isObjectNew' => null
          protected '_data' => 
            array (size=69)
              ...
          protected '_hasDataChanges' => boolean true
          protected '_origData' => 
            array (size=53)
              ...
          protected '_idFieldName' => string 'item_id' (length=7)
          protected '_isDeleted' => boolean false
          protected '_oldFieldsMap' => 
            array (size=0)
              ...
          protected '_syncFieldsMap' => 
            array (size=0)
              ...
  'recurring_trial_payment_amount' => int 0
  'base_recurring_trial_payment_amount' => int 0
  'nominal_subtotal_amount' => int 0
  'base_nominal_subtotal_amount' => int 0
  'total_qty' => int 4
  'base_virtual_amount' => int 0
  'virtual_amount' => int 0
  'base_subtotal_incl_tax' => float 888
  'nominal_discount_amount' => int 0
  'base_nominal_discount_amount' => int 0
  'nominal_weee_amount' => int 0
  'base_nominal_weee_amount' => int 0
  'nominal_tax_amount' => int 0
  'base_nominal_tax_amount' => int 0
  'msrp_amount' => int 0
  'base_msrp_amount' => int 0
  'can_apply_msrp' => boolean false
  'servicecenters_amount' => int 0
  'base_servicecenters_amount' => int 0
  'freeshipping_amount' => int 0
  'base_freeshipping_amount' => int 0
  'rounding_deltas' => 
    array (size=0)
      empty
  'weee_amount' => int 0
  'base_weee_amount' => int 0
  'applied_taxes_reset' => boolean true
  'free_method_weight' => float 88
  'item_qty' => int 4
  'tax_shipping_amount' => int 0
  'base_tax_shipping_amount' => int 0
  'shipping_taxable' => int 0
  'base_shipping_taxable' => int 0
  'is_shipping_incl_tax' => boolean false
  'cart_fixed_rules' => 
    array (size=0)
      empty
  'applied_rule_ids' => string '' (length=0)
  'base_shipping_hidden_tax_amount' => int 0

here is result in fetch var_dump($address->getData());

/**
 *
 */
public function fetch(Mage_Sales_Model_Quote_Address $address) {
    if ($address->getAddressType() != 'shipping') {
        return $this;
    }
 var_dump($address->getData());  die(); // here it will show 00 the total 
    $address->addTotal(array(
        'code' => 'lorem_ipsum',
        'title' => 'Lorem Ipsum',
        'value' => 0,
    ));

    return $this;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.