Stefan Brendle
Stefan Brendle

Reputation: 1564

How to get all child products from a m2e ebay listing

With the magento extension m2e ("magento2ebay") it's possible to create "offers". Each offer can be contain a different number of magento products, which should be listed on ebay for example. But how can I get the products programmatically?

Upvotes: 0

Views: 440

Answers (1)

Stefan Brendle
Stefan Brendle

Reputation: 1564

First, load the Instance by an ID. You can see the ID in the listing grid in the magento backend for example:

$listing = Mage::getModel('M2ePro/Ebay_Listing')->loadInstance(1) // 1 is my listing-id

foreach ( $eBayListing->getProducts() as $key => $foo )
{
 echo  $foo->getProductId(); // for Example
}

I thought I post it on stackoverflow, because there aren't a lot examples for working with m2e classes. Maybe I'll add another examples in the future ...


If you want to get a list of all offers, try:

$all_Listings = Mage::getModel('M2ePro/Ebay_Listing')->getResourceCollection();
var_dump(   $alleListings->getData()   );

It will return an array. Each element of the array contains the main data (like the id) of the single listing object. In my case (with two offers) the return array looks like:

array(2) { 
[0]=> array(3) { ["listing_id"]=> string(1) "1" ["products_sold_count"]=> string(1) "0" ["items_sold_count"]=> string(1) "0" } 
[1]=> array(3) { ["listing_id"]=> string(1) "2" ["products_sold_count"]=> string(1) "0" ["items_sold_count"]=> string(1) "0" } 
}

To get access to the main data of the listing-object (maybe the title), you have to use this method:

$your_listing_instance->getParentObject()->getData() 

There will be common data like title, synchronisation information, total product count etc.

Upvotes: 2

Related Questions