Ejemplo n.º 1
0
 /**
  * Start List of functions which handle the grids actions
  * todo refactor all these
  */
 public function addExportAction($observer)
 {
     $block = $observer->getEvent()->getBlock();
     /** @var $block Mage_Adminhtml_Block_Widget_Grid_Massaction */
     if (get_class($block) == 'Mage_Adminhtml_Block_Widget_Grid_Massaction' && $block->getRequest()->getControllerName() == 'sales_order') {
         $block->addItem('payperrentals1', array('label' => Mage::helper('payperrentals')->__('Delete Order Completely'), 'url' => Mage::helper('adminhtml')->getUrl('payperrentals/adminhtml_salesgrid/massDelete')));
         $block->addItem('payperrentals2', array('label' => Mage::helper('payperrentals')->__('Reserve Inventory'), 'url' => Mage::helper('adminhtml')->getUrl('payperrentals/adminhtml_salesgrid/massReserve')));
     }
     if (get_class($block) == 'Mage_Adminhtml_Block_Widget_Grid_Massaction' && $block->getRequest()->getControllerName() == 'catalog_product') {
         $convertoptions = Mage::getSingleton('payperrentals/product_convert')->getOptionArray();
         array_unshift($convertoptions, array('label' => '', 'value' => ''));
         $block->addItem('convert', array('label' => Mage::helper('payperrentals')->__('Convert product type'), 'url' => Mage::helper('adminhtml')->getUrl('payperrentals/adminhtml_productgrid/massConvert', array('_current' => true)), 'additional' => array('visibility' => array('name' => 'convertoption', 'type' => 'select', 'class' => 'required-entry', 'label' => Mage::helper('payperrentals')->__("Convert"), 'values' => $convertoptions))));
     }
     /** @var $block Mage_Adminhtml_Block_Sales_Order_View */
     if ($block->getType() == 'adminhtml/sales_order_view') {
         $order = $block->getOrder();
         $_returnCollection = Mage::getResourceModel('payperrentals/sendreturn_collection')->addFieldToFilter('order_id', array('in' => array($order->getId(), $order->getIncrementId())));
         $_totalQtyReturned = 0;
         $_returnedUnixtimeDate = 0;
         foreach ($_returnCollection as $_returnItem) {
             if ($_returnItem->getReturnDate() != '0000-00-00 00:00:00' && $_returnItem->getReturnDate() != '1970-01-01 00:00:00') {
                 $_totalQtyReturned += $_returnItem->getQty();
                 if ($_returnedUnixtimeDate < strtotime($_returnItem->getReturnDate())) {
                     $_returnedUnixtimeDate = strtotime($_returnItem->getReturnDate());
                 }
             }
         }
         $_shipmentCollection = Mage::getResourceModel('payperrentals/sendreturn_collection')->addFieldToFilter('order_id', array('in' => array($order->getEntityId(), $order->getIncrementId())));
         $_totalQtyShipped = 0;
         foreach ($_shipmentCollection as $_shipmentItem) {
             if ($_shipmentItem->getSendDate() != '0000-00-00 00:00:00' && $_shipmentItem->getSendDate() != '1970-01-01 00:00:00') {
                 $_totalQtyShipped += $_shipmentItem->getQty();
             }
         }
         if (!$_totalQtyReturned || $_totalQtyReturned < $_totalQtyShipped) {
             $block->addButton('order_return', array('label' => Mage::helper('payperrentals')->__('Return'), 'onclick' => 'setLocation(\'' . $block->getUrl('*/sales_order_return/new', array('order_id' => $block->getOrder()->getId())) . '\')'));
         }
         $block->addButton('order_edit_dates', array('label' => Mage::helper('payperrentals')->__('Edit Rental Dates'), 'onclick' => 'setLocation(\'' . $this->getRentalEditUrl($block) . '\')'));
         if (ITwebexperts_Payperrentals_Helper_Extend::isExtensibleOrder($block->getOrder()->getId())) {
             $block->addButton('order_extend', array('label' => Mage::helper('payperrentals')->__('Extend Order'), 'onclick' => 'extendOrder(\'' . $block->getOrder()->getId() . '\', \'' . $block->getOrder()->getIncrementId() . '\')'));
         }
         if (ITwebexperts_Payperrentals_Helper_Data::isLateOrder($block->getOrder()->getId())) {
             if (!Mage::helper('itwebcommon')->isVendorAdmin()) {
                 $block->addButton('order_extend', array('label' => Mage::helper('payperrentals')->__('Charge Late Fee'), 'onclick' => 'showLateFeePopup(' . '\'popup_form_policy\', ' . $block->getOrder()->getId() . ')'));
             }
         }
         $block->addButton('rentalcontract', array('label' => Mage::helper('payperrentals')->__('Rental Contract'), 'onclick' => 'setLocation(\'' . $block->getUrl('payperrentals_admin/adminhtml_rentalcontract/generate', array('order_id' => $block->getOrder()->getId())) . '\')'));
         if (Mage::helper('payperrentals')->orderContainsReservation($block->getOrder()->getId()) && Mage::helper('payperrentals/config')->enabledDigitalSignature()) {
             $block->addButton('signature', array('label' => Mage::helper('payperrentals')->__('Capture Signature'), 'onclick' => 'showSignaturePopup(\'' . $block->getUrl('payperrentals_admin/adminhtml_signature/view', array('order_id' => $block->getOrder()->getId())) . '\')'));
         }
     }
 }