From 2a5713c04b0afc2038c000bb97737ae9e25a91de Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 21 Jun 2022 08:34:52 -0700 Subject: [PATCH 1/2] Allow admin guest order and reorder --- .../Adminhtml/Block/Sales/Order/Create/Customer.php | 13 ++++++++++++- .../Block/Sales/Order/Create/Form/Account.php | 1 + .../Mage/Adminhtml/Model/Sales/Order/Create.php | 13 ++++++++----- .../core/Mage/Adminhtml/Model/Session/Quote.php | 13 ++++++++++++- .../controllers/Sales/Order/CreateController.php | 8 ++++++++ app/code/core/Mage/Sales/Model/Order.php | 2 +- js/mage/adminhtml/sales.js | 9 +++++++++ 7 files changed, 51 insertions(+), 8 deletions(-) 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 0f02300f949..cda010dfde3 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 @@ -48,12 +48,23 @@ public function getHeaderText() public function getButtonsHtml() { + $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 974bd36ad78..77b12232eb5 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 @@ -78,6 +78,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 04139fd7fd4..1828154d662 100644 --- a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php +++ b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php @@ -274,13 +274,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()); @@ -1266,6 +1268,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(); @@ -1380,9 +1386,6 @@ public function _prepareCustomer() { /** @var $quote Mage_Sales_Model_Quote */ $quote = $this->getQuote(); - if ($quote->getCustomerIsGuest()) { - return $this; - } /** @var $customer Mage_Customer_Model_Customer */ $customer = $this->getSession()->getCustomer(); @@ -1490,7 +1493,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 4e1cf54bb72..a38374eb396 100644 --- a/app/code/core/Mage/Adminhtml/Model/Session/Quote.php +++ b/app/code/core/Mage/Adminhtml/Model/Session/Quote.php @@ -84,6 +84,14 @@ public function getQuote() $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)) @@ -110,7 +118,7 @@ public function setCustomer(Mage_Customer_Model_Customer $customer) return $this; } -/** + /** * Retrieve customer model object * @param bool $forceReload * @param bool $useSetStore @@ -126,6 +134,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 d79eb6b3b2d..5f077749885 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php @@ -99,6 +99,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/app/code/core/Mage/Sales/Model/Order.php b/app/code/core/Mage/Sales/Model/Order.php index ad23b81ec2b..aaaeafe79ba 100644 --- a/app/code/core/Mage/Sales/Model/Order.php +++ b/app/code/core/Mage/Sales/Model/Order.php @@ -890,7 +890,7 @@ public function canReorderIgnoreSalable() */ protected function _canReorder($ignoreSalable = false) { - if ($this->canUnhold() || $this->isPaymentReview() || !$this->getCustomerId()) { + if ($this->canUnhold() || $this->isPaymentReview()) { return false; } diff --git a/js/mage/adminhtml/sales.js b/js/mage/adminhtml/sales.js index 1b1445f8062..fb0f3b6bd11 100644 --- a/js/mage/adminhtml/sales.js +++ b/js/mage/adminhtml/sales.js @@ -28,6 +28,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 : ''; @@ -105,6 +106,11 @@ AdminOrder.prototype = { this.addresses = addresses; }, + setCustomerIsGuest : function(){ + this.isGuest = true; + this.setCustomerId(false); + }, + setCustomerId : function(id){ this.customerId = id; this.loadArea('header', true); @@ -1044,6 +1050,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; } From 14be50bd6323db7226040b7851ef64ad85383221 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Wed, 14 Feb 2024 14:40:59 +0000 Subject: [PATCH 2/2] phpcs --- app/code/core/Mage/Adminhtml/Model/Session/Quote.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/Model/Session/Quote.php b/app/code/core/Mage/Adminhtml/Model/Session/Quote.php index b6a274a18d0..07661a0fc4c 100644 --- a/app/code/core/Mage/Adminhtml/Model/Session/Quote.php +++ b/app/code/core/Mage/Adminhtml/Model/Session/Quote.php @@ -88,15 +88,14 @@ public function getQuote() if ($this->getStoreId() && $this->getQuoteId()) { $this->_quote->setStoreId($this->getStoreId()) ->load($this->getQuoteId()); - } - elseif($this->getStoreId() && $this->getCustomerIsGuest()) { + } 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()) { + } elseif ($this->getStoreId() && $this->hasCustomerId()) { $this->_quote->setStoreId($this->getStoreId()) ->setCustomerGroupId(Mage::getStoreConfig(self::XML_PATH_DEFAULT_CREATEACCOUNT_GROUP)) ->assignCustomer($this->getCustomer())