How to get a list of all products in Magento 2?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
How can I get a list of all available products in Magento 2?
magento2 product
add a comment |
How can I get a list of all available products in Magento 2?
magento2 product
My answer hasn't helped you?
– Siarhey Uchukhlebau
Sep 9 '16 at 12:51
1
Mark now @SiarheyUchukhlebau answer as correct....
– P0lT10n
Mar 15 '17 at 14:28
add a comment |
How can I get a list of all available products in Magento 2?
magento2 product
How can I get a list of all available products in Magento 2?
magento2 product
magento2 product
asked Aug 5 '16 at 14:12
nuwausnuwaus
93432046
93432046
My answer hasn't helped you?
– Siarhey Uchukhlebau
Sep 9 '16 at 12:51
1
Mark now @SiarheyUchukhlebau answer as correct....
– P0lT10n
Mar 15 '17 at 14:28
add a comment |
My answer hasn't helped you?
– Siarhey Uchukhlebau
Sep 9 '16 at 12:51
1
Mark now @SiarheyUchukhlebau answer as correct....
– P0lT10n
Mar 15 '17 at 14:28
My answer hasn't helped you?
– Siarhey Uchukhlebau
Sep 9 '16 at 12:51
My answer hasn't helped you?
– Siarhey Uchukhlebau
Sep 9 '16 at 12:51
1
1
Mark now @SiarheyUchukhlebau answer as correct....
– P0lT10n
Mar 15 '17 at 14:28
Mark now @SiarheyUchukhlebau answer as correct....
– P0lT10n
Mar 15 '17 at 14:28
add a comment |
4 Answers
4
active
oldest
votes
You should use MagentoCatalogModelProductRepository
or MagentoCatalogModelResourceModelProductCollection
according your needs. You can use both methods to get product instances with all data.
Example 1 (Repository):
/**
* @param MagentoCatalogModelProductRepository $productRepository
* @param MagentoFrameworkApiSearchCriteriaInterface $criteria
* @param MagentoFrameworkApiSearchFilterGroup $filterGroup
* @param MagentoFrameworkApiFilterBuilder $filterBuilder
* @param MagentoCatalogModelProductAttributeSourceStatus $productStatus
* @param MagentoCatalogModelProductVisibility $productVisibility
*/
public function __construct(
MagentoCatalogModelProductRepository $productRepository,
MagentoFrameworkApiSearchCriteriaInterface $criteria,
MagentoFrameworkApiSearchFilterGroup $filterGroup,
MagentoFrameworkApiFilterBuilder $filterBuilder,
MagentoCatalogModelProductAttributeSourceStatus $productStatus,
MagentoCatalogModelProductVisibility $productVisibility
) {
$this->productRepository = $productRepository;
$this->searchCriteria = $criteria;
$this->filterGroup = $filterGroup;
$this->filterBuilder = $filterBuilder;
$this->productStatus = $productStatus;
$this->productVisibility = $productVisibility;
$this->getProductData();
}
/**
* @return MagentoCmsModelBlock|null
* @throws MagentoFrameworkExceptionNoSuchEntityException
*/
protected function getProductData()
{
$this->filterGroup->setFilters([
$this->filterBuilder
->setField('status')
->setConditionType('in')
->setValue($this->productStatus->getVisibleStatusIds())
->create(),
$this->filterBuilder
->setField('visibility')
->setConditionType('in')
->setValue($this->productVisibility->getVisibleInSiteIds())
->create(),
]);
$this->searchCriteria->setFilterGroups([$this->filterGroup]);
$products = $this->productRepository->getList($this->searchCriteria);
$productItems = $products->getItems();
return $productItems;
}
Result:
Example 2 (Collection):
/**
* @param MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory
* @param MagentoCatalogModelProductAttributeSourceStatus $productStatus
* @param MagentoCatalogModelProductVisibility $productVisibility
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function __construct(
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
MagentoCatalogModelProductAttributeSourceStatus $productStatus,
MagentoCatalogModelProductVisibility $productVisibility
) {
$this->productCollectionFactory = $productCollectionFactory;
$this->productStatus = $productStatus;
$this->productVisibility = $productVisibility;
}
/**
* @return MagentoFrameworkDataObject
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function getProducts()
{
/** @var MagentoCatalogModelResourceModelProductCollection $collection */
$collection = $this->productCollectionFactory->create();
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
$collection->addAttributeToFilter('status', ['in' => $this->productStatus->getVisibleStatusIds()])
->addAttributeToFilter('visibility', ['in' => $this->productVisibility->getVisibleInSiteIds()]);
return $collection->getItems();
}
Result:
hi @siarhey, I am getting an empty result with your code. Do you have any tips about it? Could it be because of I am trying to retrieve the list from a cron task?
– Lorenzo S
Feb 10 '17 at 11:22
@LorenzoS Hi, which example you are using 1 or 2? Does any product exist when you remove all filters/conditions?
– Siarhey Uchukhlebau
Feb 10 '17 at 11:36
How do get this "Variables" tab with objects tree in your screenshot ?
– maxagaz
May 15 '17 at 7:12
@maxagaz Using xDebug in PHPStorm
– Siarhey Uchukhlebau
May 15 '17 at 7:15
great answer, @SiarheyUchukhlebau but what do you mean by If you need just product data use the first class. If you need to get the product instances - use second class.
– Yehia A.Salam
May 31 '17 at 18:57
|
show 1 more comment
You can do this through api request. Take a look at the default m2 api
think your better shoot is catalogProductRepositoryV1
add a comment |
Using a REST API call:
https://{host}/rest/V1/products/?searchCriteria=
Retrieves all products. "searchCriteria" is a required param, but can be left blank, as above.
add a comment |
The most upvoted answer is working but I would like to mention that here by injecting a product repository implementation directly will cause the breach of service contract principle & that is something Magento wants developers to correct.
You should inject MagentoCatalogApiProductRepositoryInterface $productRepository
instead of it's implementation which is MagentoCatalogModelProductRepository $productRepository
.
That way you you will have a space for future upgrade ability. Bottom line is use Service contracts as much as possible.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f130185%2fhow-to-get-a-list-of-all-products-in-magento-2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You should use MagentoCatalogModelProductRepository
or MagentoCatalogModelResourceModelProductCollection
according your needs. You can use both methods to get product instances with all data.
Example 1 (Repository):
/**
* @param MagentoCatalogModelProductRepository $productRepository
* @param MagentoFrameworkApiSearchCriteriaInterface $criteria
* @param MagentoFrameworkApiSearchFilterGroup $filterGroup
* @param MagentoFrameworkApiFilterBuilder $filterBuilder
* @param MagentoCatalogModelProductAttributeSourceStatus $productStatus
* @param MagentoCatalogModelProductVisibility $productVisibility
*/
public function __construct(
MagentoCatalogModelProductRepository $productRepository,
MagentoFrameworkApiSearchCriteriaInterface $criteria,
MagentoFrameworkApiSearchFilterGroup $filterGroup,
MagentoFrameworkApiFilterBuilder $filterBuilder,
MagentoCatalogModelProductAttributeSourceStatus $productStatus,
MagentoCatalogModelProductVisibility $productVisibility
) {
$this->productRepository = $productRepository;
$this->searchCriteria = $criteria;
$this->filterGroup = $filterGroup;
$this->filterBuilder = $filterBuilder;
$this->productStatus = $productStatus;
$this->productVisibility = $productVisibility;
$this->getProductData();
}
/**
* @return MagentoCmsModelBlock|null
* @throws MagentoFrameworkExceptionNoSuchEntityException
*/
protected function getProductData()
{
$this->filterGroup->setFilters([
$this->filterBuilder
->setField('status')
->setConditionType('in')
->setValue($this->productStatus->getVisibleStatusIds())
->create(),
$this->filterBuilder
->setField('visibility')
->setConditionType('in')
->setValue($this->productVisibility->getVisibleInSiteIds())
->create(),
]);
$this->searchCriteria->setFilterGroups([$this->filterGroup]);
$products = $this->productRepository->getList($this->searchCriteria);
$productItems = $products->getItems();
return $productItems;
}
Result:
Example 2 (Collection):
/**
* @param MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory
* @param MagentoCatalogModelProductAttributeSourceStatus $productStatus
* @param MagentoCatalogModelProductVisibility $productVisibility
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function __construct(
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
MagentoCatalogModelProductAttributeSourceStatus $productStatus,
MagentoCatalogModelProductVisibility $productVisibility
) {
$this->productCollectionFactory = $productCollectionFactory;
$this->productStatus = $productStatus;
$this->productVisibility = $productVisibility;
}
/**
* @return MagentoFrameworkDataObject
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function getProducts()
{
/** @var MagentoCatalogModelResourceModelProductCollection $collection */
$collection = $this->productCollectionFactory->create();
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
$collection->addAttributeToFilter('status', ['in' => $this->productStatus->getVisibleStatusIds()])
->addAttributeToFilter('visibility', ['in' => $this->productVisibility->getVisibleInSiteIds()]);
return $collection->getItems();
}
Result:
hi @siarhey, I am getting an empty result with your code. Do you have any tips about it? Could it be because of I am trying to retrieve the list from a cron task?
– Lorenzo S
Feb 10 '17 at 11:22
@LorenzoS Hi, which example you are using 1 or 2? Does any product exist when you remove all filters/conditions?
– Siarhey Uchukhlebau
Feb 10 '17 at 11:36
How do get this "Variables" tab with objects tree in your screenshot ?
– maxagaz
May 15 '17 at 7:12
@maxagaz Using xDebug in PHPStorm
– Siarhey Uchukhlebau
May 15 '17 at 7:15
great answer, @SiarheyUchukhlebau but what do you mean by If you need just product data use the first class. If you need to get the product instances - use second class.
– Yehia A.Salam
May 31 '17 at 18:57
|
show 1 more comment
You should use MagentoCatalogModelProductRepository
or MagentoCatalogModelResourceModelProductCollection
according your needs. You can use both methods to get product instances with all data.
Example 1 (Repository):
/**
* @param MagentoCatalogModelProductRepository $productRepository
* @param MagentoFrameworkApiSearchCriteriaInterface $criteria
* @param MagentoFrameworkApiSearchFilterGroup $filterGroup
* @param MagentoFrameworkApiFilterBuilder $filterBuilder
* @param MagentoCatalogModelProductAttributeSourceStatus $productStatus
* @param MagentoCatalogModelProductVisibility $productVisibility
*/
public function __construct(
MagentoCatalogModelProductRepository $productRepository,
MagentoFrameworkApiSearchCriteriaInterface $criteria,
MagentoFrameworkApiSearchFilterGroup $filterGroup,
MagentoFrameworkApiFilterBuilder $filterBuilder,
MagentoCatalogModelProductAttributeSourceStatus $productStatus,
MagentoCatalogModelProductVisibility $productVisibility
) {
$this->productRepository = $productRepository;
$this->searchCriteria = $criteria;
$this->filterGroup = $filterGroup;
$this->filterBuilder = $filterBuilder;
$this->productStatus = $productStatus;
$this->productVisibility = $productVisibility;
$this->getProductData();
}
/**
* @return MagentoCmsModelBlock|null
* @throws MagentoFrameworkExceptionNoSuchEntityException
*/
protected function getProductData()
{
$this->filterGroup->setFilters([
$this->filterBuilder
->setField('status')
->setConditionType('in')
->setValue($this->productStatus->getVisibleStatusIds())
->create(),
$this->filterBuilder
->setField('visibility')
->setConditionType('in')
->setValue($this->productVisibility->getVisibleInSiteIds())
->create(),
]);
$this->searchCriteria->setFilterGroups([$this->filterGroup]);
$products = $this->productRepository->getList($this->searchCriteria);
$productItems = $products->getItems();
return $productItems;
}
Result:
Example 2 (Collection):
/**
* @param MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory
* @param MagentoCatalogModelProductAttributeSourceStatus $productStatus
* @param MagentoCatalogModelProductVisibility $productVisibility
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function __construct(
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
MagentoCatalogModelProductAttributeSourceStatus $productStatus,
MagentoCatalogModelProductVisibility $productVisibility
) {
$this->productCollectionFactory = $productCollectionFactory;
$this->productStatus = $productStatus;
$this->productVisibility = $productVisibility;
}
/**
* @return MagentoFrameworkDataObject
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function getProducts()
{
/** @var MagentoCatalogModelResourceModelProductCollection $collection */
$collection = $this->productCollectionFactory->create();
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
$collection->addAttributeToFilter('status', ['in' => $this->productStatus->getVisibleStatusIds()])
->addAttributeToFilter('visibility', ['in' => $this->productVisibility->getVisibleInSiteIds()]);
return $collection->getItems();
}
Result:
hi @siarhey, I am getting an empty result with your code. Do you have any tips about it? Could it be because of I am trying to retrieve the list from a cron task?
– Lorenzo S
Feb 10 '17 at 11:22
@LorenzoS Hi, which example you are using 1 or 2? Does any product exist when you remove all filters/conditions?
– Siarhey Uchukhlebau
Feb 10 '17 at 11:36
How do get this "Variables" tab with objects tree in your screenshot ?
– maxagaz
May 15 '17 at 7:12
@maxagaz Using xDebug in PHPStorm
– Siarhey Uchukhlebau
May 15 '17 at 7:15
great answer, @SiarheyUchukhlebau but what do you mean by If you need just product data use the first class. If you need to get the product instances - use second class.
– Yehia A.Salam
May 31 '17 at 18:57
|
show 1 more comment
You should use MagentoCatalogModelProductRepository
or MagentoCatalogModelResourceModelProductCollection
according your needs. You can use both methods to get product instances with all data.
Example 1 (Repository):
/**
* @param MagentoCatalogModelProductRepository $productRepository
* @param MagentoFrameworkApiSearchCriteriaInterface $criteria
* @param MagentoFrameworkApiSearchFilterGroup $filterGroup
* @param MagentoFrameworkApiFilterBuilder $filterBuilder
* @param MagentoCatalogModelProductAttributeSourceStatus $productStatus
* @param MagentoCatalogModelProductVisibility $productVisibility
*/
public function __construct(
MagentoCatalogModelProductRepository $productRepository,
MagentoFrameworkApiSearchCriteriaInterface $criteria,
MagentoFrameworkApiSearchFilterGroup $filterGroup,
MagentoFrameworkApiFilterBuilder $filterBuilder,
MagentoCatalogModelProductAttributeSourceStatus $productStatus,
MagentoCatalogModelProductVisibility $productVisibility
) {
$this->productRepository = $productRepository;
$this->searchCriteria = $criteria;
$this->filterGroup = $filterGroup;
$this->filterBuilder = $filterBuilder;
$this->productStatus = $productStatus;
$this->productVisibility = $productVisibility;
$this->getProductData();
}
/**
* @return MagentoCmsModelBlock|null
* @throws MagentoFrameworkExceptionNoSuchEntityException
*/
protected function getProductData()
{
$this->filterGroup->setFilters([
$this->filterBuilder
->setField('status')
->setConditionType('in')
->setValue($this->productStatus->getVisibleStatusIds())
->create(),
$this->filterBuilder
->setField('visibility')
->setConditionType('in')
->setValue($this->productVisibility->getVisibleInSiteIds())
->create(),
]);
$this->searchCriteria->setFilterGroups([$this->filterGroup]);
$products = $this->productRepository->getList($this->searchCriteria);
$productItems = $products->getItems();
return $productItems;
}
Result:
Example 2 (Collection):
/**
* @param MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory
* @param MagentoCatalogModelProductAttributeSourceStatus $productStatus
* @param MagentoCatalogModelProductVisibility $productVisibility
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function __construct(
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
MagentoCatalogModelProductAttributeSourceStatus $productStatus,
MagentoCatalogModelProductVisibility $productVisibility
) {
$this->productCollectionFactory = $productCollectionFactory;
$this->productStatus = $productStatus;
$this->productVisibility = $productVisibility;
}
/**
* @return MagentoFrameworkDataObject
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function getProducts()
{
/** @var MagentoCatalogModelResourceModelProductCollection $collection */
$collection = $this->productCollectionFactory->create();
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
$collection->addAttributeToFilter('status', ['in' => $this->productStatus->getVisibleStatusIds()])
->addAttributeToFilter('visibility', ['in' => $this->productVisibility->getVisibleInSiteIds()]);
return $collection->getItems();
}
Result:
You should use MagentoCatalogModelProductRepository
or MagentoCatalogModelResourceModelProductCollection
according your needs. You can use both methods to get product instances with all data.
Example 1 (Repository):
/**
* @param MagentoCatalogModelProductRepository $productRepository
* @param MagentoFrameworkApiSearchCriteriaInterface $criteria
* @param MagentoFrameworkApiSearchFilterGroup $filterGroup
* @param MagentoFrameworkApiFilterBuilder $filterBuilder
* @param MagentoCatalogModelProductAttributeSourceStatus $productStatus
* @param MagentoCatalogModelProductVisibility $productVisibility
*/
public function __construct(
MagentoCatalogModelProductRepository $productRepository,
MagentoFrameworkApiSearchCriteriaInterface $criteria,
MagentoFrameworkApiSearchFilterGroup $filterGroup,
MagentoFrameworkApiFilterBuilder $filterBuilder,
MagentoCatalogModelProductAttributeSourceStatus $productStatus,
MagentoCatalogModelProductVisibility $productVisibility
) {
$this->productRepository = $productRepository;
$this->searchCriteria = $criteria;
$this->filterGroup = $filterGroup;
$this->filterBuilder = $filterBuilder;
$this->productStatus = $productStatus;
$this->productVisibility = $productVisibility;
$this->getProductData();
}
/**
* @return MagentoCmsModelBlock|null
* @throws MagentoFrameworkExceptionNoSuchEntityException
*/
protected function getProductData()
{
$this->filterGroup->setFilters([
$this->filterBuilder
->setField('status')
->setConditionType('in')
->setValue($this->productStatus->getVisibleStatusIds())
->create(),
$this->filterBuilder
->setField('visibility')
->setConditionType('in')
->setValue($this->productVisibility->getVisibleInSiteIds())
->create(),
]);
$this->searchCriteria->setFilterGroups([$this->filterGroup]);
$products = $this->productRepository->getList($this->searchCriteria);
$productItems = $products->getItems();
return $productItems;
}
Result:
Example 2 (Collection):
/**
* @param MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory
* @param MagentoCatalogModelProductAttributeSourceStatus $productStatus
* @param MagentoCatalogModelProductVisibility $productVisibility
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function __construct(
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
MagentoCatalogModelProductAttributeSourceStatus $productStatus,
MagentoCatalogModelProductVisibility $productVisibility
) {
$this->productCollectionFactory = $productCollectionFactory;
$this->productStatus = $productStatus;
$this->productVisibility = $productVisibility;
}
/**
* @return MagentoFrameworkDataObject
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function getProducts()
{
/** @var MagentoCatalogModelResourceModelProductCollection $collection */
$collection = $this->productCollectionFactory->create();
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
$collection->addAttributeToFilter('status', ['in' => $this->productStatus->getVisibleStatusIds()])
->addAttributeToFilter('visibility', ['in' => $this->productVisibility->getVisibleInSiteIds()]);
return $collection->getItems();
}
Result:
edited Jun 1 '17 at 8:40
answered Aug 5 '16 at 14:53
Siarhey UchukhlebauSiarhey Uchukhlebau
10k93058
10k93058
hi @siarhey, I am getting an empty result with your code. Do you have any tips about it? Could it be because of I am trying to retrieve the list from a cron task?
– Lorenzo S
Feb 10 '17 at 11:22
@LorenzoS Hi, which example you are using 1 or 2? Does any product exist when you remove all filters/conditions?
– Siarhey Uchukhlebau
Feb 10 '17 at 11:36
How do get this "Variables" tab with objects tree in your screenshot ?
– maxagaz
May 15 '17 at 7:12
@maxagaz Using xDebug in PHPStorm
– Siarhey Uchukhlebau
May 15 '17 at 7:15
great answer, @SiarheyUchukhlebau but what do you mean by If you need just product data use the first class. If you need to get the product instances - use second class.
– Yehia A.Salam
May 31 '17 at 18:57
|
show 1 more comment
hi @siarhey, I am getting an empty result with your code. Do you have any tips about it? Could it be because of I am trying to retrieve the list from a cron task?
– Lorenzo S
Feb 10 '17 at 11:22
@LorenzoS Hi, which example you are using 1 or 2? Does any product exist when you remove all filters/conditions?
– Siarhey Uchukhlebau
Feb 10 '17 at 11:36
How do get this "Variables" tab with objects tree in your screenshot ?
– maxagaz
May 15 '17 at 7:12
@maxagaz Using xDebug in PHPStorm
– Siarhey Uchukhlebau
May 15 '17 at 7:15
great answer, @SiarheyUchukhlebau but what do you mean by If you need just product data use the first class. If you need to get the product instances - use second class.
– Yehia A.Salam
May 31 '17 at 18:57
hi @siarhey, I am getting an empty result with your code. Do you have any tips about it? Could it be because of I am trying to retrieve the list from a cron task?
– Lorenzo S
Feb 10 '17 at 11:22
hi @siarhey, I am getting an empty result with your code. Do you have any tips about it? Could it be because of I am trying to retrieve the list from a cron task?
– Lorenzo S
Feb 10 '17 at 11:22
@LorenzoS Hi, which example you are using 1 or 2? Does any product exist when you remove all filters/conditions?
– Siarhey Uchukhlebau
Feb 10 '17 at 11:36
@LorenzoS Hi, which example you are using 1 or 2? Does any product exist when you remove all filters/conditions?
– Siarhey Uchukhlebau
Feb 10 '17 at 11:36
How do get this "Variables" tab with objects tree in your screenshot ?
– maxagaz
May 15 '17 at 7:12
How do get this "Variables" tab with objects tree in your screenshot ?
– maxagaz
May 15 '17 at 7:12
@maxagaz Using xDebug in PHPStorm
– Siarhey Uchukhlebau
May 15 '17 at 7:15
@maxagaz Using xDebug in PHPStorm
– Siarhey Uchukhlebau
May 15 '17 at 7:15
great answer, @SiarheyUchukhlebau but what do you mean by If you need just product data use the first class. If you need to get the product instances - use second class.
– Yehia A.Salam
May 31 '17 at 18:57
great answer, @SiarheyUchukhlebau but what do you mean by If you need just product data use the first class. If you need to get the product instances - use second class.
– Yehia A.Salam
May 31 '17 at 18:57
|
show 1 more comment
You can do this through api request. Take a look at the default m2 api
think your better shoot is catalogProductRepositoryV1
add a comment |
You can do this through api request. Take a look at the default m2 api
think your better shoot is catalogProductRepositoryV1
add a comment |
You can do this through api request. Take a look at the default m2 api
think your better shoot is catalogProductRepositoryV1
You can do this through api request. Take a look at the default m2 api
think your better shoot is catalogProductRepositoryV1
edited Aug 5 '16 at 16:14
answered Aug 5 '16 at 14:32
9562395623
1545
1545
add a comment |
add a comment |
Using a REST API call:
https://{host}/rest/V1/products/?searchCriteria=
Retrieves all products. "searchCriteria" is a required param, but can be left blank, as above.
add a comment |
Using a REST API call:
https://{host}/rest/V1/products/?searchCriteria=
Retrieves all products. "searchCriteria" is a required param, but can be left blank, as above.
add a comment |
Using a REST API call:
https://{host}/rest/V1/products/?searchCriteria=
Retrieves all products. "searchCriteria" is a required param, but can be left blank, as above.
Using a REST API call:
https://{host}/rest/V1/products/?searchCriteria=
Retrieves all products. "searchCriteria" is a required param, but can be left blank, as above.
answered Apr 3 '18 at 19:10
JamezJamez
1
1
add a comment |
add a comment |
The most upvoted answer is working but I would like to mention that here by injecting a product repository implementation directly will cause the breach of service contract principle & that is something Magento wants developers to correct.
You should inject MagentoCatalogApiProductRepositoryInterface $productRepository
instead of it's implementation which is MagentoCatalogModelProductRepository $productRepository
.
That way you you will have a space for future upgrade ability. Bottom line is use Service contracts as much as possible.
add a comment |
The most upvoted answer is working but I would like to mention that here by injecting a product repository implementation directly will cause the breach of service contract principle & that is something Magento wants developers to correct.
You should inject MagentoCatalogApiProductRepositoryInterface $productRepository
instead of it's implementation which is MagentoCatalogModelProductRepository $productRepository
.
That way you you will have a space for future upgrade ability. Bottom line is use Service contracts as much as possible.
add a comment |
The most upvoted answer is working but I would like to mention that here by injecting a product repository implementation directly will cause the breach of service contract principle & that is something Magento wants developers to correct.
You should inject MagentoCatalogApiProductRepositoryInterface $productRepository
instead of it's implementation which is MagentoCatalogModelProductRepository $productRepository
.
That way you you will have a space for future upgrade ability. Bottom line is use Service contracts as much as possible.
The most upvoted answer is working but I would like to mention that here by injecting a product repository implementation directly will cause the breach of service contract principle & that is something Magento wants developers to correct.
You should inject MagentoCatalogApiProductRepositoryInterface $productRepository
instead of it's implementation which is MagentoCatalogModelProductRepository $productRepository
.
That way you you will have a space for future upgrade ability. Bottom line is use Service contracts as much as possible.
edited 2 days ago
answered 2 days ago
SarvagyaSarvagya
77521638
77521638
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f130185%2fhow-to-get-a-list-of-all-products-in-magento-2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
My answer hasn't helped you?
– Siarhey Uchukhlebau
Sep 9 '16 at 12:51
1
Mark now @SiarheyUchukhlebau answer as correct....
– P0lT10n
Mar 15 '17 at 14:28