Question

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;  

}
Was it helpful?

Solution

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

    }
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top