Magento – проблема с созданием настраиваемого модуля

Я использую Magento 1.9.1, и я пытаюсь создать модуль, который дает 50% скидку от общей суммы.

Вот мой код:

/app/code/local/VivasIndustries/PercentPayment/etc/config.xml:

<?xml version="1.0"?> <config> <modules> <VivasIndustries_PercentPayment> <version>0.1.0</version> </VivasIndustries_PercentPayment> </modules> <global> <sales> <quote> <totals> <discount> <class>VivasIndustries_PercentPayment_Model_Discount</class> <after>subtotal</after> </discount> </totals> </quote> <order_invoice> <totals> <discount> <class>VivasIndustries_PercentPayment_Model_Invoice</class> <after>subtotal</after> </discount> </totals> </order_invoice> <order_creditmemo> <totals> <discount> <class>VivasIndustries_PercentPayment_Model_Creditmemo</class> <after>subtotal</after> </discount> </totals> </order_creditmemo> </sales> </global> </config> 

/app/code/local/VivasIndustries/PercentPayment/controllers/IndexController.php:

 <?PHP class VivasIndustries_PercentPayment_Model_Discount extends Mage_Sales_Model_Quote_Address_Total_Abstract { public function collect(Mage_Sales_Model_Quote_Address $address) { if ($address->getData('address_type') == 'billing') return $this; $discount = 50; //your discount percent $grandTotal = $address->getGrandTotal(); $baseGrandTotal = $address->getBaseGrandTotal(); $totals = array_sum($address->getAllTotalAmounts()); $baseTotals = array_sum($address->getAllBaseTotalAmounts()); $address->setFeeAmount(-$totals * $discount / 100); $address->setBaseFeeAmount(-$baseTotals * $discount / 100); $address->setGrandTotal($grandTotal + $address->getFeeAmount()); $address->setBaseGrandTotal($baseGrandTotal + $address->getBaseFeeAmount()); return $this; } public function fetch(Mage_Sales_Model_Quote_Address $address) { if ($address->getData('address_type') == 'billing') return $this; $amt = $address->getDiscountAmount(); if ($amt != 0) { $address->addTotal(array( 'code' => 'Discount', 'title' => 'Discount', 'value' => $amt )); } return $address; } } ?> 

/app/etc/modules/VivasIndustries_PercentPayment.xml:

 <?xml version="1.0"?> <config> <modules> <VivasIndustries_PercentPayment> <active>true</active> <codePool>local</codePool> </VivasIndustries_PercentPayment> </modules> </config> 

Это все файлы, которые я создал для моего нового модуля. Все, что я сделал.

Я использовал это руководство: http://magento.ikantam.com/qa/how-add-discount-total-magento

Теперь, когда я пытаюсь открыть мою страницу проверки, я получил ошибку – There has been an error processing your request

Когда я открываю свой error_log, я вижу эту вещь:

[09-Nov-2014 18:22:35 UTC] CSRF state token does not match one provided.

Не могли бы вы помочь мне исправить эту проблему и сделать мой новый модуль таким же, как и предполагалось?

Заранее спасибо!

Изменение общей сложности всегда сложно. И трудно узнать проблему в вашем коде, если я не настроил этот модуль в своей системе. Во всяком случае здесь я поделился некоторыми кодами для изменения общего количества во время процесса оформления заказа. Я объяснил, насколько могу.

Для этого вам нужно обновить много вещей. Quote, Address, Order, Creditmemo, Invoice, shipping, multi shipping и т. Д. Мы здесь, сначала нам нужно создать наш файл конфигурации, который называется config.xml, config.xml

Обновить:

 <config> <modules> <VivasIndustries_PercentPayment> <version>0.1.0</version> </VivasIndustries_PercentPayment> </modules> <global> <helpers> <percentpayment> <class>VivasIndustries_PercentPayment_Helper</class> </percentpayment> </helpers> <models> <percentpayment> <class>VivasIndustries_PercentPayment_Model</class> <resourceModel>percentpayment_mysql4</resourceModel> </percentpayment> </models> <resources> <salesattribute1416562342_setup> <setup> <module>VivasIndustries_PercentPayment</module> <class>Mage_Sales_Model_Mysql4_Setup</class> </setup> <connection> <use>core_setup</use> </connection> </salesattribute1416562342_setup> <salesattribute1416562342_write> <connection> <use>core_write</use> </connection> </salesattribute1416562342_write> <salesattribute1416562342_read> <connection> <use>core_read</use> </connection> </salesattribute1416562342_read> </resources> <events> <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> </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> тем <config> <modules> <VivasIndustries_PercentPayment> <version>0.1.0</version> </VivasIndustries_PercentPayment> </modules> <global> <helpers> <percentpayment> <class>VivasIndustries_PercentPayment_Helper</class> </percentpayment> </helpers> <models> <percentpayment> <class>VivasIndustries_PercentPayment_Model</class> <resourceModel>percentpayment_mysql4</resourceModel> </percentpayment> </models> <resources> <salesattribute1416562342_setup> <setup> <module>VivasIndustries_PercentPayment</module> <class>Mage_Sales_Model_Mysql4_Setup</class> </setup> <connection> <use>core_setup</use> </connection> </salesattribute1416562342_setup> <salesattribute1416562342_write> <connection> <use>core_write</use> </connection> </salesattribute1416562342_write> <salesattribute1416562342_read> <connection> <use>core_read</use> </connection> </salesattribute1416562342_read> </resources> <events> <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> </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> тем <config> <modules> <VivasIndustries_PercentPayment> <version>0.1.0</version> </VivasIndustries_PercentPayment> </modules> <global> <helpers> <percentpayment> <class>VivasIndustries_PercentPayment_Helper</class> </percentpayment> </helpers> <models> <percentpayment> <class>VivasIndustries_PercentPayment_Model</class> <resourceModel>percentpayment_mysql4</resourceModel> </percentpayment> </models> <resources> <salesattribute1416562342_setup> <setup> <module>VivasIndustries_PercentPayment</module> <class>Mage_Sales_Model_Mysql4_Setup</class> </setup> <connection> <use>core_setup</use> </connection> </salesattribute1416562342_setup> <salesattribute1416562342_write> <connection> <use>core_write</use> </connection> </salesattribute1416562342_write> <salesattribute1416562342_read> <connection> <use>core_read</use> </connection> </salesattribute1416562342_read> </resources> <events> <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> </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> тем <config> <modules> <VivasIndustries_PercentPayment> <version>0.1.0</version> </VivasIndustries_PercentPayment> </modules> <global> <helpers> <percentpayment> <class>VivasIndustries_PercentPayment_Helper</class> </percentpayment> </helpers> <models> <percentpayment> <class>VivasIndustries_PercentPayment_Model</class> <resourceModel>percentpayment_mysql4</resourceModel> </percentpayment> </models> <resources> <salesattribute1416562342_setup> <setup> <module>VivasIndustries_PercentPayment</module> <class>Mage_Sales_Model_Mysql4_Setup</class> </setup> <connection> <use>core_setup</use> </connection> </salesattribute1416562342_setup> <salesattribute1416562342_write> <connection> <use>core_write</use> </connection> </salesattribute1416562342_write> <salesattribute1416562342_read> <connection> <use>core_read</use> </connection> </salesattribute1416562342_read> </resources> <events> <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> </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> тем <config> <modules> <VivasIndustries_PercentPayment> <version>0.1.0</version> </VivasIndustries_PercentPayment> </modules> <global> <helpers> <percentpayment> <class>VivasIndustries_PercentPayment_Helper</class> </percentpayment> </helpers> <models> <percentpayment> <class>VivasIndustries_PercentPayment_Model</class> <resourceModel>percentpayment_mysql4</resourceModel> </percentpayment> </models> <resources> <salesattribute1416562342_setup> <setup> <module>VivasIndustries_PercentPayment</module> <class>Mage_Sales_Model_Mysql4_Setup</class> </setup> <connection> <use>core_setup</use> </connection> </salesattribute1416562342_setup> <salesattribute1416562342_write> <connection> <use>core_write</use> </connection> </salesattribute1416562342_write> <salesattribute1416562342_read> <connection> <use>core_read</use> </connection> </salesattribute1416562342_read> </resources> <events> <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> </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> тем <config> <modules> <VivasIndustries_PercentPayment> <version>0.1.0</version> </VivasIndustries_PercentPayment> </modules> <global> <helpers> <percentpayment> <class>VivasIndustries_PercentPayment_Helper</class> </percentpayment> </helpers> <models> <percentpayment> <class>VivasIndustries_PercentPayment_Model</class> <resourceModel>percentpayment_mysql4</resourceModel> </percentpayment> </models> <resources> <salesattribute1416562342_setup> <setup> <module>VivasIndustries_PercentPayment</module> <class>Mage_Sales_Model_Mysql4_Setup</class> </setup> <connection> <use>core_setup</use> </connection> </salesattribute1416562342_setup> <salesattribute1416562342_write> <connection> <use>core_write</use> </connection> </salesattribute1416562342_write> <salesattribute1416562342_read> <connection> <use>core_read</use> </connection> </salesattribute1416562342_read> </resources> <events> <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> </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> тем <config> <modules> <VivasIndustries_PercentPayment> <version>0.1.0</version> </VivasIndustries_PercentPayment> </modules> <global> <helpers> <percentpayment> <class>VivasIndustries_PercentPayment_Helper</class> </percentpayment> </helpers> <models> <percentpayment> <class>VivasIndustries_PercentPayment_Model</class> <resourceModel>percentpayment_mysql4</resourceModel> </percentpayment> </models> <resources> <salesattribute1416562342_setup> <setup> <module>VivasIndustries_PercentPayment</module> <class>Mage_Sales_Model_Mysql4_Setup</class> </setup> <connection> <use>core_setup</use> </connection> </salesattribute1416562342_setup> <salesattribute1416562342_write> <connection> <use>core_write</use> </connection> </salesattribute1416562342_write> <salesattribute1416562342_read> <connection> <use>core_read</use> </connection> </salesattribute1416562342_read> </resources> <events> <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> </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> 

измените другие вещи в соответствии с этой конфигурацией. перед этим перейдите в свою базу данных, используя таблицу open core_resources phpmyadmin. и удалите запись модуля, если она есть. это оно.
Прокомментируйте здесь, если у вас есть какие-либо сомнения.