diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Customer.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Customer.php index 746115d32b3..dae7ed1771d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Customer.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Customer.php @@ -40,11 +40,22 @@ public function getHeaderText() */ public function getButtonsHtml() { - $addButtonData = [ + $html = ''; + + $addButtonData = array( 'label' => Mage::helper('sales')->__('Create New Customer'), 'onclick' => 'order.setCustomerId(false)', 'class' => 'add', - ]; - return $this->getLayout()->createBlock('adminhtml/widget_button')->setData($addButtonData)->toHtml(); + ); + $html .= $this->getLayout()->createBlock('adminhtml/widget_button')->setData($addButtonData)->toHtml(); + + $addButtonData = array( + 'label' => Mage::helper('sales')->__('Create Guest Order'), + 'onclick' => 'order.setCustomerIsGuest()', + 'class' => 'add', + ); + $html .= $this->getLayout()->createBlock('adminhtml/widget_button')->setData($addButtonData)->toHtml(); + + return $html; } } diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Account.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Account.php index b6afa08c143..77bfd65235c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Account.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Account.php @@ -68,6 +68,7 @@ protected function _prepareForm() } } + // if quote is guest, unset customer_group_id if ($this->getQuote()->getCustomerIsGuest()) { unset($attributes['group_id']); } diff --git a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php index cafa8ba1466..138b500194d 100644 --- a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php +++ b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php @@ -264,13 +264,15 @@ public function initFromOrder(Mage_Sales_Model_Order $order) } /** - * Check if we edit quest order + * Check if we edit guest order */ $session->setCurrencyId($order->getOrderCurrencyCode()); if ($order->getCustomerId()) { $session->setCustomerId($order->getCustomerId()); } else { $session->setCustomerId(false); + $session->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID); + $session->setCustomerIsGuest(true); } $session->setStoreId($order->getStoreId()); @@ -1261,6 +1263,10 @@ public function setAccountData($accountData) $data[$code] = $customer->getData($attribute->getAttributeCode()); } + if ($this->getQuote()->getCustomerIsGuest()) { + $data['customer_group_id'] = Mage_Customer_Model_Group::NOT_LOGGED_IN_ID; + } + if (isset($data['customer_group_id'])) { $groupModel = Mage::getModel('customer/group')->load($data['customer_group_id']); $data['customer_tax_class_id'] = $groupModel->getTaxClassId(); @@ -1374,9 +1380,6 @@ protected function _setCustomerData(Mage_Customer_Model_Customer $customer) public function _prepareCustomer() { $quote = $this->getQuote(); - if ($quote->getCustomerIsGuest()) { - return $this; - } /** @var Mage_Customer_Model_Customer $customer */ $customer = $this->getSession()->getCustomer(); @@ -1479,7 +1482,7 @@ public function _prepareCustomer() $this->_getCustomerForm() ->setEntity($customer) ->resetEntityData(); - } else { + } elseif ($customer->getGroupId() !== Mage_Customer_Model_Group::NOT_LOGGED_IN_ID) { $quote->setCustomerId(true); } diff --git a/app/code/core/Mage/Adminhtml/Model/Session/Quote.php b/app/code/core/Mage/Adminhtml/Model/Session/Quote.php index 0eee7f64036..07661a0fc4c 100644 --- a/app/code/core/Mage/Adminhtml/Model/Session/Quote.php +++ b/app/code/core/Mage/Adminhtml/Model/Session/Quote.php @@ -88,6 +88,13 @@ public function getQuote() if ($this->getStoreId() && $this->getQuoteId()) { $this->_quote->setStoreId($this->getStoreId()) ->load($this->getQuoteId()); + } elseif ($this->getStoreId() && $this->getCustomerIsGuest()) { + $this->_quote->setStoreId($this->getStoreId()) + ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID) + ->setCustomerIsGuest(true) + ->setIsActive(false) + ->save(); + $this->setQuoteId($this->_quote->getId()); } elseif ($this->getStoreId() && $this->hasCustomerId()) { $this->_quote->setStoreId($this->getStoreId()) ->setCustomerGroupId(Mage::getStoreConfig(self::XML_PATH_DEFAULT_CREATEACCOUNT_GROUP)) @@ -130,6 +137,9 @@ public function getCustomer($forceReload = false, $useSetStore = false) if ($customerId = $this->getCustomerId()) { $this->_customer->load($customerId); } + if ($this->getCustomerIsGuest()) { + $this->_customer->setGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID); + } } return $this->_customer; } diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php index 579d0875990..6438cd62fff 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php @@ -87,6 +87,14 @@ protected function _initSession() $this->_getSession()->setCustomerId((int) $customerId); } + /** + * Identify guest + */ + if ($customerIsGuest = $this->getRequest()->getParam('customer_is_guest')) { + $this->_getSession()->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID); + $this->_getSession()->setCustomerIsGuest(true); + } + /** * Identify store */ diff --git a/js/mage/adminhtml/sales.js b/js/mage/adminhtml/sales.js index 0838aac0d7b..1769c599c55 100644 --- a/js/mage/adminhtml/sales.js +++ b/js/mage/adminhtml/sales.js @@ -17,6 +17,7 @@ AdminOrder.prototype = { if(!data) data = {}; this.loadBaseUrl = false; this.customerId = data.customer_id ? data.customer_id : false; + this.isGuest = data.is_guest ? true : false; this.storeId = data.store_id ? data.store_id : false; this.currencyId = false; this.currencySymbol = data.currency_symbol ? data.currency_symbol : ''; @@ -94,6 +95,11 @@ AdminOrder.prototype = { this.addresses = addresses; }, + setCustomerIsGuest : function(){ + this.isGuest = true; + this.setCustomerId(false); + }, + setCustomerId : function(id){ this.customerId = id; this.loadArea('header', true); @@ -1033,6 +1039,9 @@ AdminOrder.prototype = { if (!params.customer_id) { params.customer_id = this.customerId; } + if (!params.customer_is_guest) { + params.customer_is_guest = this.isGuest ? 1 : 0; + } if (!params.store_id) { params.store_id = this.storeId; }