0

Please anyone review my code. Facing this error. Exception #0 (ReflectionException): Class Sugarcode\Test\Model\ResourceModel\Test\RewardspointsFactory does not exist Exception #1 (ReflectionException): Class Sugarcode\Test\Model\ResourceModel\Test\RewardspointsFactory does not exist

<?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 $quoteValidator = null;

    protected $rewardspointCollectionFactory;

    public function __construct(
            \Magento\Quote\Model\QuoteValidator $quoteValidator,
            \Sugarcode\Test\Model\ResourceModel\Test\RewardspointsFactory $rewardspointCollectionFactory
            ) {
        $this->quoteValidator = $quoteValidator;
        $this->rewardspointCollectionFactory = $rewardspointCollectionFactory;
    }

    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);


        $exist_amount = 0; //$quote->getFee(); 
        $fee = 200; //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) {


        $rewardspointCollection = $this->rewardspointCollectionFactory->create();
        $customerId = $quote->getCustomerId();
        $rewardspointCollection->addFieldToSelect('*')
                ->addFieldToFilter('dukaaniatest_id',$customerId);
        if(count($rewardspointCollection) > 0){
           $firstItem =  $rewardspointCollection->geFirstItem();
           return [
            'code' => 'fee',
            'title' => $firstItem->getData('title'),
            'value' => $firstItem->getData('author')
        ];
        }else{
            return [
            'code' => 'fee',
            'title' => 'Fee',
            'value' => 0
        ];
        }



    }

    /**
     * Get Subtotal label
     *
     * @return \Magento\Framework\Phrase
     */
    public function getLabel() {
        return __('Fee');
    }

}
5
  • Make sure you are calling the right file and your naming conversion is proper. As per magento standard there should be collection.php in the path you have mentioned i.e Sugarcode\Test\Model\ResourceModel\Test\CollectionFactory
    – Priyank
    Oct 1, 2018 at 10:41
  • /home1/dukaania/public_html/testing2/app/code/Sugarcode/Test/Model/ResourceModel/Fee/Collection.php so the path i set is \Sugarcode\Test\Model\ResourceModel\Test\Model\ResourceModel\Fee\CollectionFactory $rewardspointCollectionFactory Oct 1, 2018 at 10:43
  • As per your comment you should change your injected class from \Sugarcode\Test\Model\ResourceModel\Test\RewardspointsFactory to \Sugarcode\Test\Model\ResourceModel\Fee\CollectionFactory
    – Priyank
    Oct 1, 2018 at 11:25
  • the code is run but it shows a blank page and just Estimate Shipping and Tax written on that Oct 1, 2018 at 11:26
  • Try clearing your generated and cache. If still not getting enable log or error reporting to find the error
    – Priyank
    Oct 1, 2018 at 13:44

1 Answer 1

0

please clear your generation folder and check. Another process is to run bin/magento setup:di:compile command

26
  • I run the command as well but nothing happen error show on screen RewardspointsFactory does not exist Oct 1, 2018 at 10:40
  • Looking at the path that you have called in your __construct, i doubt that file exists, Test folder is generally reserved for the testing framework. Oct 1, 2018 at 10:43
  • 1
    I see error in your checkout page: Cannot declare class Sugarcode\Test\Model\ResourceModel\Test\Collection, because the name is already in use in <b>/home/dukaania/public_html/testing2/app/code/Sugarcode/Test/Model/ResourceModel/Fee/Collection.php</b> on line <b>16</b><br /> . Please fix it. Oct 1, 2018 at 11:44
  • 1
    I saw your cart view source page and at the end of the page there was that error message. Oct 1, 2018 at 11:48
  • 1
    You have to debug your namespace declaration and class name declaration, it should go to exact path. Oct 1, 2018 at 12:06

Your Answer

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

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