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 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
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

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;
fballiano marked this conversation as resolved.
Show resolved Hide resolved
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,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 @@ -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());
Expand Down Expand Up @@ -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;
}

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 @@ -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();
Expand Down Expand Up @@ -1490,7 +1493,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
13 changes: 12 additions & 1 deletion app/code/core/Mage/Adminhtml/Model/Session/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -110,7 +118,7 @@ public function setCustomer(Mage_Customer_Model_Customer $customer)
return $this;
}

/**
/**
* Retrieve customer model object
* @param bool $forceReload
* @param bool $useSetStore
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Sales/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ public function canReorderIgnoreSalable()
*/
protected function _canReorder($ignoreSalable = false)
{
if ($this->canUnhold() || $this->isPaymentReview() || !$this->getCustomerId()) {
if ($this->canUnhold() || $this->isPaymentReview()) {
fballiano marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

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 @@ -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 : '';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down