/** * Save shipment * We can save only new shipment. Existing shipments are not editable * * @return null */ public function saveAction() { $data = $this->getRequest()->getPost('shipment'); if (!empty($data['comment_text'])) { Mage::getSingleton('adminhtml/session')->setCommentText($data['comment_text']); } try { $shipment = $this->_initShipment(); if (!$shipment) { $this->_forward('noRoute'); return; } $shipment->register(); $comment = ''; if (!empty($data['comment_text'])) { $shipment->addComment($data['comment_text'], isset($data['comment_customer_notify']), isset($data['is_visible_on_front'])); if (isset($data['comment_customer_notify'])) { $comment = $data['comment_text']; } } if (!empty($data['send_email'])) { $shipment->setEmailSent(true); } $shipment->getOrder()->setCustomerNoteNotify(!empty($data['send_email'])); $responseAjax = new Varien_Object(); $isNeedCreateLabel = isset($data['create_shipping_label']) && $data['create_shipping_label']; if ($isNeedCreateLabel && $this->_createShippingLabel($shipment)) { $responseAjax->setOk(true); } $this->_saveShipment($shipment); Mage::dispatchEvent('sales_order_shipment_save_custom', array('post' => $data, 'shipment' => $shipment)); $shipment->sendEmail(!empty($data['send_email']), $comment); $shipmentCreatedMessage = $this->__('The shipment has been created.'); $labelCreatedMessage = $this->__('The shipping label has been created.'); $this->_getSession()->addSuccess($isNeedCreateLabel ? $shipmentCreatedMessage . ' ' . $labelCreatedMessage : $shipmentCreatedMessage); Mage::getSingleton('adminhtml/session')->getCommentText(true); } catch (Mage_Core_Exception $e) { if ($isNeedCreateLabel) { $responseAjax->setError(true); $responseAjax->setMessage($e->getMessage()); } else { $this->_getSession()->addError($e->getMessage()); $this->_redirect('*/*/new', array('order_id' => $this->getRequest()->getParam('order_id'))); } } catch (Exception $e) { Mage::logException($e); if ($isNeedCreateLabel) { $responseAjax->setError(true); $responseAjax->setMessage(Mage::helper('sales')->__('An error occurred while creating shipping label.')); } else { $this->_getSession()->addError($this->__('Cannot save shipment.')); $this->_redirect('*/*/new', array('order_id' => $this->getRequest()->getParam('order_id'))); } } if ($isNeedCreateLabel) { $this->getResponse()->setBody($responseAjax->toJson()); } else { $this->_redirect('*/sales_order/view', array('order_id' => $shipment->getOrderId())); } }
public function confirmAction() { $updateResult = new Varien_Object(); try { $orderItemId = (int) $this->getRequest()->getParam('item_id'); $options = $this->getRequest()->getParam('options'); $orderItem = Mage::getModel('sales/order_item')->load($orderItemId); $quote = Mage::getModel('sales/quote')->load($orderItem->getOrder()->getQuoteId()); $quoteItem = Mage::getModel('sales/quote_item')->load($orderItem->getQuoteItemId())->setQuote($quote); $buyRequest = $orderItem->getBuyRequest(); $buyRequest->setOptions($options); $products = $orderItem->getProduct()->getTypeInstance(true)->prepareForCartAdvanced($buyRequest, $orderItem->getProduct(), 'lite'); $quoteItem->setOptions($products[0]->getCustomOptions()); $quoteItem->setBuyRequest($buyRequest); $productOptions = $orderItem->getProductOptions(); $productOptions['info_buyRequest'] = $buyRequest->getData(); $productOptions['options'] = Mage::helper('catalog/product_configuration')->getCustomOptions($quoteItem); $orderItem->setProductOptions($productOptions); Mage::dispatchEvent('sales_convert_quote_item_to_order_item', array('order_item' => $orderItem, 'item' => $quoteItem)); $quoteItem->save(); $orderItem->save(); $updateResult->setOk(true); } catch (Exception $e) { $updateResult->setError(true); $updateResult->setMessage($e->getMessage()); } $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname')); Mage::getSingleton('adminhtml/session')->setCompositeProductResult($updateResult); $this->_redirect('*/catalog_product/showUpdateResult'); return $this; }
public function configureProductToAddAction() { echo 'okk'; return; // Prepare data $productId = (int) $this->getRequest()->getParam('id'); $configureResult = new Varien_Object(); $configureResult->setOk(true); $configureResult->setProductId($productId); $sessionQuote = Mage::getSingleton('adminhtml/session_quote'); $configureResult->setCurrentStoreId($sessionQuote->getStore()->getId()); $configureResult->setCurrentCustomerId($sessionQuote->getCustomerId()); // Render page /* @var $helper Mage_Adminhtml_Helper_Catalog_Product_Composite */ $helper = Mage::helper('adminhtml/catalog_product_composite'); $helper->renderConfigureResult($this, $configureResult); echo $this->_lens($productId); return $this; }
public function configureQuoteItemsAction() { // Prepare data $configureResult = new Varien_Object(); try { $quoteItemId = (int) $this->getRequest()->getParam('id'); if (!$quoteItemId) { Mage::throwException($this->__('Quote item id is not received.')); } $quoteItem = Mage::getModel('buyback/quote_item')->load($quoteItemId); if (!$quoteItem->getId()) { Mage::throwException($this->__('Quote item is not loaded.')); } $configureResult->setOk(true); $optionCollection = Mage::getModel('buyback/quote_item_option')->getCollection()->addItemFilter(array($quoteItemId)); $quoteItem->setOptions($optionCollection->getOptionsByItem($quoteItem)); $configureResult->setBuyRequest($quoteItem->getBuyRequest()); $configureResult->setCurrentStoreId($quoteItem->getStoreId()); $configureResult->setProductId($quoteItem->getProductId()); $sessionQuote = Mage::getSingleton('adminhtml/session_quote'); $configureResult->setCurrentCustomerId($sessionQuote->getCustomerId()); } catch (Exception $e) { $configureResult->setError(true); $configureResult->setMessage($e->getMessage()); } // Render page /* @var $helper Mage_Adminhtml_Helper_Catalog_Product_Composite */ $helper = Mage::helper('adminhtml/catalog_product_composite'); $helper->renderConfigureResult($this, $configureResult); return $this; }
/** * Ship order */ public function shipAction() { $orderid = $this->getRequest()->getParam('id'); if ($order = $this->_initOrder()) { try { $customerid = Mage::getSingleton('customer/session')->getCustomerId(); $seller_orders = Mage::getModel('marketplace/order')->getCollection()->addFieldToFilter('seller_id', array('eq' => $customerid))->addFieldToFilter('order_id', array('eq' => $orderid)); if (count($seller_orders)) { $trackingid = $this->getRequest()->getParam('tracking_id'); if ($this->getRequest()->getParam('api_shipment')) { Mage::dispatchEvent('generate_api_shipment', array('api_shipment' => $this->getRequest()->getParam('api_shipment'), 'orderid' => $orderid)); $shipment_data = Mage::getSingleton('core/session')->getData('shipment_data'); $api_name = $shipment_data['api_name']; $trackingid = $shipment_data['tracking_number']; Mage::getSingleton('core/session')->unsetData('shipment_data'); } if ($this->getRequest()->getParam('api_shipment') && $trackingid == '') { $this->_redirect('marketplace/order/view/', array('id' => $orderid)); } else { $carrier = $this->getRequest()->getParam('carrier'); $order = Mage::getModel('sales/order')->load($orderid); if ($order->canUnhold()) { Mage::getSingleton('core/session')->addError(Mage::helper('marketplace')->__("Can not do shipment as order is in HOLD state")); } else { $items = array(); $shippingAmount = 0; foreach ($seller_orders as $tracking) { $shippingAmount = $tracking->getShippingCharges(); } $collection = Mage::getModel('marketplace/saleslist')->getCollection()->addFieldToFilter('mageproownerid', $customerid)->addFieldToFilter('mageorderid', array('eq' => $orderid)); foreach ($collection as $saleproduct) { array_push($items, $saleproduct['order_item_id']); } /**/ $itemsarray = $this->_getItemQtys($order, $items); if (count($itemsarray) > 0) { $shipment = false; $shipmentId = $this->getRequest()->getParam('shipment_id'); $orderId = $orderid; if ($shipmentId) { $shipment = Mage::getModel('sales/order_shipment')->load($shipmentId); } elseif ($orderId) { $order = Mage::getModel('sales/order')->load($orderId); if (!$order->getId()) { Mage::getSingleton('core/session')->addError(Mage::helper('marketplace')->__('The order no longer exists.')); return false; } if ($order->getForcedDoShipmentWithInvoice()) { Mage::getSingleton('core/session')->addError(Mage::helper('marketplace')->__('Cannot do shipment for the order separately from invoice.')); return false; } if (!$order->canShip()) { Mage::getSingleton('core/session')->addError(Mage::helper('marketplace')->__('Cannot do shipment for the order.')); return false; } $savedQtys = $this->_getItemQtys($order, $items); $shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($savedQtys['data']); } $shipment->register(); $comment = ''; $shipment->getOrder()->setCustomerNoteNotify(1); $responseAjax = new Varien_Object(); $isNeedCreateLabel = isset($data['create_shipping_label']) && $data['create_shipping_label']; if ($isNeedCreateLabel && true) { $responseAjax->setOk(true); } $shipment->getOrder()->setIsInProcess(true); $transactionSave = Mage::getModel('core/resource_transaction')->addObject($shipment)->addObject($shipment->getOrder())->save(); $shipmentCreatedMessage = Mage::helper('marketplace')->__('The shipment has been created.'); $labelCreatedMessage = Mage::helper('marketplace')->__('The shipping label has been created.'); Mage::getSingleton('core/session')->addSuccess($isNeedCreateLabel ? $shipmentCreatedMessage . ' ' . $labelCreatedMessage : $shipmentCreatedMessage); $courrier = "custom"; $seller_collection = Mage::getModel('marketplace/order')->getCollection()->addFieldToFilter('seller_id', array('eq' => $customerid))->addFieldToFilter('order_id', array('eq' => $orderid)); foreach ($seller_collection as $row) { if ($shipment->getId() != '') { $row->setShipmentId($shipment->getId()); $row->setTrackingNumber($trackingid); $row->setCarrierName($carrier); $row->save(); $track = Mage::getModel('sales/order_shipment_track')->setShipment($shipment)->setData('title', $carrier)->setData('number', $trackingid)->setData('carrier_code', $courrier)->setData('order_id', $shipment->getData('order_id'))->save(); } } $shipment->sendEmail(true, $comment)->setEmailSent(true)->save(); Mage::getModel('marketplace/order')->getCommsionCalculation($order); } } } } else { Mage::getSingleton('core/session')->addError(Mage::helper('marketplace')->__('You are not permitted to generate shipment for this order.')); } } catch (Exception $e) { Mage::getSingleton('core/session')->addError(Mage::helper('marketplace')->__($e->getMessage())); } } $this->_redirect('marketplace/order/view/', array('id' => $orderid)); }
/** * IFrame handler for submitted configuration for wishlist item * * @return false */ public function updateAction() { // Update wishlist item $updateResult = new Varien_Object(); try { $this->_initData(); $buyRequest = new Varien_Object($this->getRequest()->getParams()); $this->_wishlist->updateItem($this->_wishlistItem->getId(), $buyRequest)->save(); $updateResult->setOk(true); } catch (Exception $e) { $updateResult->setError(true); $updateResult->setMessage($e->getMessage()); } $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname')); Mage::getSingleton('adminhtml/session')->setCompositeProductResult($updateResult); $this->_redirect('*/catalog_product/showUpdateResult'); return false; }
/** * Create shipping label action for specific shipment * */ public function createLabelAction() { $response = new Varien_Object(); try { $shipment = $this->_initShipment(); if ($this->_createShippingLabel($shipment)) { $shipment->save(); $this->_getSession()->addSuccess(Mage::helper('sales')->__('The shipping label has been created.')); $response->setOk(true); } } catch (Mage_Core_Exception $e) { $response->setError(true); $response->setMessage($e->getMessage()); } catch (Exception $e) { Mage::logException($e); $response->setError(true); $response->setMessage(Mage::helper('sales')->__('An error occurred while creating shipping label.')); } $this->getResponse()->setBody($response->toJson()); }
/** * Save shipment * We can save only new shipment. Existing shipments are not editable * * @return null */ public function savePostAction() { $isNeedCreateLabel = ''; try { $updateOrderId = $this->getRequest()->getParam('order_id'); $collection = Mage::getModel('marketplace/commission')->getCollection()->addFieldToFilter('seller_id', Mage::getSingleton('customer/session')->getId())->addFieldToFilter('order_id', $updateOrderId)->getFirstItem(); /** * Checking manage order enable for seller */ $orderStatusFlag = Mage::getStoreConfig('marketplace/admin_approval_seller_registration/order_manage'); /** * Checking for seller order management enable or not */ if (count($collection) <= 0 || $orderStatusFlag != 1) { $this->_getSession()->addError($this->__('You do not have permission to access this page')); $this->_redirect('marketplace/order/vieworder/orderid/' . $updateOrderId); return; } /** * Gettting shipment info */ $data = $this->getRequest()->getParam('shipment'); $shipment = $this->_initShipment(); if (!$shipment) { $this->_forward('noRoute'); return; } /** * Register shipment */ $shipment->register(); $comment = ''; if (!empty($data['comment_text'])) { $shipment->addComment($data['comment_text'], isset($data['comment_customer_notify']), isset($data['is_visible_on_front'])); if (isset($data['comment_customer_notify'])) { $comment = $data['comment_text']; } } $shipment->setEmailSent(true); $shipment->getOrder()->setCustomerNoteNotify(true); $responseAjax = new Varien_Object(); $isNeedCreateLabel = isset($data['create_shipping_label']) && $data['create_shipping_label']; if ($isNeedCreateLabel && $this->_createShippingLabel($shipment)) { $responseAjax->setOk(true); } /** * Save shipment */ $this->_saveShipment($shipment); /** * Send shipment email */ $shipment->sendEmail(true, $comment); /** * Initilize shipment label */ $shipmentCreatedMessage = $this->__('The shipment has been created.'); $labelCreatedMessage = $this->__('The shipping label has been created.'); $savedQtys = $this->_getItemQtys(); Mage::getModel('marketplace/order')->updateSellerOrderItemsBasedOnSellerItems($savedQtys, $updateOrderId, 0); $this->_getSession()->addSuccess($isNeedCreateLabel ? $shipmentCreatedMessage . ' ' . $labelCreatedMessage : $shipmentCreatedMessage); } catch (Mage_Core_Exception $e) { if ($isNeedCreateLabel) { $responseAjax->setError(true); $responseAjax->setMessage($e->getMessage()); } else { $this->_getSession()->addError($e->getMessage()); $this->_redirect('marketplace/order/vieworder/orderid/' . $updateOrderId); } } catch (Exception $e) { Mage::logException($e); if ($isNeedCreateLabel) { $responseAjax->setError(true); $responseAjax->setMessage(Mage::helper('sales')->__('An error occurred while creating shipping label.')); } else { $this->_getSession()->addError($this->__('Cannot save shipment.')); $this->_redirect('marketplace/order/vieworder/orderid/' . $updateOrderId); } } if ($isNeedCreateLabel) { $this->getResponse()->setBody($responseAjax->toJson()); } else { $this->_redirect('marketplace/order/vieworder/orderid/' . $updateOrderId); } }