You get the error main.WARNING: Session size of … exceeded allowed session max size of … when adding items to an order in the Magento 2 admin area? There is an easy solution to that problem, just run the following…
Getting the PayPal transaction ID (Magento 1)
Use the following code to get the Magento PayPal transaction ID from an order object:
1 |
$transactionId = $order->getPayment()->getLastTransId(); |
Sort order items by SKU (Magento 1)
If you want to change the default sorting of the ordered items on the order detail page, go ahead and override app/design/adminhtml/default/default/template/sales/order/view/items.phtml in your theme and replace
1 2 3 4 5 6 7 8 |
<?php $_items = $this->getItemsCollection() ?> <?php $i=0;foreach ($_items as $_item):?> <?php if ($_item->getParentItem()) continue; else $i++;?> <tbody class="<?php echo $i%2?'even':'odd' ?>"> <?php echo $this->getItemHtml($_item) ?> <?php echo $this->getItemExtraInfoHtml($_item) ?> </tbody> <?php endforeach; ?> |
with
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php $_items = $this->getItemsCollection() ?> <?php $_sortedItems = array(); ?> <?php foreach ($_items as $_item) : ?> <?php $_sortedItems[$_item->getSku()] = $_item;?> <?php endforeach;?> <?php ksort($_sortedItems); // This is where the sorting by SKU takes place ?> <?php $i=0;foreach ($_sortedItems as $_item):?> <?php if ($_item->getParentItem()) continue; else $i++;?> <tbody class="<?php echo $i%2?'even':'odd' ?>"> <?php echo $this->getItemHtml($_item) ?> <?php echo $this->getItemExtraInfoHtml($_item) ?> </tbody> <?php endforeach; ?> |
Done. If you open the detail page of an order…
Creating order including custom options programmatically (Magento 1)
Using the following code, you can create an order including custom options programmatically.
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 |
$quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore('default')->getId()); $quote->setCustomerEmail($mail); $product = Mage::getModel('catalog/product')->load($productId); $buyInfo = array( 'qty' => 1, 'options' => array($optionId => $optionValue) ); $quote->addProduct($product, new Varien_Object($buyInfo)); $addressData = array( 'firstname' => $firstName, 'lastname' => $lastName, 'street' => $street, 'city' => $city, 'postcode' => $postCode, 'telephone' => '-', 'country_id' => $country, 'region_id' => $regionId, ); $billingAddress = $quote->getBillingAddress()->addData($addressData); $shippingAddress = $quote->getShippingAddress()->addData($addressData); $shippingAddress->setCollectShippingRates(true)->collectShippingRates() ->setShippingMethod('flatrate_flatrate') ->setPaymentMethod('bankpayment'); $quote->getPayment()->importData(array('method' => 'bankpayment')); $quote->collectTotals()->save(); $service = Mage::getModel('sales/service_quote', $quote); $service->submitAll(); $order = $service->getOrder(); // ... |
Getting orders with items that have a certain attribute set (Magento 1)
The following MySQL query returns all Magento orders that have at least one item with attribute set id 9.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
/* 9 = attribute set Id */ select increment_id, created_at, entity_id from sales_flat_order where entity_id not in ( SELECT o.entity_id FROM sales_flat_order o LEFT JOIN sales_flat_order_item i ON o.entity_id = i.order_id LEFT JOIN catalog_product_entity p ON i.product_id = p.entity_id WHERE p.attribute_set_id = 9 ) |
Getting an orders tracking information (Magento 1)
Using the following code, you can obtain the tracking information of a Magento order.
1 2 3 4 |
$trackingCollection = $order->getTracksCollection(); $firstItem = $trackingCollection->getFirstItem(); $trackingNumber = $firstItem->getNumber(); ... |
Getting order data on success page (success.phtml) (Magento 1)
To get the order data on the Magento success page, use the following code. The key here is to create an order object and get the data from there.
1 2 3 |
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId()); $date = $order->getCreatedAtStoreDate(); // ... |
Getting order items on success page (success.phtml) (Magento 1)
Use the following code to get all ordered items on the Magento success page.
1 2 3 4 5 |
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId()); $items = $order->getAllItems(); foreach($items as $item) { //... } |
Getting the shipping address for an order (Magento 1)
Use the following code to get the shipping address of a Magento order:
1 |
$address = $order->getShippingAddress(); |