Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: Allow admin to create guest orders and reorder as guest #2233

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if it's not part of the change wouldn't it be better to be here "Create Customer Order"? In doesn't matter if is a New Customer or a Registered one. At least we keep two buttons with a clear message:

[Create Customer Order] [Create Guest Order]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ADDISON74 the first button really creates a new customer so I think it can be left as it is

$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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protected function _prepareForm()
}
}

// if quote is guest, unset customer_group_id
if ($this->getQuote()->getCustomerIsGuest()) {
unset($attributes['group_id']);
}
Comment on lines +71 to 74
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should read:

// if quote is guest, unset group_id dropdown

As it removes the customer group dropdown on the order create screen if we're creating a guest order. I will change and push.

Expand Down
13 changes: 8 additions & 5 deletions app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}

fballiano marked this conversation as resolved.
Show resolved Hide resolved
if (isset($data['customer_group_id'])) {
$groupModel = Mage::getModel('customer/group')->load($data['customer_group_id']);
$data['customer_tax_class_id'] = $groupModel->getTaxClassId();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1479,7 +1482,7 @@ public function _prepareCustomer()
$this->_getCustomerForm()
->setEntity($customer)
->resetEntityData();
} else {
} elseif ($customer->getGroupId() !== Mage_Customer_Model_Group::NOT_LOGGED_IN_ID) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also check !$quote->getCustomerIsGuest() instead of checking $customer->getGroupId().

I chose the latter because the if was also checking the $customer object, but the former is maybe better since it's the same as the conditional I removed at the top of the method. I may push this as a change.

$quote->setCustomerId(true);
}

Expand Down
10 changes: 10 additions & 0 deletions app/code/core/Mage/Adminhtml/Model/Session/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
9 changes: 9 additions & 0 deletions js/mage/adminhtml/sales.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : '';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
Loading