3

I am using Magento 1.9.0.1.

I've created two extensions. The first one i created is called PercentPayment and the second PercentShipping.

The issue appeared when i created the second one. Strangely when i've made the second one - PercentShipping a problem occured on the first one PercentPayment. Notice that i was not having the problem before i created the second one extension.

Take a look at this picture, it is taken from http://mymagento.com/index.php/admin/sales_order/view/order_id/170/key/bc6310e25596905e90c2d1f99c712d51/ <- The Sales order view page.

enter image description here

Before i've add PercentShipping to this table and the new extension was made there was no problem. The PercentPayment value was correctly shown.

Here i will post some codes from the extensions which i think are releated to this problem.

PercentPayment config:

<?xml version="1.0"?>
<config>
  <modules>
    <VivasIndustries_PercentPayment>
      <version>0.1.0</version>
    </VivasIndustries_PercentPayment>
  </modules>
      <adminhtml>
        <layout>
            <updates>
                <percentpayment>
                    <file>percentpayment.xml</file>
                </percentpayment>
            </updates>
        </layout>
    </adminhtml> 
  <global>
        <models>
      <percentpayment>
        <class>VivasIndustries_PercentPayment_Model</class>
        <resourceModel>percentpayment_mysql4</resourceModel>
      </percentpayment>
    </models>
    <helpers>
    <percentpayment>
      <class>VivasIndustries_PercentPayment_Helper</class>
    </percentpayment>
    </helpers>
    <resources>
      <percentpaymentatribute_setup>
        <setup>
          <module>VivasIndustries_PercentPayment</module>
          <class>Mage_Sales_Model_Mysql4_Setup</class>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </percentpaymentatribute_setup>
      <percentpaymentatribute_write>
        <connection>
          <use>core_write</use>
        </connection>
      </percentpaymentatribute_write>
      <percentpaymentatribute_read>
        <connection>
          <use>core_read</use>
        </connection>
      </percentpaymentatribute_read>
    </resources>
    <events>
    <sales_order_place_after>
        <observers>
            <clear_session>
                <class>VivasIndustries_PercentPayment_Model_Observer</class>
                <method>clearCheckoutSession</method>
            </clear_session>
        </observers>
    </sales_order_place_after>
    <checkout_type_onepage_save_order_after> <!-- identifier of the event we want to catch -->
        <observers>
          <checkout_type_onepage_save_order_after_discount_handler> <!-- identifier of the event handler -->
            <type>model</type> <!-- class method call type; valid are model, object and singleton -->
            <class>percentpayment/newordertotalobserver</class> <!-- observers class alias -->
            <method>saveDiscountTotal</method>  <!-- observer's method to be called -->
            <args></args> <!-- additional arguments passed to observer -->
          </checkout_type_onepage_save_order_after_discount_handler>
        </observers>
      </checkout_type_onepage_save_order_after>     
    <checkout_type_multishipping_create_orders_single> <!-- identifier of the event we want to catch -->
        <observers>     
          <checkout_type_multishipping_create_orders_single_discount_handler> <!-- identifier of the event handler -->
            <type>model</type> <!-- class method call type; valid are model, object and singleton -->
            <class>percentpayment/newordertotalobserver</class> <!-- observers class alias -->
            <method>saveDiscountTotalForMultishipping</method>  <!-- observer's method to be called -->
            <args></args> <!-- additional arguments passed to observer -->
          </checkout_type_multishipping_create_orders_single_discount_handler>      
        </observers>
      </checkout_type_multishipping_create_orders_single>
        <sales_model_service_quote_submit_after>
            <observers>
                <clear_session>
                    <class>VivasIndustries_PercentPayment_Observer</class>
                    <method>clearCheckoutSession</method>
                </clear_session>
            </observers>
        </sales_model_service_quote_submit_after>
    </events>   
     <sales>
        <quote>
            <totals>                
                <discount_total>
                    <class>percentpayment/quote_address_total_discount</class>
                    <after>subtotal,freeshipping,tax_subtotal,shipping</after>
                    <before>grand_total</before>
                </discount_total> 
            </totals>
        </quote>
            <order_invoice>
                <totals>                
                <discount_total>
                    <class>percentpayment/order_invoice_total_discount</class>
                    <after>subtotal,freeshipping,tax_subtotal,shipping</after>
                    <before>grand_total</before>
                </discount_total> 
                </totals>
            </order_invoice>
            <order_creditmemo>
                <totals>                
                <discount_total>
                    <class>percentpayment/order_creditmemo_total_discount</class>
                    <after>subtotal,freeshipping,tax_subtotal,shipping</after>
                    <before>grand_total</before>
                </discount_total> 
                </totals>
            </order_creditmemo>
    </sales>
  </global>
</config>  

PercentShipping Config:

<?xml version="1.0"?>
<config>
  <modules>
    <VivasIndustries_PercentShipping>
      <version>0.1.0</version>
    </VivasIndustries_PercentShipping>
  </modules>
      <adminhtml>
        <layout>
            <updates>
                <percentshipping>
                    <file>percentshipping.xml</file>
                </percentshipping>
            </updates>
        </layout>
    </adminhtml> 
  <global>
        <models>
      <percentshipping>
        <class>VivasIndustries_PercentShipping_Model</class>
        <resourceModel>percentshipping_mysql4</resourceModel>
      </percentshipping>
    </models>
    <helpers>
    <percentshipping>
      <class>VivasIndustries_PercentShipping_Helper</class>
    </percentshipping>
    </helpers>
    <resources>
      <percentshippingatribute_setup>
        <setup>
          <module>VivasIndustries_PercentShipping</module>
          <class>Mage_Sales_Model_Mysql4_Setup</class>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </percentshippingatribute_setup>
      <percentshippingatribute_write>
        <connection>
          <use>core_write</use>
        </connection>
      </percentshippingatribute_write>
      <percentshippingatribute_read>
        <connection>
          <use>core_read</use>
        </connection>
      </percentshippingatribute_read>
    </resources>
    <events>
    <sales_order_place_after>
        <observers>
            <clear_session>
                <class>VivasIndustries_PercentShipping_Model_Observer</class>
                <method>clearCheckoutSession</method>
            </clear_session>
        </observers>
    </sales_order_place_after>
    <checkout_type_onepage_save_order_after> <!-- identifier of the event we want to catch -->
        <observers>
          <checkout_type_onepage_save_order_after_discount_handler> <!-- identifier of the event handler -->
            <type>model</type> <!-- class method call type; valid are model, object and singleton -->
            <class>percentshipping/newordertotalobserver</class> <!-- observers class alias -->
            <method>saveDiscountshippingTotal</method>  <!-- observer's method to be called -->
            <args></args> <!-- additional arguments passed to observer -->
          </checkout_type_onepage_save_order_after_discount_handler>
        </observers>
      </checkout_type_onepage_save_order_after>     
    <checkout_type_multishipping_create_orders_single> <!-- identifier of the event we want to catch -->
        <observers>     
          <checkout_type_multishipping_create_orders_single_discount_handler> <!-- identifier of the event handler -->
            <type>model</type> <!-- class method call type; valid are model, object and singleton -->
            <class>percentshipping/newordertotalobserver</class> <!-- observers class alias -->
            <method>saveDiscountshippingTotalForMultishipping</method>  <!-- observer's method to be called -->
            <args></args> <!-- additional arguments passed to observer -->
          </checkout_type_multishipping_create_orders_single_discount_handler>      
        </observers>
      </checkout_type_multishipping_create_orders_single>
        <sales_model_service_quote_submit_after>
            <observers>
                <clear_session>
                    <class>VivasIndustries_PercentShipping_Observer</class>
                    <method>clearCheckoutSession</method>
                </clear_session>
            </observers>
        </sales_model_service_quote_submit_after>
    </events>   
     <sales>
        <quote>
            <totals>                
                <discountshipping_total>
                    <class>percentshipping/quote_address_total_discount</class>
                    <after>subtotal,freeshipping,tax_subtotal,shipping,discount_total</after>
                    <before>grand_total</before>
                </discountshipping_total> 
            </totals>
        </quote>
            <order_invoice>
                <totals>                
                <discountshipping_total>
                    <class>percentshipping/order_invoice_total_discount</class>
                    <after>subtotal,freeshipping,tax_subtotal,shipping,discount_total</after>
                    <before>grand_total</before>
                </discountshipping_total> 
                </totals>
            </order_invoice>
            <order_creditmemo>
                <totals>                
                <discountshipping_total>
                    <class>percentshipping/order_creditmemo_total_discount</class>
                    <after>subtotal,freeshipping,tax_subtotal,shipping,discount_total</after>
                    <before>grand_total</before>
                </discountshipping_total> 
                </totals>
            </order_creditmemo>
    </sales>
  </global>
</config>  

PercentPayment - /VivasIndustries/PercentPayment/Model/Newordertotalobserver.php:

<?php
class VivasIndustries_PercentPayment_Model_Newordertotalobserver
{
     public function saveDiscountTotal(Varien_Event_Observer $observer)
    {
         $order = $observer -> getEvent() -> getOrder();
         $quote = $observer -> getEvent() -> getQuote();
         $shippingAddress = $quote -> getShippingAddress();
         if($shippingAddress && $shippingAddress -> getData('discount_total')){
             $order -> setData('discount_total', $shippingAddress -> getData('discount_total'));
             }
        else{
             $billingAddress = $quote -> getBillingAddress();
             $order -> setData('discount_total', $billingAddress -> getData('discount_total'));
             }
         $order -> save();
     }

     public function saveDiscountTotalForMultishipping(Varien_Event_Observer $observer)
    {
         $order = $observer -> getEvent() -> getOrder();
         $address = $observer -> getEvent() -> getAddress();
         $order -> setData('discount_total', $shippingAddress -> getData('discount_total'));
         $order -> save();
     }
}

PercentShipping - /VivasIndustries/PercentShipping/Model/Newordertotalobserver.php:

<?php
class VivasIndustries_PercentShipping_Model_Newordertotalobserver
{
     public function saveDiscountshippingTotal(Varien_Event_Observer $observer)
    {
         $order = $observer -> getEvent() -> getOrder();
         $quote = $observer -> getEvent() -> getQuote();
         $shippingAddress = $quote -> getShippingAddress();
         if($shippingAddress && $shippingAddress -> getData('discountshipping_total')){
             $order -> setData('discountshipping_total', $shippingAddress -> getData('discountshipping_total'));
             }
        else{
             $billingAddress = $quote -> getBillingAddress();
             $order -> setData('discountshipping_total', $billingAddress -> getData('discountshipping_total'));
             }
         $order -> save();
     }

     public function saveDiscountshippingTotalForMultishipping(Varien_Event_Observer $observer)
    {
         $order = $observer -> getEvent() -> getOrder();
         $address = $observer -> getEvent() -> getAddress();
         $order -> setData('discountshipping_total', $shippingAddress -> getData('discountshipping_total'));
         $order -> save();
     }
}

PercentPayment: /app/design/adminhtml/default/default/template/percentpayment/sales/order/total.phtml :

<?php $this->setPriceDataObject($this->getSource()) ?>

    <tr>
        <td class="label"><?php echo Mage::helper('percentpayment')->formatFee($this->getSource()->getDiscountTotal()) ?></td>
        <td>
            <?php echo $this->displayPrices($this->getSource()->getBaseFeeAmount(), $this->getSource()->getDiscountTotal()); ?>
        </td>
    </tr>

PercentShipping: /app/design/adminhtml/default/default/template/percentshipping/sales/order/total.phtml :

<?php $this->setPriceDataObject($this->getSource()) ?>

    <tr>
        <td class="label"><?php echo Mage::helper('percentshipping')->formatFee($this->getSource()->getDiscountshippingTotal()) ?></td>
        <td>
            <?php echo $this->displayPrices($this->getSource()->getBaseFeeAmount(), $this->getSource()->getDiscountshippingTotal()); ?>
        </td>
    </tr>

PercentPayment - /VivasIndustries/PercentPayment/sql/percentpaymentatribute_setup/mysql4-install-0.1.0.php

<?php
$installer = $this;
$installer->startSetup();

$installer->addAttribute("quote_address", "discount_total", array("type"=>"varchar"));
$installer->addAttribute("order", "discount_total", array("type"=>"varchar"));
$installer->endSetup();

PercentShipping - /VivasIndustries/PercentShipping/sql/percentshippingatribute_setup/mysql4-install-0.1.0.php:

<?php
$installer = $this;
$installer->startSetup();

$installer->addAttribute("quote_address", "discountshipping_total", array("type"=>"varchar"));
$installer->addAttribute("order", "discountshipping_total", array("type"=>"varchar"));
$installer->endSetup();

If you can not see the problem here please ask in the comment and i can show more of the code for both extensions.

The both extensions are created by me, but i can not understand why the value from the second extenions is showing correctly but the extension from the first one is not showing correct.

Thanks in advance and I hope we can clear this problem and find out from where it comes.

3

I think the issue could be that both modules listen to the same event and do not have unique identifiers for the events in the config.xml so only the second modules observers are working.

Magento will combine the config.xml and so if the items are not unique then the will be overridden.

Try updating checkout_type_onepage_save_order_after_discount_handler and checkout_type_multishipping_create_orders_single_discount_handler to something unique for the modules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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