Skip to content
Permalink
Browse files

Fixed reverse bug

  • Loading branch information...
arobbins committed Jun 12, 2019
1 parent 10c051c commit 5df7f308ff08bdf49712b858e2ca101d6e2bcf02
Showing with 37 additions and 46 deletions.
  1. +20 −9 src/checkout/index.js
  2. +17 −31 src/client/index.js
  3. +0 −4 src/errors/index.js
  4. +0 −2 src/products/index.js
@@ -1,5 +1,6 @@
import { buildClient } from '../client'
import to from 'await-to-js'
import isEmpty from 'lodash/isEmpty'
import { buildClient } from '../client'
import { getCache, setCache } from '../cache'
import { fetchShopInfo } from '../shop'
import { maybeAlterErrorMessage } from '../errors'
@@ -26,15 +27,25 @@ function removeAllLineItems(client, checkout) {
}

function updateCheckoutAttributesAPI(client, checkout, customAttributes = false, note = false) {
console.log('ddddddddddddddddd', {
customAttributes: customAttributes,
note: note
})
let attributes = {}

return client.checkout.updateAttributes(checkout.id, {
customAttributes: customAttributes,
note: note
})
if (!isEmpty(customAttributes)) {
attributes.customAttributes = customAttributes
}

if (note) {
let trimmedNote = note.trim()

if (!isEmpty(trimmedNote)) {
attributes.note = trimmedNote
}
}

if (isEmpty(attributes)) {
return new Promise((resolve, reject) => resolve(checkout))
}

return client.checkout.updateAttributes(checkout.id, attributes)
}

function addLineItemsAPI(client, checkout, lineItems) {
@@ -1,7 +1,7 @@
import Client from 'shopify-buy';
import to from 'await-to-js';
import { noticeConfigBadCredentials } from '../notices/notices';
import { getCache, setCache } from '../cache';
import Client from 'shopify-buy'
import to from 'await-to-js'
import { noticeConfigBadCredentials } from '../notices/notices'
import { getCache, setCache } from '../cache'

/*
@@ -10,62 +10,48 @@ upon initial bootstrap for ease of use.
*/
function clientActive(client) {

if (!client) {
return false;
return false
}

return true;

return true
}

function getClient() {
return getCache('wps-client');
return getCache('wps-client')
}

function setClient(client) {
setCache('wps-client', client)

setCache('wps-client', client);

return client;

return client
}


function initClient(config) {

return Client.buildClient({
domain: config.domain,
storefrontAccessToken: config.storefrontAccessToken
});

})
}

function buildClient() {

const creds = WP_Shopify.storefront;
const creds = WP_Shopify.storefront

// If client cached, just return it
if (clientActive(WP_Shopify.client)) {
console.log('buildClient 4');
return getClient();
return getClient()
}

if (!creds) {
console.log('buildClient 6');
return noticeConfigBadCredentials();
return noticeConfigBadCredentials()
}

// If creds look good, build the Client!
const client = initClient(creds);

setClient(client);
const client = initClient(creds)

return client;
setClient(client)

return client
}


export {
buildClient
}
export { buildClient }
@@ -2,8 +2,6 @@ import isString from 'lodash/isString'
import isError from 'lodash/isError'

function findErrorMessage(maybeErrorMessage) {
console.log('maybeErrorMessage', maybeErrorMessage)

let finalErrorMessage = ''

if (isString(maybeErrorMessage)) {
@@ -25,8 +23,6 @@ function maybeAlterErrorMessage(errorMessage) {
let finalError = ''
let foundErrorMessage = findErrorMessage(errorMessage)

console.log('foundErrorMessage', foundErrorMessage)

switch (foundErrorMessage) {
case 'TypeError: Failed to fetch':
finalError = 'Uh oh, it looks like your Shopify credentials are incorrect. Please double check your domain and storefront access token within the plugin settings and try again.'
@@ -214,8 +214,6 @@ function refetchQuery(node) {

function graphQuery(type, queryParams, connectionParams = false) {
return new Promise(async (resolve, reject) => {
console.log('queryParams', queryParams)

if (!queryParams) {
return reject(maybeAlterErrorMessage('Uh oh, it looks your query params are invalid. Please clear your browser cache and reload the page.'))
}

0 comments on commit 5df7f30

Please sign in to comment.
You can’t perform that action at this time.