0

I have created a class in module as im working on discount module.

class Custom extends \Magento\Quote\Model\Quote\Address\Total\AbstractTotal
{
    protected $_priceCurrency;

    public function __construct(
        \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
    ) {
        $this->_priceCurrency = $priceCurrency;
    }

    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);
        $baseDiscount = 10;
        $discount = $this->_priceCurrency->convert($baseDiscount);
        $total->addTotalAmount('customdiscount', $discount);
        $total->addBaseTotalAmount('customdiscount', $baseDiscount);
        $total->setBaseGrandTotal($total->getBaseGrandTotal() - $baseDiscount);
        $quote->setCustomDiscount($discount);

        return $this;
    }
}

I'm getting an error like

syntax error, unexpected ' protected' (T_STRING), expecting function (T_FUNCTION) in C:\xampp1\htdocs\Magento\app\code\Discout\Mode\Model\Quote\Custom.php on line 6

5
  • plz show your full file with code Aug 29, 2016 at 6:27
  • Have you working below answer? Aug 29, 2016 at 7:35
  • no i didnt get any answer still im facing error Aug 29, 2016 at 9:36
  • You clear your Magento Cache and delete var/generation folder? Aug 29, 2016 at 15:07
  • yes deleted but still its not working....removed space and everything but unable to find the problem Aug 30, 2016 at 14:06

1 Answer 1

0

you have spacing issue before extend\Magento to extend \Magento,

please keep below code and test,

  class Custom extends \Magento\Quote\Model\Quote\Address\Total\AbstractTotal
  {
      protected $_priceCurrency;
      public function __construct (
            \Magento\Framework\Pricing\PriceCurrencyInterface   $priceCurrency   
          )
       {
          $this->_priceCurrency = $priceCurrency;
       }        

       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);
        $baseDiscount = 10;
       $discount =  $this->_priceCurrency->convert($baseDiscount);
       $total->addTotalAmount('customdiscount', $discount);
       $total->addBaseTotalAmount('customdiscount', $baseDiscount);
       $total->setBaseGrandTotal($total->getBaseGrandTotal() - $baseDiscount);
       $quote->setCustomDiscount($discount);
        return $this;
       }
   }
5
  • hi i did but still some error for function now as it was giving for protected...... Aug 27, 2016 at 12:31
  • Plz show whole file of your code Aug 27, 2016 at 12:33
  • Your collect function are not complted you have to define body Aug 27, 2016 at 12:46
  • hi rakesh i left only this function in class { parent::collect($quote, $shippingAssignment, $total); $baseDiscount = 10; $discount = ;//$this->_priceCurrency->convert($baseDiscount); $total->addTotalAmount('customdiscount', $discount); $total->addBaseTotalAmount('customdiscount', $baseDiscount); $total->setBaseGrandTotal($total->getBaseGrandTotal() - $baseDiscount); $quote->setCustomDiscount($discount); return $this; } Aug 29, 2016 at 6:08
  • updated full code Aug 29, 2016 at 7:12

Your Answer

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

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