Skip to content

Commit

Permalink
Offline orders with out of stock products don't stack anymore and get…
Browse files Browse the repository at this point in the history
… canceled after going back to online - closes #2740
  • Loading branch information
lukeromanowicz committed Apr 26, 2019
1 parent 4183e69 commit b3813f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- "Toggle password visible" button in password fields works the right way - @lromanowicz (#2772)
- Range queries to elasticsearch - @oskar1233 (#2746)
- BaseInput has min height now to avoid jumping on forms - @patzick (#2771)
- Orders with invalid address don't stack anymore and have proper notification popup - @AndreiBelokopytov, @lukeromanowicz (#2663)
- Orders with invalid address don't stack anymore in the queue and have proper notification popup - @AndreiBelokopytov, @lukeromanowicz (#2663)
- Offline orders with out of stock products don't stack anymore and get canceled after going back to online - @lukeromanowicz (#2740)

## [1.9.0-rc.2] - 2019.04.10

Expand Down
26 changes: 24 additions & 2 deletions core/client-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ const invokeClientEntry = async () => {
const orderId = id

Logger.log('Pushing out order ' + orderId)()
/** @todo refactor order synchronisation to proper handling through vuex actions to avoid code duplication */
return fetch(config.orders.endpoint,
{
method: 'POST',
Expand All @@ -162,10 +163,31 @@ const invokeClientEntry = async () => {
}
})
.then(jsonResponse => {
if (jsonResponse && jsonResponse.code === 200) {
if (jsonResponse) {
Logger.info('Response for: ' + orderId + ' = ' + JSON.stringify(jsonResponse.result))()
orderData.transmited = true
orderData.transmited = true // by default don't retry to transmit this order
orderData.transmited_at = new Date()

if (jsonResponse.code !== 200) {
Logger.error(jsonResponse, 'order-sync')()

if (jsonResponse.code === 400) {
rootStore.dispatch('notification/spawnNotification', {
type: 'error',
message: i18n.t('Address provided in checkout contains invalid data. Please check if all required fields are filled in and also contact us on {email} to resolve this issue for future. Your order has been canceled.', { email: config.mailer.contactAddress }),
action1: { label: i18n.t('OK') }
})
} else if (jsonResponse.code === 500 && jsonResponse.result === "Error: Error while adding products") {

This comment has been minimized.

Copy link
@pkarw

pkarw Apr 26, 2019

Collaborator

Not sure, but we probably should have i18n.t('Error: Error while adding products') just in case somebody has localized error messages in Magento

rootStore.dispatch('notification/spawnNotification', {
type: 'error',
message: i18n.t('Some products you\'ve ordered are out of stock. Your order has been canceled.'),
action1: { label: i18n.t('OK') }
})
} else {
orderData.transmited = false // probably some server related error. Enqueue
}
}

ordersCollection.setItem(orderId.toString(), orderData)
} else {
Logger.error(jsonResponse)()
Expand Down

0 comments on commit b3813f4

Please sign in to comment.