Magento SOAP API Product List

I am trying to read the Magento product list through the SOAP API (V2) and try to do any / any type of pagination.

A simple scenario:

var filters = new filters(); var products = catalogProductList(out pe, Connection.Session, filters, null); 

This will crash Magento using: "Allowed memory size of 1073741824 bytes exhausted (tried to allocate 72 bytes."

I tried to add pagination by pointing two complex filters to product_id :

 filters.complex_filter = new complexFilter[] { new complexFilter() { key = "product_id", value = new associativeEntity() { key = "gt", value = "400" } }, new complexFilter() { key = "product_id", value = new associativeEntity() { key = "lt", value = "1000" } } }; 

However, in this scenario, only the second filter is applied, the first is ignored.

I thought about reading the category tree and then about the assigned products, but there are many products that are not tied to any category or to several categories, so I either skip them or get them several times.

Is there a way to read the product list using some type of pagination so that I don't read the full list right away? (Note: memory expansion request is not really an option)

+6
source share
4 answers

I came up with a pretty good solution for this. Hope this helps someone.

 $in = array(); for ($i = ($page * $size) - $size; $i < ($page * $size); $i++) { $in[] = $i + 1; } $complexFilter = array('complex_filter' => array( array( 'key' => 'product_id', 'value' => array( 'key' => 'in', 'value' => join(",", $in) ) ) ) ); 
+2
source

I have successfully done the following in PHP:

 $filters = new StdClass(); $filters->complexFilter = array( array( 'key' =>'sku', 'value' => array('lt'=>'03969999')), array( 'key' => 'sku', 'value' => array('gt'=>'03969000')), ); 

Although, according to

 <complexType name="filters"><all><element name="filter" type="typens:associativeArray" minOccurs="0"/><element name="complex_filter" type="typens:complexFilterArray" minOccurs="0"/></all></complexType> 

Maybe it should be "$ filters-> complex_filter = array ();"? The first code seems to have worked for me.

+1
source

It looks like the answer you need is described in fooobar.com/questions/376324 / ...

Apparently, you can use PRODUCT_ID in one of two filter conditions to circumvent the Magento restriction, which prevents two filter conditions on the same key.

+1
source

Ugly as hell, but works for me:

 public catalogProductEntity[] GetProducts() { int storeId; catalogProductEntity[] catalogEntity; List<catalogProductEntity> res = new List<catalogProductEntity>(); Client.catalogProductCurrentStore(out storeId, SessionId, null); var filters = new filters(); filters.complex_filter = new complexFilter[1]; filters.complex_filter[0] = new complexFilter(); complexFilter filter = filters.complex_filter[0]; filter.key = "name"; filter.value = new associativeEntity(); associativeEntity assoc = filter.value; assoc.key = "like"; //A to Z. for (char i = 'A'; i <= 'Z'; i++) { assoc.value = i + "%"; Client.catalogProductList(out catalogEntity, SessionId, filters, null); res.AddRange(catalogEntity); } //Starts with #. assoc.value = "#%"; Client.catalogProductList(out catalogEntity, SessionId, filters, null); res.AddRange(catalogEntity); //0 to 9 for (int i = 0; i <= 9; i++) { assoc.value = i + "%"; Client.catalogProductList(out catalogEntity, SessionId, filters, null); res.AddRange(catalogEntity); } return res.ToArray(); } 
0
source

Source: https://habr.com/ru/post/911998/


All Articles