In diesem Eintrag möchte ich zeigen, wie man eine Bestellung exportiert mit allen wichtigen Informationen und unter Beachtung der Währungsumstellung durch den Kunden (inkl. Währungskurs). Im folgenden wird ein externes Script demonstriert, welches die Mage.php einbindet und alle Bestellungen ab einer festgelegten id und mit festgelegten Status ausliest.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | <?php header('Content-Type: text/html; charset=utf-8'); date_default_timezone_set('Europe/Berlin'); //Mage $lastOrderId = 0; $arrOrders = array(); require_once '../app/Mage.php'; Mage::app(); $orders = Mage::getModel('sales/order')->getCollection() ->addAttributeToSelect("*") ->addAttributeToFilter('status', array('processing','processing_cod','pending','pending_processing','pending_payment')) ->addAttributeToFilter('entity_id', array('gt' => array($lastOrderId))); foreach($orders as $order) { //Details $orderId = 'order_'.$order->getId(); $arrOrders[$orderId]['orderdetails']['incrementid'] = $order->getIncrementId(); $arrOrders[$orderId]['orderdetails']['orderid'] = $order->getId(); $arrOrders[$orderId]['orderdetails']['status'] = $order->getStatus(); $arrOrders[$orderId]['orderdetails']['email'] = $order->getCustomerEmail(); $arrOrders[$orderId]['orderdetails']['orderdate'] = $order->getCreatedAt(); $arrOrders[$orderId]['orderdetails']['lastupdateorder'] = $order->getUpdatedAt(); $arrOrders[$orderId]['orderdetails']['payment'] = $order->getPayment()->getMethodInstance()->getTitle(); //Customer Group Tax $customerId = $order->getCustomerId(); $customer = Mage::getModel('customer/customer')->load($customerId); $customerGroupId = $customer->getGroupId(); $arrOrders[$orderId]['customer']['groupid'] = $customerGroupId; if (is_numeric($customerGroupId)) { $customerGroup = Mage::getModel ('customer/group')->load($customerGroupId); $customerGroupCode = $customerGroup->getCode(); $arrOrders[$orderId]['customer']['groupcode'] = $customerGroupCode; $customerTaxClassId = $customerGroup->getTaxClassId(); if (is_numeric($customerTaxClassId)) { $arrOrders[$orderId]['customer']['taxclassid'] = $customerTaxClassId; $taxclass = Mage::getModel('tax/class')->load($customerTaxClassId); $arrOrders[$orderId]['customer']['taxclassname'] = $taxclass->getClassName(); } } //Billing Adress $ba = $order->getBillingAddress(); $ba_street = ""; foreach ($ba->getStreet() as $value) { if ($ba_street!="") $ba_street .= ' '; $ba_street = $value; } $arrOrders[$orderId]['billingaddress']['prefix'] = $ba->getPrefix(); $arrOrders[$orderId]['billingaddress']['company'] = $ba->getCompany(); $arrOrders[$orderId]['billingaddress']['firstname'] = $ba->getFirstname(); $arrOrders[$orderId]['billingaddress']['lastname'] = $ba->getLastname(); $arrOrders[$orderId]['billingaddress']['street'] = $ba_street; $arrOrders[$orderId]['billingaddress']['postcode'] = $ba->getPostcode(); $arrOrders[$orderId]['billingaddress']['city'] = $ba->getCity(); $arrOrders[$orderId]['billingaddress']['country_iso2'] = $ba->getCountry(); $arrOrders[$orderId]['billingaddress']['region'] = $ba->getRegion(); $arrOrders[$orderId]['billingaddress']['telephone'] = $ba->getTelephone(); $arrOrders[$orderId]['billingaddress']['fax'] = $ba->getFax(); //Shipping Address $sa = $order->getShippingAddress(); $sa_street = ""; foreach ($sa->getStreet() as $value) { if ($sa_street!="") $sa_street .= ' '; $sa_street = $value; } $arrOrders[$orderId]['shippingaddress']['prefix'] = $sa->getPrefix(); $arrOrders[$orderId]['shippingaddress']['company'] = $sa->getCompany(); $arrOrders[$orderId]['shippingaddress']['firstname'] = $sa->getFirstname(); $arrOrders[$orderId]['shippingaddress']['lastname'] = $sa->getLastname(); $arrOrders[$orderId]['shippingaddress']['street'] = $sa_street; $arrOrders[$orderId]['shippingaddress']['postcode'] = $sa->getPostcode(); $arrOrders[$orderId]['shippingaddress']['city'] = $sa->getCity(); $arrOrders[$orderId]['shippingaddress']['country_iso2'] = $sa->getCountry(); $arrOrders[$orderId]['shippingaddress']['region'] = $sa->getRegion(); $arrOrders[$orderId]['shippingaddress']['telephone'] = $sa->getTelephone(); $arrOrders[$orderId]['shippingaddress']['fax'] = $sa->getFax(); //Currency $ordercurrencycode = $order->getOrderCurrencyCode(); $arrOrders[$orderId]['currency']['ordercurrencycode'] = $order->getOrderCurrencyCode(); $basecurrencycode = $order->getBaseCurrencyCode(); $arrOrders[$orderId]['currency']['basecurrencycode'] = $order->getBaseCurrencyCode(); $arrOrders[$orderId]['currency']['base_to_order_rate'] = $order->getBaseToOrderRate(); //Totals //Order (Gewählte Währung zur Bestellung) $arrOrders[$orderId]['totals'][$ordercurrencycode.'_totalprice_inkl_tax_and_shipping'] = $order->getGrandTotal(); $arrOrders[$orderId]['totals'][$ordercurrencycode.'_subtotal_inkl_tax'] = $order->getSubtotalInclTax(); $arrOrders[$orderId]['totals'][$ordercurrencycode.'_subtotal_excl_tax'] = $order->getSubtotal(); $arrOrders[$orderId]['totals'][$ordercurrencycode.'_tax_amount_inkl_shippingtax'] = $order->getTaxAmount(); $arrOrders[$orderId]['totals'][$ordercurrencycode.'_shipping_amount_inkl_tax'] = $order->getShippingInclTax(); $arrOrders[$orderId]['totals'][$ordercurrencycode.'_shipping_amount_excl_tax'] = $order->getShippingAmount(); $arrOrders[$orderId]['totals'][$ordercurrencycode.'_shipping_tax_amount'] = $order->getShippingTaxAmount(); $arrOrders[$orderId]['totals'][$ordercurrencycode.'_discount_amount'] = $order->getDiscountAmount(); //Base (Basis Währung des Shops) $arrOrders[$orderId]['totals'][$basecurrencycode.'_base_totalprice_inkl_tax_and_shipping'] = $order->getBaseGrandTotal(); $arrOrders[$orderId]['totals'][$basecurrencycode.'_base_subtotal_inkl_tax'] = $order->getBaseSubtotalInclTax(); $arrOrders[$orderId]['totals'][$basecurrencycode.'_base_subtotal_excl_tax'] = $order->getBaseSubtotal(); $arrOrders[$orderId]['totals'][$basecurrencycode.'_base_tax_amount_inkl_shippingtax'] = $order->getBaseTaxAmount(); $arrOrders[$orderId]['totals'][$basecurrencycode.'_base_shipping_amount_inkl_tax'] = $order->getBaseShippingInclTax(); $arrOrders[$orderId]['totals'][$basecurrencycode.'_base_shipping_amount_excl_tax'] = $order->getBaseShippingAmount(); $arrOrders[$orderId]['totals'][$basecurrencycode.'_base_shipping_tax_amount'] = $order->getBaseShippingTaxAmount(); $arrOrders[$orderId]['totals'][$basecurrencycode.'_base_discount_amount'] = $order->getBaseDiscountAmount(); //Items foreach ($order->getAllItems() as $item) { if ($item->getPrice() == 0.0000 && $item->getTaxPercent() == 0.0000) continue; $arrOrders[$orderId]['items']['item_'.$item->getSku()] = array(); $arrOrders[$orderId]['items']['item_'.$item->getSku()]['sku'] = $item->getSku(); $arrOrders[$orderId]['items']['item_'.$item->getSku()]['qty'] = $item->getQtyOrdered(); $arrOrders[$orderId]['items']['item_'.$item->getSku()]['weight'] = $item->getWeight(); //$arrOrders[$orderId]['items']['item_'.$item->getSku()]['productoptions'] = unserialize($item->getProduct_options()); $arrOrders[$orderId]['items']['item_'.$item->getSku()]['tax_percent'] = $item->getTaxPercent(); $arrOrders[$orderId]['items']['item_'.$item->getSku()][$ordercurrencycode.'_price_incl_tax'] = $item->getPriceInclTax(); $arrOrders[$orderId]['items']['item_'.$item->getSku()][$ordercurrencycode.'_price_excl_tax'] = round($item->getRowTotal()/$item->getQtyOrdered(),4); $arrOrders[$orderId]['items']['item_'.$item->getSku()][$ordercurrencycode.'_tax_amount'] = round($item->getTaxAmount()/$item->getQtyOrdered(),4); $arrOrders[$orderId]['items']['item_'.$item->getSku()][$ordercurrencycode.'_discount_amount'] = $item->getDiscountAmount(); $arrOrders[$orderId]['items']['item_'.$item->getSku()][$basecurrencycode.'_base_price_incl_tax'] = $item->getBasePriceInclTax(); $arrOrders[$orderId]['items']['item_'.$item->getSku()][$basecurrencycode.'_base_price_excl_tax'] = round($item->getBaseRowTotal()/$item->getQtyOrdered(),4); $arrOrders[$orderId]['items']['item_'.$item->getSku()][$basecurrencycode.'_base_tax_amount'] = round($item->getBaseTaxAmount()/$item->getQtyOrdered(),4); $arrOrders[$orderId]['items']['item_'.$item->getSku()][$ordercurrencycode.'_base_discount_amount'] = $item->getBaseDiscountAmount(); $totalweight += round($item->getQtyOrdered()*$item->getWeight(),2); } $arrOrders[$orderId]['orderdetails']['totalweight'] = $totalweight; } echo "<pre>"; print_r($arrOrders); exit; ?> |
Ausgabe Beispiel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | [order_139] => Array ( [orderdetails] => Array ( [incrementid] => 200000044 [orderid] => 139 [status] => pending_payment [email] => ****@yahoo.com [orderdate] => 2011-11-20 20:30:14 [lastupdateorder] => 2011-11-20 20:30:18 ) [customer] => Array ( [groupid] => 1 [groupcode] => Endverbraucher (DE/EU) [taxclassid] => 3 [taxclassname] => Privat - Brutto inkl. MwSt. ) [billingaddress] => Array ( [prefix] => [company] => [firstname] => ken [lastname] => tester [street] => teststreet [postcode] => 99999 [city] => burlington [country_iso2] => US [region] => New Jersey [telephone] => ***-***-**** [fax] => ) [shippingaddress] => Array ( [prefix] => [company] => [firstname] => empfaengertest [lastname] => tester [street] => teststraße [postcode] => 98999 [city] => burlington [country_iso2] => US [region] => New Jersey [telephone] => ***-***-**** [fax] => ) [currency] => Array ( [ordercurrencycode] => USD [basecurrencycode] => EUR [base_to_order_rate] => 1.3521 ) [totals] => Array ( [USD_grandtotal_inkl_tax_and_shipping] => 86.4768 [USD_subtotal_inkl_tax] => 79.6400 [USD_subtotal_excl_tax] => 66.9200 [USD_tax_amount_inkl_shippingtax] => 13.8100 [USD_shipping_amount_inkl_tax] => 10.8168 [USD_shipping_amount_excl_tax] => 9.0968 [USD_shipping_tax_amount] => 1.7300 [EUR_base_grandtotal_inkl_tax_and_shipping] => 63.9500 [EUR_base_subtotal_inkl_tax] => 58.9000 [EUR_base_subtotal_excl_tax] => 49.5000 [EUR_base_tax_amount_inkl_shippingtax] => 10.2100 [EUR_base_shipping_amount_inkl_tax] => 8.0000 [EUR_base_shipping_amount_excl_tax] => 6.7200 [EUR_base_shipping_tax_amount] => 1.2800 ) [items] => Array ( [item_MMHSRRS-1] => Array ( [sku] => MMHSRRS-1 [qty] => 1.0000 [tax_percent] => 19.0000 [USD_price_incl_tax] => 52.7319 [USD_price_excl_tax] => 44.31 [USD_tax_amount] => 8 [EUR_base_price_incl_tax] => 39.0000 [EUR_base_price_excl_tax] => 32.77 [EUR_base_tax_amount] => 5.92 ) [item_MMVDSDS-11] => Array ( [sku] => MMVDSDS-11 [qty] => 1.0000 [tax_percent] => 19.0000 [USD_price_incl_tax] => 26.9068 [USD_price_excl_tax] => 22.61 [USD_tax_amount] => 4.08 [EUR_base_price_incl_tax] => 19.9000 [EUR_base_price_excl_tax] => 16.73 [EUR_base_tax_amount] => 3.01 ) ) ) |
Info zum Discout Amount:
Nehmen wir folgendes Beispiel an: Beim Kauf von 30 Artikeln vom Preis 0,50 € bekommt man 5 € Rabatt.
Magento rechnet dann 30 * 0,50 € = 15 €
Dann wird der Rabatt subtrahiert (15 € – 5 €)
Und die MwSt auf den Restbetrag dargestellt: 1,60 €