1

facing this error undefined variable framework/App/ErrorHandler

[2018-10-06 12:45:23] main.CRITICAL: Notice: Undefined variable: vls in /home/dukaania/public_html/testing2/app/code/Sugarcode/Test/Model/Total/Fee.php on line 46 {"exception":"[object] (Exception(code: 0): Notice: Undefined variable: vls in /home/dukaania/public_html/testing2/app/code/Sugarcode/Test/Model/Total/Fee.php on line 46 at /home/dukaania/public_html/testing2/vendor/magento/framework/App/ErrorHandler.php:61)"} []

Please someone review my code:

<?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Sugarcode\Test\Model\Total;




class Fee extends \Magento\Quote\Model\Quote\Address\Total\AbstractTotal
{

   /**
     * Collect grand total address amount
     *
     * @param \Magento\Quote\Model\Quote $quote
     * @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment
     * @param \Magento\Quote\Model\Quote\Address\Total $total
     * @return $this
     */


       protected $_coreSession;

    protected $quoteValidator = null; 

     protected $vls = null;


    public function __construct(\Magento\Quote\Model\QuoteValidator $quoteValidator, \Magento\Framework\Session\SessionManagerInterface $coreSession)
    {
        $this->quoteValidator = $quoteValidator;
           $this->_coreSession = $coreSession;
    }



       public function getValue()
{
     $this->_coreSession->start();
    return $this->_coreSession->getMyValue(); //Get value from customer session
}



  public function collect(
        \Magento\Quote\Model\Quote $quote,
        \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment,
        \Magento\Quote\Model\Quote\Address\Total $total
    ) {
        parent::collect($quote, $shippingAssignment, $total);




        global $total_cost;
       $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
$customerSession->setValue($total_cost); //set value in customer session
$vluas= $customerSession->getValue();

$this->vls = $vluas[0].$vluas[1];


        $exist_amount = 0; //$quote->getFee(); 
        $fee = $this->vls; //Excellence_Fee_Model_Fee::getFee();
        $balance = $fee - $exist_amount;

        $total->setTotalAmount('fee', $balance);
        $total->setBaseTotalAmount('fee', $balance);

        $total->setFee($balance);
        $total->setBaseFee($balance);

        $total->setGrandTotal($total->getGrandTotal() + $balance);
        $total->setBaseGrandTotal($total->getBaseGrandTotal() + $balance);


        return $this;
    } 

    protected function clearValues(Address\Total $total)
    {
        $total->setTotalAmount('subtotal', 0);
        $total->setBaseTotalAmount('subtotal', 0);
        $total->setTotalAmount('tax', 0);
        $total->setBaseTotalAmount('tax', 0);
        $total->setTotalAmount('discount_tax_compensation', 0);
        $total->setBaseTotalAmount('discount_tax_compensation', 0);
        $total->setTotalAmount('shipping_discount_tax_compensation', 0);
        $total->setBaseTotalAmount('shipping_discount_tax_compensation', 0);
        $total->setSubtotalInclTax(0);
        $total->setBaseSubtotalInclTax(0);
    }
    /**
     * @param \Magento\Quote\Model\Quote $quote
     * @param Address\Total $total
     * @return array|null
     */
    /**
     * Assign subtotal amount and label to address object
     *
     * @param \Magento\Quote\Model\Quote $quote
     * @param Address\Total $total
     * @return array
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */



    public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total)
    {



       global $total_cost;
       $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
$customerSession->setValue($total_cost); //set value in customer session
$vluas= $customerSession->getValue();

$this->vls = $vluas[0].$vluas[1];
//print_r($vls);

        return [
            'code' => 'fee',
            'title' => 'Shipping Price',
            'value' => $this->vls
        ];

    }

    /**
     * Get Subtotal label
     *
     * @return \Magento\Framework\Phrase
     */
    public function getLabel()
    {
        return __('Fee');
    }
}
1
  • Please check my answer and let me know Oct 7 '18 at 16:47
0

Add variable like this after this variable protected $quoteValidator = null;

protected $vls = null;

Then, use $vls variable like this : $this->vls;

For ex : $this->vls = $vluas[0].$vluas[1];

8
  • value show on first look or first time then it refresh to 0 :/ Oct 7 '18 at 17:23
  • Did you replace from $vls to $this->vls in whole file code? Oct 7 '18 at 17:28
  • yes code is working on first when page load then it refresh to 0 value value not stay :/ Oct 7 '18 at 17:31
  • Can you please update whole code after update variable ? Oct 7 '18 at 17:37
  • updated my code please have a look Oct 7 '18 at 17:39

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.