Skip to main content
deleted 446 characters in body
Source Link

Try this,

Inject this in your constructor

<?php                                                         
namespace Vendor\Module\Controller\Orders;                       
class SetOrders extends \Magento\Framework\App\Action\Action
{
protected $resultPageFactory;
protected $itemFactory;
public function __construct(
 \Magento\Sales\Model\Order\ItemFactory $itemFactory,
 \Magento\Framework\App\Action\Context $context,
 \Magento\Framework\View\Result\PageFactory $resultPageFactory
) {

and add this in your constructor

 $this->itemFactory = $itemFactory;
 $this->resultPageFactory = $resultPageFactory;
 parent::__construct($context);
}

then you can apply filter like this anywhere in your function and in your case it would be like

public function executegetAllItems()   
{
 try {
    $current_seller_id = 5;
    $order = $this->itemFactory->create()->getCollection()->addFieldToFilter('current_seller_id', $current_seller_id);
    foreach ($order as $items) {
       echo $itemId =  $items->getItemId();
    }
    echo "success";
} catch (\Exception $e) {
    error_log($e->getMessage());
}
}
}

this is how you can add filter by your attribute.

Hope this helps :)

Try this

<?php                                                         
namespace Vendor\Module\Controller\Orders;                       
class SetOrders extends \Magento\Framework\App\Action\Action
{
protected $resultPageFactory;
protected $itemFactory;
public function __construct(
 \Magento\Sales\Model\Order\ItemFactory $itemFactory,
 \Magento\Framework\App\Action\Context $context,
 \Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
 $this->itemFactory = $itemFactory;
 $this->resultPageFactory = $resultPageFactory;
 parent::__construct($context);
}
public function execute()   
{
 try {
    $current_seller_id = 5;
    $order = $this->itemFactory->create()->getCollection()->addFieldToFilter('current_seller_id', $current_seller_id);
    foreach ($order as $items) {
       echo $itemId =  $items->getItemId();
    }
    echo "success";
} catch (\Exception $e) {
    error_log($e->getMessage());
}
}
}

Hope this helps :)

Try this,

Inject this in your constructor

 \Magento\Sales\Model\Order\ItemFactory $itemFactory

and add this in your constructor

 $this->itemFactory = $itemFactory;

then you can apply filter like this anywhere in your function and in your case it would be like

public function getAllItems()
{
    $current_seller_id = 5;
    $order = $this->itemFactory->create()->getCollection()->addFieldToFilter('current_seller_id', $current_seller_id);
    foreach ($order as $items) {
      echo $itemId =  $items->getItemId();
    }
}

this is how you can add filter by your attribute.

Hope this helps :)

Source Link

Try this

<?php                                                         
namespace Vendor\Module\Controller\Orders;                       
class SetOrders extends \Magento\Framework\App\Action\Action
{
protected $resultPageFactory;
protected $itemFactory;
public function __construct(
 \Magento\Sales\Model\Order\ItemFactory $itemFactory,
 \Magento\Framework\App\Action\Context $context,
 \Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
 $this->itemFactory = $itemFactory;
 $this->resultPageFactory = $resultPageFactory;
 parent::__construct($context);
}
public function execute()   
{
 try {
    $current_seller_id = 5;
    $order = $this->itemFactory->create()->getCollection()->addFieldToFilter('current_seller_id', $current_seller_id);
    foreach ($order as $items) {
       echo $itemId =  $items->getItemId();
    }
    echo "success";
} catch (\Exception $e) {
    error_log($e->getMessage());
}
}
}

Hope this helps :)