Skip to content

Conversation

mglaman
Copy link
Contributor

@mglaman mglaman commented Mar 16, 2017

…ements and bug fixes

if ($triggering_element['#name'] == 'remove_coupon') {
$order->get('coupons')->setValue([]);
$order->save();
drupal_set_message(t('Coupon applied'));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Order should only be saved in rebuildForm (rename it) when element button clicked.

if (self::couponApplies($order, $promotion, $coupon)) {
$order->get('coupons')->appendItem($coupon);
$order->save();
drupal_set_message(t('Coupon applied'));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Order should only be saved in rebuildForm (rename it) when element button clicked.

$order->get('coupons')->appendItem($coupon);
$order->save();
drupal_set_message(t('Coupon applied'));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Allow this text to be customized.

@mglaman mglaman force-pushed the 2861002-redemption-fixes branch 2 times, most recently from 57dc196 to 03214ae Compare March 16, 2017 18:56
$order_storage = \Drupal::entityTypeManager()->getStorage('commerce_order');
$order = $order_storage->load($element['#order_id']);
if (!$order instanceof OrderInterface) {
throw new \InvalidArgumentException('The commerce_coupon_redemption_form #order_id property must be an existing order entity.');
Copy link
Contributor

Choose a reason for hiding this comment

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

This argument message is misleading, need to be clear that we need the ID of an existing order, and not the .order itself. "The commerce_coupon_redemption #order_id must be a valid order ID." ?

array_merge($element['#parents'], ['code']),
],
'#submit' => [
[get_called_class(), 'elementButtonSubmit'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not call elementButtonSubmit and elementButtonRemove closer to what they do? applyCoupon and removeCoupon?

@mglaman mglaman force-pushed the 2861002-redemption-fixes branch 3 times, most recently from 7579e3e to ee5a83c Compare March 16, 2017 20:00
'#name' => 'apply_coupon',
'#limit_validation_errors' => [
$element['#parents'],
array_merge($element['#parents'], ['code']),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to pass $element['#parents'] to ensure submit callback has proper values. Maybe we can kill second line.

@mglaman mglaman force-pushed the 2861002-redemption-fixes branch from ee5a83c to 36c37d2 Compare March 16, 2017 23:26
@bojanz bojanz merged commit 3bcfdef into drupalcommerce:8.x-2.x Mar 17, 2017
@mglaman mglaman deleted the 2861002-redemption-fixes branch March 17, 2017 12:48
bradjones1 pushed a commit to bradjones1/commerce that referenced this pull request May 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants