-
Notifications
You must be signed in to change notification settings - Fork 256
Issue #2861002 by mglaman: Coupon redemption form needs severe improv… #678
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
Issue #2861002 by mglaman: Coupon redemption form needs severe improv… #678
Conversation
if ($triggering_element['#name'] == 'remove_coupon') { | ||
$order->get('coupons')->setValue([]); | ||
$order->save(); | ||
drupal_set_message(t('Coupon applied')); |
There was a problem hiding this comment.
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')); |
There was a problem hiding this comment.
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')); | ||
} |
There was a problem hiding this comment.
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.
57dc196
to
03214ae
Compare
$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.'); |
There was a problem hiding this comment.
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'], |
There was a problem hiding this comment.
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?
7579e3e
to
ee5a83c
Compare
'#name' => 'apply_coupon', | ||
'#limit_validation_errors' => [ | ||
$element['#parents'], | ||
array_merge($element['#parents'], ['code']), |
There was a problem hiding this comment.
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.
…ements and bug fixes
ee5a83c
to
36c37d2
Compare
…ements and bug fixes (drupalcommerce#678)
…ements and bug fixes