分类
服务器

magento筛选查询列表

    /**
     * @var SearchCriteriaBuilder
     */
    private $searchCriteriaBuilder;

    /**
     * @var SourceItemRepositoryInterface
     */
    private $sourceItemRepository;


    /**
     * @var LoggerInterface
     */
    private $logger;

    public function __construct(
        SearchCriteriaBuilder $searchCriteriaBuilder,
        SourceItemRepositoryInterface $sourceItemRepository,
        LoggerInterface $logger
    ) {
        $this->searchCriteriaBuilder = $searchCriteriaBuilder;
        $this->sourceItemRepository = $sourceItemRepository;
        $this->logger = $logger;
    }


    public function execute()
{
        echo $sku;
        try {
            $searchCriteria = $this->searchCriteriaBuilder
                ->addFilter(SourceItemInterface::SKU, $sku)->addFilter(SourceItemInterface::SOURCE_CODE,$source_code)
                ->create();
            $items = $this->sourceItemRepository->getList($searchCriteria)->getItems();

            echo '<pre>';
            foreach ($items as $value) {
                var_dump($value->getData());
            }

            die('没有数据');

        } catch (\Exception $e) {
            $this->logger->error($e->getMessage());
        }
        return $this;
}