0

I have used an external Script to sum up my orders. It's based on this script here:

    <?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;
?>

Which is by http://wiki.schmidtmarcel.de/magento-bestellung-exportieren/ -> thanks for that.

But what I need is to get a product attribute 'myattribute' too. The attribute is a multiple answers.

But I didn't find any way to get this to work, could you please help me?

2 Answers 2

0

Inside of your order items loop, you can get the product attribute value as follows:

foreach ($order->getAllItems() as $item) {
    $attributeValue = $item->getProduct()->getMyAttribute();
}
0

Because you have to add your custom attribute in to your quote.

<global>
    <sales>
        <quote>
            <item>
                <product_attributes>
                    <myattribute />
                </product_attributes>
            </item>
        </quote>
    </sales>
</global>

Or load product from catalog/product model

foreach ($order->getAllItems() as $item) {
    $product = Mage::getModel('catalog/product')->load($item->getProductId());
    //$prudct->getMyattribute();
}

Your Answer

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

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