Ejemplo n.º 1
0
 public function reorderAction()
 {
     if ($vendor = Mage::helper('smvendors')->getVendorLogin()) {
         $this->_getSession()->clear();
         $orderId = $this->getRequest()->getParam('order_id');
         $order = Mage::getModel('sales/order')->load($orderId);
         /* @var $order Mage_Sales_Model_Order */
         if (!Mage::helper('sales/reorder')->canReorder($order)) {
             return $this->_forward('noRoute');
         }
         if ($order->getId()) {
             $items = $order->getItemsCollection();
             foreach ($items as $key => $item) {
                 if ($item->getVendorId() !== $vendor->getId()) {
                     $items->removeItemByKey($key);
                 }
             }
             $order->setReordered(true);
             $this->_getSession()->setUseOldShippingMethod(true);
             $this->_getOrderCreateModel()->initFromOrder($order);
             $this->_redirect('*/*');
         } else {
             $this->_redirect('*/vendors_order/');
         }
     } else {
         return parent::reorderAction();
     }
 }
Ejemplo n.º 2
0
 protected function _processActionData($action = null)
 {
     parent::_processActionData($action);
     Mage::app()->setCurrentStore($this->getStore());
     $quote = Mage::getSingleton('checkout/cart')->getQuote();
     if ($action == 'save') {
         $mt = Mage::getSingleton('payment/method_free');
         $payDefault = Mage::getSingleton('sales/quote_payment')->load(1);
         $quote->setPayment($payDefault);
         $quote->getPayment()->setMethod('free');
         $quote->save();
         $h = Mage::helper('payment')->getPaymentMethods();
         foreach ($h as $pp) {
             var_dump($pp);
             break;
         }
         var_dump($quote->getPayment()->getData());
         $this->_getOrderCreateModel()->setQuote($quote);
         $this->_getOrderCreateModel()->saveQuote();
     }
 }
Ejemplo n.º 3
0
 /**
  * Process request data with additional logic for saving quote and creating order
  *
  * @param string $action
  * @return Mage_Adminhtml_Sales_Order_CreateController
  */
 protected function _processData($action = null)
 {
     //2011-12-20 HiepHM: Fix bug auto add product that has product_id = quote item_id
     //Bug arised because must pass $action to _processActionData(), so it could be checked in line 193 of CreateController:
     // ... && !($action == 'save'))
     if ($action != 'save') {
         if (Mage::helper('xpos')->aboveVersion('1.5')) {
             parent::_processActionData($action);
         } else {
             parent::_processData();
         }
     }
     if ($action == 'save') {
         $quote = $this->_getOrderCreateModel()->getQuote();
         if ($storeid = $this->getRequest()->getPost('store_id')) {
             $quote->setStoreId($storeid);
         } else {
             $quote->setStoreId($this->_storeid);
         }
         $data = $this->getRequest()->getPost('order');
         $couponCode = $this->_processDiscount($data);
         $shipping_same_as_billing = $this->getRequest()->getPost('shipping_same_as_billing');
         if ($data['customer_id'] != "false" && intval($data['customer_id'])) {
             $this->_getSession()->setCustomerId((int) $data['customer_id']);
         }
         $billingAddress = array('firstname' => 'Guest ' . $this->_getOrderCreateModel()->getQuote()->getId(), 'lastname' => 'Guest ' . $this->_getOrderCreateModel()->getQuote()->getId(), 'street' => array('Guest Address'), 'city' => empty($this->_billingOrigin['city']) ? 'Guest City' : $this->_billingOrigin['city'], 'country_id' => empty($this->_billingOrigin['country_id']) ? 'Guest City' : $this->_billingOrigin['country_id'], 'region' => empty($this->_billingOrigin['region']) ? 'CA' : $this->_billingOrigin['region'], 'postcode' => empty($this->_billingOrigin['postcode']) ? '95064' : $this->_billingOrigin['postcode'], 'telephone' => Mage::getStoreConfig('general/store_information/phone') == "" ? '1234567890' : Mage::getStoreConfig('general/store_information/phone'));
         if (!empty($data['customer_id']) && ($customer_id = $this->_getSession()->getCustomerId())) {
             if (Mage::getModel('customer/customer')->load($customer_id)->getDefaultBillingAddress()) {
                 $defaultBillingAddress = Mage::getModel('customer/customer')->load($customer_id)->getDefaultBillingAddress()->getData();
             }
             foreach ($billingAddress as $k => $v) {
                 if (!empty($defaultBillingAddress[$k])) {
                     $data['billing_address'][$k] = $defaultBillingAddress[$k];
                 }
             }
             if (!empty($defaultBillingAddress['region_id'])) {
                 unset($data['billing_address']['region']);
                 $data['billing_address']['region_id'] = $defaultBillingAddress['region_id'];
             }
         } else {
             foreach ($billingAddress as $k => $v) {
                 if (empty($data['billing_address'][$k])) {
                     $data['billing_address'][$k] = $v;
                 }
             }
         }
         $quote->getBillingAddress()->addData($data['billing_address']);
         if ($shipping_same_as_billing) {
             $quote->getShippingAddress()->addData($data['billing_address']);
         } else {
             $quote->getShippingAddress()->addData($data['shipping_address']);
         }
         $data['shipping_method'] = "freeshipping_freeshipping";
         $shippingAddress = $quote->getShippingAddress();
         $shippingAddress->setCollectShippingRates(true)->collectShippingRates()->setShippingMethod('freeshipping_freeshipping');
         if ($paymentData = $this->getRequest()->getPost('payment')) {
             $this->_getOrderCreateModel()->setPaymentData($paymentData);
             $quote->getPayment()->addData($paymentData);
         }
         $this->_getOrderCreateModel()->collectRates();
         $quote->collectTotals();
         $quote->save();
         // remove coupon if has
         if ($couponCode) {
             $couponCode->setIsActive(0)->save();
         }
     }
 }