1
public function execute()
{   

    $yourDate = date('2019-11-17');
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $collection = $objectManager->get('Magento\Sales\Model\ResourceModel\Order\Creditmemo\Collection');
    $collection->addFieldToFilter('created_at', array('gt' => $yourDate));

    foreach ($collection as $creditmemo):
    $data = $creditmemo->getData();
    $this->createNewCreditMemoHead($data);
    endforeach;  

}
0

I have checked with test order and credit memo with multiple items it's working for me. Please try this.

$yourDate = date('2019-11-21');
    $creditMemoFacory = $objectManager->create('Magento\Sales\Api\CreditmemoRepositoryInterface');

    $searchCriteria = $objectManager->create('Magento\Framework\Api\SearchCriteriaBuilder');
    $searchCriteria = $searchCriteria->addFilter(
        'created_at',
        $yourDate,
        'gt'
    )->create();
    $creditmemos = $creditMemoFacory
    ->getList($searchCriteria)
    ->getItems();
    foreach($creditmemos as $creditMemo){
        foreach($creditMemo->getAllItems() as $items){
            echo "<pre>"; print_r($items->getData());
        }

    }
  • Fatal error: Uncaught Error: Call to undefined method Magento\Sales\Model\Order\CreditmemoRepository::addFieldToFilter() in D:\dev.magento\app\code\Learning\HelloPage\Controller\Page\View.php:201 Stack trace: #0 – Manu Nov 18 '19 at 8:32
  • sir actually i want all the items from credit memo – Manu Nov 18 '19 at 8:34
  • Please check with above code. – Jaydeep Charadva Nov 21 '19 at 5:41

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.