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 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
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.

113 changes: 108 additions & 5 deletions includes/commerce_pos.transaction.inc
Original file line number Diff line number Diff line change
Expand Up @@ -174,33 +174,49 @@ 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['search_type'] = array(
'#type' => 'radios',
'#options' => array(
'product' => t('Search or scan product'),
'order' => t('Search for Order ID'),
),
'#default_value' => 'product',
);

$form['order_search'] = array(
'#type' => 'container',
'#prefix' => '<div id="commerce-pos-return-order-search">',
'#tree' => TRUE,
'#suffix' => '</div>',
'#states' => array(
'visible' => array(
':input[name="search_type"]' => array('value' => 'order'),
),
),
);

$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('Search'),
'#ajax' => $wrapper_ajax,
'#element_key' => 'do-order-search',
'#validate' => array('_commerce_pos_order_search_validate'),
'#name' => 'do-order-search',
'#attributes' => array('class' => array('blue')),
);
}

Expand Down Expand Up @@ -232,6 +248,11 @@ function commerce_pos_transaction_form(&$form, &$form_state, $transaction_type)
'placeholder' => t('Product Search'),
),
'#element_validate' => array('_commerce_pos_transaction_validate_product_input'),
'#states' => array(
'visible' => array(
':input[name="search_type"]' => array('value' => 'product'),
),
),
);

$form['product_search']['product_sku'] = array(
Expand Down Expand Up @@ -799,7 +820,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 @@ -935,3 +956,85 @@ 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.
*
* This popup shows a checkbox next to each item for the user to add that item
* to the return transaction.
*
* @param $order
Copy link

@wilderuncat wilderuncat May 11, 2017

Choose a reason for hiding this comment

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

This is missing parameter type.

@param object $order

That should get travis to start passing this.

* The order entity.
*/
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 (isset($line_item_wrapper->type) && in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) {

// 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,
);
}
2 changes: 1 addition & 1 deletion modules/label/css/commerce_pos_label.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions sass/_sale.scss
Original file line number Diff line number Diff line change
Expand Up @@ -575,3 +575,66 @@
#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: -33px;
}
}

#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;
}
}
}
}
}

.form-radios {
.form-item {
display: inline-block;
width: 190px;

input {
width: 15px;
}

label {
display: inline-block;
vertical-align: text-bottom;
font-size: 14px;
}
}
}

input#edit-order-search-input {
width: 320px;
}
}
6 changes: 6 additions & 0 deletions theme/commerce-pos-transaction.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
<div class="commerce-pos-sale-container clearfix">
<div class="commerce-pos-col-products">
<div class="commerce-pos-product-search-container">
<?php if(isset($form['product_search']['onboarding_text'])): ?>
<?php print render($form['product_search']['onboarding_text']); ?>
<?php endif; ?>
<?php if(isset($form['search_type'])): ?>
<?php print render($form['search_type']); ?>
<?php endif; ?>
<?php print render($form['product_search']); ?>
<?php if(isset($form['order_search'])): ?>
<?php print render($form['order_search']); ?>
Expand Down