1

I use an observer checkout_cart_update_items_after to update the price of a product.In Vendor\Module\Observer\PriceRule\UpdateObserver my observer code resides.In this class I need to use ScopeConfigInterface. But when I declare it in the constructor like this--

 public function __construct(
    Session $session,

    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
) {
    $this->scopeConfig = $scopeConfig;
    $this->customerFactory = $customerFactory;

My observer stop working.But when I remove this two line--

\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
$this->scopeConfig = $scopeConfig;

it works fine.But I need to use scope config to implement my logic. Please help me in this regard.

2

clear contents of generated/code, or if you have compilation enabled, either disable it by removing the contents of generated/metadata or compile again with php bin/magento setup:di:compile.

2

Try to flush the cache, if still not work then just remove "var/generation" and it will work

public function __construct(Context $context, PageFactory $pageFactory, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
{
  $this->pageFactory = $pageFactory;
  $this->scopeConfig = $scopeConfig;
  return parent::__construct($context);
}

Oh, i got it, you miss this in your contruct, see below

public function __construct(
    ...
    \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerFactory
    ...
) {
  • ok I am trying this . – Magento Learner Aug 31 '18 at 10:53
  • Hi @john,It is not working. – Magento Learner Aug 31 '18 at 10:59
  • see my updated answer – John Aug 31 '18 at 11:03

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.