2

Normally I would get a Magento order info (like Tax) in this way:

$order = Mage::getModel('sales/order')->loadByIncrementId($set['order_id']); echo $order->getShippingTaxAmount();

But for Ebay orders I am not able to see the M2E Order Information in the Order Object, specifically the Tax.

In the Admin area I need to click on "Show Ebay Order" to see the Tax, but i need to write a report that needs this value. Does anyone know how to retrieve the M2E Ebay Order information programmatically?

Thanks

UPDATE

this is what I needed:

$ebay_order = Mage::getModel('M2ePro/Ebay_Order')->load('41289'); 
$tax = $ebay_order->getTaxDetails();

UPDATE 2

For those in cases where you only have the increment_id for the Magento Order. You will need retrieve the ChannelOrderId first then filter the collection by ebay_order_id

See my example below:

$order = Mage::getModel('sales/order')->loadByIncrementId($increment_id);

$paymentInfo = Mage::helper('payment')->getInfoBlock($order->getPayment())->setIsSecureMode(true);
$channelOrderId = $paymentInfo->getChannelOrderId();

$ebay_order = Mage::getModel('M2ePro/ebay_order')->getCollection()
          ->addFieldToFilter('ebay_order_id', $channelOrderId)
          ->getFirstItem();

$tax = $ebay_order->getTaxDetails();

echo '<pre>';
print_r($ebay_order);
echo '</pre>';

echo '<pre>';
print_r($tax);
echo '</pre>';
1
  • 1
    Aren't you supposed to load orders based on the marketplace, i.e. $order = Mage::getModel('M2ePro/Ebay_Order')->load($id); $tax = $order->getTaxDetails(); as given in Ess_M2ePro_Model_Ebay_Order (or $order = Mage::getModel('M2ePro/Amazon_Order')->load($id); per Ess_M2ePro_Model_Amazon_Order)? Feb 7, 2018 at 1:38

2 Answers 2

0

Just for the record as it was resolved in the comments already - and furthermore to provide some ideas on how one can approach a situation like the questioner.

Unlike the name of the class Ess_M2ePro_Model_Order may let one assume, it does not provide any relevant information on externally placed orders.

The relevant class seems to be Ess_M2ePro_Model_Ebay_Order for Ebay- and Ess_M2ePro_Model_Amazon_Order for Amazon-orders. In both the method getTaxDetails() can be found.

A practical example would be:

$id = 1; // order id of interest
$order = Mage::getModel('M2ePro/Ebay_Order')->load($id); // load the order
$tax = $order->getTaxDetails(); // get tax details from order
/**
 * Note: Since I haven't worked with this module yet and haven't been
 * able to find any dummy/demo data I can't tell what the returned array
 * looks like exactly, yet, based on other methods in class it seems to
 * hold at least the keys 'rate' and 'amount'.
 * (@Hector, maybe you could share a var_dump() here?)
 */

Now just some quick ideas how one can approach a situation like this (assuming that there is not sufficient documentation provided and you don'T want to review every single file):

Especially in modules with a large amount of files/classes/methods it's always worth a shot to first of all check how the initial developer did approach a certain task. Basically this is one common way the check how certain functionality is integrated in Magento core as well when it comes to modifying a certain behavior. For the given module and problem this means, a quick check on what tables / table columns look promising is always a good starting point (unfortunately, due to the separated install/upgrade scripts in Magento 1 there is mostly hardly a way around of installing a module first, before being able to get the whole table structure).

Since the obvious one (m2epro_order) does not hold any column that seems relevant (it just has columns like account_id, marketplace_id, store_id, ...) the class Ess_M2ePro_Model_Order got pretty much uninteresting (this assumption was confirmed when having a quick look at the methods in app/code/Ess/M2ePro/Model/Order.php). Yet (when you wish to assume that the module creator did a nice job) continuing digging for the obvious mostly leads you to what you're looking for - doing so for this module would certainly bring you to the table m2epro_ebay_order. Since this table fits nicely to Model/Ebay/Order.php you're pretty much reached your goal already.

Another way to search for something you really expect to be present some where in a given module is to use the (Unix) CLI command grep -r "searchstring" /path/to/folder. Running this for some catchy phrases such as tax_details (the column name we found earlier), getTaxDetails (based on the column name) - or when in doubt getTax, Tax or tax (note that the command is case sensitive - there might be a way to overcome this but that's even further out of scope than what I'm tying already anyway ;) ). Next to some other stuff this will eventually come up with

C:\laragon\www\mage1936\app\code\community\Ess\M2ePro
λ grep -r "getTax" ./
[...]
./Model/Amazon/Order.php:    public function getTaxDetails()
./Model/Amazon/Order.php:        $taxDetails = $this->getTaxDetails();
./Model/Amazon/Order.php:        $taxDetails = $this->getTaxDetails();
./Model/Amazon/Order.php:        $taxDetails = $this->getTaxDetails();
./Model/Ebay/Order.php:    public function getTaxDetails()
./Model/Ebay/Order.php:    public function getTaxRate()
./Model/Ebay/Order.php:        $taxDetails = $this->getTaxDetails();
./Model/Ebay/Order.php:    public function getTaxAmount()

Module source for reference: https://github.com/m2epro/magento1-extension

0

Thank you Christoph for helping understand the Class in more detail. Per your comment I will share what the returned array looked like for me:

$order = Mage::getModel('M2ePro/Ebay_Order')->load($id); $tax = $order->getTaxDetails();

Array ( [rate] => 7 [amount] => 12.11 [is_vat] => [includes_shipping] => )

And $order holds these keys:

[order_id] => 00000 [ebay_order_id] => 0000000000 [selling_manager_id] => 00000 [buyer_name] => Name [buyer_email] => [email protected] [buyer_user_id] => user000000 [buyer_message] => [buyer_tax_id] => [paid_amount] => 0.0000 [saved_amount] => 0.0000 [currency] => USD [checkout_status] => 1 [shipping_status] => 2 [payment_status] => 3 [shipping_details] => {"address":{"country_code":"US","country_name":"United States","city":"Tampa","state":"FL","postal_code":"000000","phone":"00000","street":["PO Box 0000"],"company":""},"service":"USPS Priority Mail","price":13,"date":"2018-01-30 15:08:10","global_shipping_details":[],"click_and_collect_details":[],"in_store_pickup_details":[],"cash_on_delivery_cost":0} [payment_details] => {"date":"2018-01-29 21:53:54","method":"PayPal","status":"NoPaymentFailure","is_refund":false} [tax_details] => {"rate":7,"amount":12.11,"is_vat":false,"includes_shipping":false} [purchase_update_date] => 2018-02-02 22:39:36 [purchase_create_date] => 2018-01-29 21:34:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.