Last active
September 8, 2015 03:00
-
-
Save michaelhoang/aa7ed8653c44562119cb to your computer and use it in GitHub Desktop.
Magento Add Pagination Pager in block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Reference: app/code/core/Mage/Sales/Model/Service/Quote.php:134 | |
// Set customer info to quote | |
// $store = Mage::getSingleton('core/store')->load($this->getArg('store_id')); | |
// $quote = Mage::getModel('sales/quote')->setStore($store)->load($this->getArg('quote_id')); | |
$convert = Mage::getModel('sales/convert_quote'); | |
$isVirtual = $quote->isVirtual(); | |
// Set shipping method | |
$quote->getShippingAddress()->setShippingMethod('freeshipping_freeshipping'); | |
// Set payment method to quote | |
$quote->collectTotals() | |
->getPayment()->setMethod('checkmo'); | |
$transaction = Mage::getModel('core/resource_transaction'); | |
if ($quote->getCustomerId()) { | |
$transaction->addObject($quote->getCustomer()); | |
} | |
$transaction->addObject($quote); | |
// Generate reserve order id | |
$quote->reserveOrderId(); | |
if ($isVirtual) { | |
$order = $convert->addressToOrder($quote->getBillingAddress()); | |
} else { | |
$order = $convert->addressToOrder($quote->getShippingAddress()); | |
} | |
$order->setBillingAddress($convert->addressToOrderAddress($quote->getBillingAddress())); | |
if ($quote->getBillingAddress()->getCustomerAddress()) { | |
$order->getBillingAddress()->setCustomerAddress($quote->getBillingAddress()->getCustomerAddress()); | |
} | |
if (!$isVirtual) { | |
$order->setShippingAddress($convert->addressToOrderAddress($quote->getShippingAddress())); | |
if ($quote->getShippingAddress()->getCustomerAddress()) { | |
$order->getShippingAddress()->setCustomerAddress($quote->getShippingAddress()->getCustomerAddress()); | |
} | |
} | |
$order->setPayment($convert->paymentToOrderPayment($quote->getPayment())); | |
foreach ($quote->getAllItems() as $item) { | |
$orderItem = $convert->itemToOrderItem($item); | |
if ($item->getParentItem()) { | |
$orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId())); | |
} | |
$order->addItem($orderItem); | |
} | |
$order->setQuote($quote); | |
$transaction->addObject($order); | |
$transaction->addCommitCallback(array($order, 'place')); | |
$transaction->addCommitCallback(array($order, 'save')); | |
/** | |
* We can use configuration data for declare new order status | |
*/ | |
Mage::dispatchEvent('checkout_type_onepage_save_order', array('order'=>$order, 'quote'=>$quote)); | |
Mage::dispatchEvent('sales_model_service_quote_submit_before', array('order'=>$order, 'quote'=>$quote)); | |
try { | |
$transaction->save(); | |
$quote->setIsActive(false); | |
Mage::dispatchEvent('sales_model_service_quote_submit_success', array('order'=>$order, 'quote'=>$quote)); | |
} catch (Exception $e) { | |
if (!Mage::getSingleton('customer/session')->isLoggedIn()) { | |
// reset customer ID's on exception, because customer not saved | |
$quote->getCustomer()->setId(null); | |
} | |
//reset order ID's on exception, because order not saved | |
$order->setId(null); | |
/** @var $item Mage_Sales_Model_Order_Item */ | |
foreach ($order->getItemsCollection() as $item) { | |
$item->setOrderId(null); | |
$item->setItemId(null); | |
} | |
Mage::dispatchEvent('sales_model_service_quote_submit_failure', array('order'=>$order, 'quote'=>$quote)); | |
throw $e; | |
} | |
Mage::dispatchEvent('sales_model_service_quote_submit_after', array('order'=>$order, 'quote'=>$quote)); | |
// Clear checkout cart | |
Mage::getSingleton('checkout/cart')->truncate()->save(); | |
// Clear session data | |
Mage::getSingleton('checkout/session')->clear(); | |
$quote->save(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Example pagination in check cart | |
* We should add in block class: overide function _prepareLayout | |
* app/code/local/Likipe/Reseller/Block/Cart.php | |
* Get template in block: $this->getChildHtml('cart.pager') | |
*/ | |
protected function _prepareLayout() | |
{ | |
parent::_prepareLayout(); | |
$pager = $this->getLayout()->createBlock('page/html_pager', 'cart.pager')->setTemplate('likipe/page/html/pager.phtml'); | |
$pager->setCollection($this->_prepareProductCollection()); | |
$this->setChild('cart.pager', $pager); // Set child block and its allias | |
return $this; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment