0

I have some weird problem

Here is my code that write in afterGetPrice() function, I am using plugin here to change price of product based on my custom table

$customPrice = $this->_customPriceFactory->addFieldToFilter('entity_id',$product->getId())->getData();

echo $product->getId();

echo rand();

print_r($customPrice);

on search page and Listing I got the same result every time Here is image

enter image description here

2
  • If you are trying to into phtml file then it will not work, you need to override ListProduct.php file. Commented Oct 28, 2017 at 18:37
  • You need to create getfinalprice plugin Commented Oct 29, 2017 at 5:53

1 Answer 1

3

You need to try create() method.

create() method creates new object every time when it's call.

$customPrice = $this->_customPriceFactory->create();
$customPrice = $customPrice->addFieldToFilter('entity_id',$product->getId())->getData();

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.