Magento - 创建新扩展时出现意外的PHP错误

时间:2015-01-15 19:09:01

标签: php magento

我正在使用Magento 1.9.0.1。

我的system.log文件中有非常奇怪的错误报告。

以下是日志所说的内容并重复多次:

2015-01-15T02:28:51+00:00 ERR (3): Notice: Undefined index: grand_total  in /home/sportsdi/public_html/beta/app/code/local/VivasIndustries/PercentPayment/Model/Quote/Address/Total/Discount.php on line 134
2015-01-15T02:28:51+00:00 ERR (3): Notice: Undefined index: grand_total  in /home/sportsdi/public_html/beta/app/code/local/VivasIndustries/PercentPayment/Model/Quote/Address/Total/Discount.php on line 66
2015-01-15T02:28:51+00:00 ERR (3): Notice: Undefined index: grand_total  in /home/sportsdi/public_html/beta/app/code/local/VivasIndustries/PercentShipping/Model/Quote/Address/Total/Discount.php on line 188
2015-01-15T02:28:51+00:00 ERR (3): Notice: Undefined variable: adress  in /home/sportsdi/public_html/beta/app/code/local/VivasIndustries/PercentShipping/Model/Quote/Address/Total/Discount.php on line 202

以下是这两个文件,您可以查看代码:

文件:/app/code/local/VivasIndustries/PercentPayment/Model/Quote/Address/Total/Discount.php:

<?php
class VivasIndustries_PercentPayment_Model_Quote_Address_Total_Discount extends Mage_Sales_Model_Quote_Address_Total_Abstract
{

     public function __construct()
    {
         $this -> setCode('discount_total');
         }
    /**
     * Collect totals information about discount
     * 
     * @param Mage_Sales_Model_Quote_Address $address 
     * @return Mage_Sales_Model_Quote_Address_Total_Shipping 
     */

     public function getPercSmall()
    {

        $EnableDiscount = Mage::getStoreConfig('checkout/percentpayment/active');
         $MinPrice = Mage::getStoreConfig('checkout/percentpayment/percentpayment_min_amt');
         $MaxPrice = Mage::getStoreConfig('checkout/percentpayment/percentpayment_max_amt');
         $quote1 = Mage::getModel('checkout/session')->getQuote();
         $quoteData= $quote1->getData();
         $SessionGrandTotal = $quoteData['grand_total'];



        return ($EnableDiscount==1 && Mage::getStoreConfig('checkout/percentpayment/discountusergroup') == Mage::getSingleton('customer/session')->getCustomerGroupId() && $MinPrice <= $SessionGrandTotal && $MaxPrice >= $SessionGrandTotal);
    }


    public function SetPercSession(){

    Mage::getSingleton('core/session')->setPcPayment('pc_payment');

    $PcPay = Mage::getSingleton('core/session')->getPcSession();

        if($PcPay == ""){
            Mage::getSingleton('core/session')->setPcSession('no_redirect');
            header("Location: http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
            exit;
        }

    }

    public function UnsPercSession(){
    Mage::getSingleton('core/session')->unsPcPayment();
    $PcPay = Mage::getSingleton('core/session')->getPcSession();
        if($PcPay != ""){
        Mage::getSingleton('core/session')->unsPcSession();
            header("Location: http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
            exit;

        }
    }   


     public function getPerc()
    {

        $EnableDiscount = Mage::getStoreConfig('checkout/percentpayment/active');
         $MinPrice = Mage::getStoreConfig('checkout/percentpayment/percentpayment_min_amt');
         $MaxPrice = Mage::getStoreConfig('checkout/percentpayment/percentpayment_max_amt');
         $quote1 = Mage::getModel('checkout/session')->getQuote();
         $quoteData= $quote1->getData();
         $SessionGrandTotal = $quoteData['grand_total'];


        $PcPayment = Mage::getSingleton('core/session')->getPcPayment();

        return ($MinPrice <= $SessionGrandTotal && $MaxPrice >= $SessionGrandTotal && $PcPayment == 'pc_payment');
    }

     public function collect(Mage_Sales_Model_Quote_Address $address)
    {
         parent :: collect($address);
         $items = $this->_getAddressItems($address);
         if (!count($items)) {
            return $this;
         }
         $quote= $address->getQuote();



         //amount definition


         if($this->getPerc())
            {




         $discount = Mage::getStoreConfig('checkout/percentpayment/percentpayment_percent');
         $setFee = Mage::getStoreConfig('checkout/fee/active');
        if($setFee==0)
        {
         $totals = array_sum($address->getAllTotalAmounts()) + VivasIndustries_PercentShipping_Model_Quote_Address_Total_Discount::getShippingPercent();
         } else {
         $totals = array_sum($address->getAllTotalAmounts()) + AG_Fee_Model_Fee::getFee();
         }
         $discountAmount = (-$totals * $discount / 100);


            $address->setDiscountAmount($discountAmount);
            $address->setBaseDiscountAmount($discountAmount);

            $quote->setDiscountAmount($discountAmount);      

         //amount definition

         $discountAmount = $quote -> getStore() -> roundPrice($discountAmount);
         $this -> _setAmount($discountAmount) -> _setBaseAmount($discountAmount);
         $address->setData('discount_total',$discountAmount);

         return $this;
         }
     }

    /**
     * Add discount totals information to address object
     * 
     * @param Mage_Sales_Model_Quote_Address $address 
     * @return Mage_Sales_Model_Quote_Address_Total_Shipping 
     */
     public function fetch(Mage_Sales_Model_Quote_Address $address)
    {

         $EnableDiscount = Mage::getStoreConfig('checkout/percentpayment/active');
         $MinPrice = Mage::getStoreConfig('checkout/percentpayment/percentpayment_min_amt');
         $MaxPrice = Mage::getStoreConfig('checkout/percentpayment/percentpayment_max_amt');
         $quote1 = Mage::getModel('checkout/session')->getQuote();
         $quoteData= $quote1->getData();
         $SessionGrandTotal = $quoteData['grand_total'];

         if($this->getPerc())
            {
         parent :: fetch($address);
         $amount = $address -> getTotalAmount($this -> getCode());
         if ($amount != 0){
             $address -> addTotal(array(
                     'code' => $this -> getCode(),
                     'title' => $this -> getLabel(),
                     'value' => $amount
                    ));
         }

         return $adress;
         }
     }

     public function getLabel()
    {
         return Mage::helper('percentpayment')->__('50% Предплата');
    }

    /**
     * Get label
     * 
     * @return string 
     */

}

这是另一个文件:/beta/app/code/local/VivasIndustries/PercentShipping/Model/Quote/Address/Total/Discount.php:

<?php
class VivasIndustries_PercentShipping_Model_Quote_Address_Total_Discount extends Mage_Sales_Model_Quote_Address_Total_Abstract
{

     public function __construct()
    {
         $this -> setCode('discountshipping_total');
         }
    /**
     * Collect totals information about discount
     * 
     * @param Mage_Sales_Model_Quote_Address $address 
     * @return Mage_Sales_Model_Quote_Address_Total_Shipping 
     */

     public function getShippingPerc()
    {

        $EnableDiscountShipping = Mage::getStoreConfig('checkout/percentshipping/active');



        return ($EnableDiscountShipping==1);
    }


/*  public function SetPercSession(){

    Mage::getSingleton('core/session')->setPcPayment('pc_payment');

    $PcPay = Mage::getSingleton('core/session')->getPcSession();

        if($PcPay == ""){
            Mage::getSingleton('core/session')->setPcSession('no_redirect');
            header("Location: http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
            exit;
        }

    }

    public function UnsPercSession(){
    Mage::getSingleton('core/session')->unsPcPayment();
    $PcPay = Mage::getSingleton('core/session')->getPcSession();
        if($PcPay != ""){
        Mage::getSingleton('core/session')->unsPcSession();
            header("Location: http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
            exit;

        }
    }   


    */

     public function collect(Mage_Sales_Model_Quote_Address $address)
    {
         parent :: collect($address);
         $items = $this->_getAddressItems($address);
         if (!count($items)) {
            return $this;
         }
         $quote= $address->getQuote();

         Mage::getSingleton('core/session', array('name' => 'frontend'));



         //amount definition


         if($this->getShippingPerc()) {

         $PcPayment = Mage::getSingleton('core/session')->getPcPayment();
         $PayOnDel = Mage::getSingleton('core/session')->getPayOnDel();

         $Tax100 = Mage::getStoreConfig('checkout/percentshipping/percentshipping100tax_percent');
         $Tax50 = Mage::getStoreConfig('checkout/percentshipping/percentshipping50tax_percent');
         $Tax100ondel = Mage::getStoreConfig('checkout/percentshipping/percentshipping100ondeltax_percent');

         if($PcPayment==""){
         $discount = Mage::getStoreConfig('checkout/percentshipping/percentshipping100_percent');
         }

         if($PcPayment!=""){
         $discount = Mage::getStoreConfig('checkout/percentshipping/percentshipping50_percent');
         }

         if($PayOnDel!=""){
         $discount = Mage::getStoreConfig('checkout/percentshipping/percentshipping100ondel_percent');
         }

         $totals = array_sum($address->getAllTotalAmounts());

         if($PcPayment!=""){
         $discountAmount = ($totals * $discount / 100);
         $discountAmount = $discountAmount*2;
         } else {
         $discountAmount = ($totals * $discount / 100);
         }


         //amount definition

         //Tax definitions
         if($PcPayment=="" && $PayOnDel==""){
             if($Tax100 >= $discountAmount){
             $discountAmount = $Tax100;
             $this -> _setAmount($discountAmount) -> _setBaseAmount($discountAmount);
             $address->setData('discountshipping_total',$discountAmount);

             Mage::getSingleton('core/session')->setPercentShipping($discountAmount);

             return $this;
             } else {
             $discountAmount = $quote -> getStore() -> roundPrice($discountAmount);
             $this -> _setAmount($discountAmount) -> _setBaseAmount($discountAmount);
             $address->setData('discountshipping_total',$discountAmount);

             Mage::getSingleton('core/session')->setPercentShipping($discountAmount);

             return $this;
             }

         }

         if($PcPayment!="" && $PayOnDel==""){
             if($Tax50 >= $discountAmount){
             $discountAmount = $Tax50;
             $this -> _setAmount($discountAmount) -> _setBaseAmount($discountAmount);
             $address->setData('discountshipping_total',$discountAmount);

             Mage::getSingleton('core/session')->setPercentShipping($discountAmount);

             return $this;
             } else {
             $discountAmount = $quote -> getStore() -> roundPrice($discountAmount);
             $this -> _setAmount($discountAmount) -> _setBaseAmount($discountAmount);
             $address->setData('discountshipping_total',$discountAmount);

             Mage::getSingleton('core/session')->setPercentShipping($discountAmount);

             return $this;
             }

         }

        if($PayOnDel!=""){
             if($Tax100ondel >= $discountAmount){
             $discountAmount = $Tax100ondel;
             $this -> _setAmount($discountAmount) -> _setBaseAmount($discountAmount);
             $address->setData('discountshipping_total',$discountAmount);

             Mage::getSingleton('core/session')->setPercentShipping($discountAmount);

             return $this;
             } else {
             $discountAmount = $quote -> getStore() -> roundPrice($discountAmount);
             $this -> _setAmount($discountAmount) -> _setBaseAmount($discountAmount);
             $address->setData('discountshipping_total',$discountAmount);

             Mage::getSingleton('core/session')->setPercentShipping($discountAmount);


             return $this;
             }

         }       

         }

     }

     public static function getShippingPercent() {

     $ret = Mage::getSingleton('core/session')->getPercentShipping();

     return $ret;
     }     

     public function fetch(Mage_Sales_Model_Quote_Address $address)
    {

         $EnableDiscount = Mage::getStoreConfig('checkout/percentpayment/active');
         $MinPrice = Mage::getStoreConfig('checkout/percentpayment/percentpayment_min_amt');
         $MaxPrice = Mage::getStoreConfig('checkout/percentpayment/percentpayment_max_amt');
         $quote1 = Mage::getModel('checkout/session')->getQuote();
         $quoteData= $quote1->getData();
         $SessionGrandTotal = $quoteData['grand_total'];


        if($this->getShippingPerc()) {
         parent :: fetch($address);
         $amount = $address -> getTotalAmount($this -> getCode());
         if ($amount != 0){
             $address -> addTotal(array(
                     'code' => $this -> getCode(),
                     'title' => $this -> getLabel(),
                     'value' => $amount
                    ));
         }

         return $adress;
         }

     }

     public function getLabel()
    {
         $TaxLabel = Mage::getStoreConfig('checkout/percentshipping/percentshipping_text');
         return Mage::helper('percentshipping')->__($TaxLabel);
    }

    /**
     * Get label
     * 
     * @return string 
     */

}

可以请指出我在哪里问题以及如何解决它? 提前谢谢!

1 个答案:

答案 0 :(得分:0)

日志文件中的第4个错误:未定义的变量:地址。 这是因为在函数Fetch()的两个文件中,你在return语句中都出现了拼写错误。它应该是return $address;,而不是return $adress;

和前三个错误:未定义的索引:grand_total。 这是因为&#39; grand_total&#39;变量$quoteData不存在索引。 使用一些调试消息来打印$quoteData的内容,您将了解问题。 同时尝试查看$quote1->getData();实际返回的内容。