On this weblog, we’re going to learn to use PrestaShopCollection element in PrestaShop whereas creating module.
PrestaShop have a PrestaShopCollection class which is a set of ObjectModel objects, which implements widespread helpful interfaces obtainable in PHP reminiscent of Iterator, ArrayAccess and Countable.
use PrestaShopCollection; $idLang = 1; $productCollection = new PrestaShopCollection('Product', $idLang); $guidelines = new PrestaShopCollection('SpecificPriceRule');
A number of the instance makes use of of assortment
Becoming a member of related entities
- Be part of
producer
to yourProduct
assortment - Class becoming a member of and many others
$productCollection = new PrestaShopCollection('Product'); $productCollection->be a part of('producer'); $productCollection = new PrestaShopCollection('Product'); $productCollection->be a part of('classes', 'id_category'); $productCollection->be a part of('classes', 'id_category', PrestaShopCollection::LEFT_JOIN); $productCollection->be a part of('classes', 'id_category', PrestaShopCollection::INNER_JOIN); $productCollection->be a part of('classes', 'id_category', PrestaShopCollection::LEFT_OUTER_JOIN); $productCollection = (new PrestaShopCollection('Product')) ->be a part of('producer') ->the place('producer.identify', '=', 'Producer AAA');
Ordering a Assortment
Assortment might be ordered in ascending or descending order, with asc
or desc
within the $order
parameter. To order assortment, use the orderBy()
methodology as proven beneath
$productCollection = (new PrestaShopCollection('Product')) ->orderBy('reference', 'desc');
Grouping
Assortment might be grouped primarily based on a selected discipline, by utilizing groupBy()
methodology as proven beneath
$productCollection = (new PrestaShopCollection('Product')) ->groupBy('id_supplier');
Paginating a Assortment
For retrieving numerous objects, it’s needed to make use of pagination strategies reminiscent of SQL’s OFFSET/LIMIT. It will assist in managing assortment extra effectively.
$productCollection = (new PrestaShopCollection('Product')) ->setPageSize(100) // will get solely 100 objects ->setPageNumber(2); // however from web page 2
Filtering a Assortment
When constructing the Assortment, it’s possible you’ll must filter its content material. To take action, use the the place()
methodology.
$productCollection = new PrestaShopCollection('Product'); $productCollection->the place('on_sale', '=', true); $productCollection = new PrestaShopCollection('Product'); $productCollection->the place('reference', 'LIKE', 'REF-%'); // discover merchandise with reference starting by "REF-"
Having
methodology
There may be additionally having()
methodology obtainable, which calls the place()
with the parameter $methodology
set to having
.
public operate having($discipline, $operator, $worth)
You need to use any PrestaShop object equally as above instance to fetch, show and manipulate.
That’s all about PrestaShopCollection element class in PrestaShop. Hope it can make it easier to.
Concluding this weblog, I hope it proves useful to you. For those who encounter any points or have doubts concerning the aforementioned course of, please don’t hesitate to contact us via the remark part.
Additionally, you’ll be able to discover our PrestaShop Growth Companies and a wide variety of high quality PrestaShop Modules.
For any doubt contact us at [email protected]
On this weblog, we’re going to learn to use PrestaShopCollection element in PrestaShop whereas creating module.
PrestaShop have a PrestaShopCollection class which is a set of ObjectModel objects, which implements widespread helpful interfaces obtainable in PHP reminiscent of Iterator, ArrayAccess and Countable.
use PrestaShopCollection; $idLang = 1; $productCollection = new PrestaShopCollection('Product', $idLang); $guidelines = new PrestaShopCollection('SpecificPriceRule');
A number of the instance makes use of of assortment
Becoming a member of related entities
- Be part of
producer
to yourProduct
assortment - Class becoming a member of and many others
$productCollection = new PrestaShopCollection('Product'); $productCollection->be a part of('producer'); $productCollection = new PrestaShopCollection('Product'); $productCollection->be a part of('classes', 'id_category'); $productCollection->be a part of('classes', 'id_category', PrestaShopCollection::LEFT_JOIN); $productCollection->be a part of('classes', 'id_category', PrestaShopCollection::INNER_JOIN); $productCollection->be a part of('classes', 'id_category', PrestaShopCollection::LEFT_OUTER_JOIN); $productCollection = (new PrestaShopCollection('Product')) ->be a part of('producer') ->the place('producer.identify', '=', 'Producer AAA');
Ordering a Assortment
Assortment might be ordered in ascending or descending order, with asc
or desc
within the $order
parameter. To order assortment, use the orderBy()
methodology as proven beneath
$productCollection = (new PrestaShopCollection('Product')) ->orderBy('reference', 'desc');
Grouping
Assortment might be grouped primarily based on a selected discipline, by utilizing groupBy()
methodology as proven beneath
$productCollection = (new PrestaShopCollection('Product')) ->groupBy('id_supplier');
Paginating a Assortment
For retrieving numerous objects, it’s needed to make use of pagination strategies reminiscent of SQL’s OFFSET/LIMIT. It will assist in managing assortment extra effectively.
$productCollection = (new PrestaShopCollection('Product')) ->setPageSize(100) // will get solely 100 objects ->setPageNumber(2); // however from web page 2
Filtering a Assortment
When constructing the Assortment, it’s possible you’ll must filter its content material. To take action, use the the place()
methodology.
$productCollection = new PrestaShopCollection('Product'); $productCollection->the place('on_sale', '=', true); $productCollection = new PrestaShopCollection('Product'); $productCollection->the place('reference', 'LIKE', 'REF-%'); // discover merchandise with reference starting by "REF-"
Having
methodology
There may be additionally having()
methodology obtainable, which calls the place()
with the parameter $methodology
set to having
.
public operate having($discipline, $operator, $worth)
You need to use any PrestaShop object equally as above instance to fetch, show and manipulate.
That’s all about PrestaShopCollection element class in PrestaShop. Hope it can make it easier to.
Concluding this weblog, I hope it proves useful to you. For those who encounter any points or have doubts concerning the aforementioned course of, please don’t hesitate to contact us via the remark part.
Additionally, you’ll be able to discover our PrestaShop Growth Companies and a wide variety of high quality PrestaShop Modules.
For any doubt contact us at [email protected]