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

Feature: Search by order number for return transactions. #43

Open
wants to merge 7 commits into
base: 7.x-2.x
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion css/commerce_pos_style.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion css/commerce_pos_style.css.map

Large diffs are not rendered by default.

88 changes: 83 additions & 5 deletions includes/commerce_pos.transaction.inc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function commerce_pos_transaction_form(&$form, &$form_state, $transaction_type)
unset($form_state['lookup_result']);
}

// Let's add a order search textfield if we're in a return transaction so the
// Let's add an order search textfield if we're in a return transaction so the
// user could easily pick out which items from the order needs to be returned.
if ($return) {
$form['order_search'] = array(
Expand All @@ -183,23 +183,24 @@ function commerce_pos_transaction_form(&$form, &$form_state, $transaction_type)
'#tree' => TRUE,
'#suffix' => '</div>',
);

$form['order_search']['input'] = array(
'#type' => 'textfield',
'#title' => '',
'#size' => 60,
'#description' => t('Search by order ID to load the items in an order.<br>(Note: This does not support searching for Order Number.)'),
'#description' => t('Search by order number to load the items in an order.'),
'#attributes' => array(
'placeholder' => t('Order Search'),
),
'#element_validate' => array('element_validate_integer_positive'),
'#default_value' => !empty($form_state['values']['order_search']['input']) ? $form_state['values']['order_search']['input'] : NULL,
);

$form['order_search']['search'] = array(
'#type' => 'button',
'#value' => t('Go'),
'#value' => t('Return items from this order'),

Choose a reason for hiding this comment

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

This seems a little long to me... Maybe something like "Lookup Order" would be more succinct?

Copy link
Author

Choose a reason for hiding this comment

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

This title was suggested by @travis-bradbury , to make it clear to the user. So might need to get a consensus on this one.

Choose a reason for hiding this comment

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

I'll yield to travis, he is a better authority here than me.

Choose a reason for hiding this comment

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

I'm not saying "Return items from this order" is the best. It is a little long. I just wanted something that describes what the user is trying to do.

'#ajax' => $wrapper_ajax,
'#element_key' => 'do-order-search',
'#validate' => array('_commerce_pos_order_search_validate'),
'#name' => 'do-order-search',
);
}
Expand Down Expand Up @@ -800,7 +801,7 @@ function commerce_pos_transaction_ajax_check(&$form, &$form_state) {
break;

case 'do-order-search':
$order = commerce_order_load($form_state['input']['order_search']['input']);
$order = commerce_order_load_by_number($form_state['input']['order_search']['input']);
// If we have got a valid order display the item in the order in a
// modal.
if ($order) {
Expand Down Expand Up @@ -936,3 +937,80 @@ function _commerce_pos_override_confirm_validate($form, &$form_state) {
// Add the product to the overridden items list.
$form_state['out_of_stock_overridden_products'][$form_state['triggering_element']['#product_id']] = $form_state['triggering_element']['#product_id'];
}

/**
* Returns a modal form displaying each item in an order along with a checkbox

Choose a reason for hiding this comment

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

The docblock should have a one-line summary under 80 characters long. Then a longer description underneath. Also, it would be useful to include the $order as a @param

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, will do.

* for the user to add that item to the return transaction.
*/
function commerce_pos_return_select_item_popup(&$form, &$form_state, $order) {

// Load our generic modal form.
$form['commerce_pos_return_select_item_modal'] = commerce_pos_form_modal(array(

Choose a reason for hiding this comment

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

Do you also need to do

form_load_include($form_state, 'inc', 'commerce_pos', 'includes/commerce_pos.common');

before this to make sure it is included?

Copy link
Author

Choose a reason for hiding this comment

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

Nope, we don't need it. It works right out of the box :)

Choose a reason for hiding this comment

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

I'm a bit curious why it works though... Maybe another form in the same request is including it. But what if this form is called alone? Would it still work? Would it hurt to include it twice? Might be better to be explicit. But I haven't tested it so not sure.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I didn't give too much thought into it. Travis would be able to answer this quickly as he did the restructuring for the generic modal.

'closeable' => TRUE,
'throbber' => FALSE
));

// Initialize variables.
$options = array();
$line_items = array();

// Go through each item in the order and generate the html for the items
// display.
foreach (entity_metadata_wrapper('commerce_order', $order)->commerce_line_items as $delta => $line_item_wrapper) {
if (in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) {

Choose a reason for hiding this comment

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

I've found it best to first check if $line_item_wrapper->type exists before checking the value. I've seen many orders / line items get corrupted and things like this result in a 500 error.

Copy link
Author

Choose a reason for hiding this comment

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

👍


// Load the product.
$product_sku = $line_item_wrapper->commerce_product->sku->value();
if (!empty($product_sku) && $product = $line_item_wrapper->commerce_product->value()) {

// Add all the items one by one to our markup variable so we can add
// that to the checkboxes element below.
$markup = '';

if ($image = _commerce_pos_product_thumbnail($product)) {
$markup .= '<div class="commerce-pos-return-product-image">' . $image . '</div>';
}

$markup .= '<div class="commerce-pos-return-product-info"><div class="commerce-pos-return-product-title">' . $product->title_field[LANGUAGE_NONE][0]['safe_value'] . '</div>';

$markup .= '<div class="commerce-pos-return-product-sku">' . t('SKU: @sku', array('@sku' => $product_sku)) . '</div>';

// Make sure we display the actual price paid to account for any
// discounts the user might have received.
$markup .= '<div class="commerce-pos-return-product-price-paid">'
. t('Price Paid/Per Item: @price', array('@price' => commerce_currency_format($line_item_wrapper->commerce_unit_price->value()['amount'], $line_item_wrapper->commerce_unit_price->value()['currency_code'])))
. '</div></div>';

// Add the markup to the checkboxes options to add below.
$options[$product_sku] = $markup;

// Add the line items indexed by sku to the products array so we can add
// it to our close element.
$line_items[$product_sku] = $line_item_wrapper;
}
}
}

// Add a checkboxes element that will display each product in the order.
$form['commerce_pos_return_select_item_modal']['modal']['return_items'] = array(
'#title' => t('Check the items that need to be returned'),
'#type' => 'checkboxes',
'#options' => $options,
'#weight' => 0,
);

// Add our close button which will add all the items that were selected to
// be returned to the return transaction.
$form['commerce_pos_return_select_item_modal']['modal']['add'] = array(
'#type' => 'button',
'#value' => t('Add'),
'#ajax' => array(
'callback' => 'commerce_pos_transaction_wrapper_js',
'wrapper' => 'commerce-pos-sale-wrapper',
),
'#element_key' => 'return-items-add',
'#name' => 'return-items-add',
'#line_items' => $line_items,
'#weight' => 1,
);
}
199 changes: 199 additions & 0 deletions pos-return-order-search-2772927-19 (1).patch

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions sass/_sale.scss
Original file line number Diff line number Diff line change
Expand Up @@ -575,3 +575,45 @@
#commerce-pos-product-no-results-message {
text-align: center;
}

/** Styling for return order search. **/
#commerce-pos-sale-wrapper {
#commerce-pos-return-order-search {
.form-type-textfield {
display: inline-block;
}

.form-submit {
display: inline-block;
position: relative;
top: -35px;
}
}

#commerce-pos-form-modal-modal {
height: auto !important;
}

.form-item-return-items {
.form-type-checkbox {
margin: 5px;

.commerce-pos-return-product-image, .commerce-pos-return-product-info {
display: inline-block;
margin: 0px 20px;
vertical-align: text-top;

&.commerce-pos-return-product-info {
position: relative;
vertical-align: top;
text-align: left;
width: 40%;

.commerce-pos-return-product-title {
font-weight: bold;
}
}
}
}
}
}