@@ -28,6 +28,7 @@ import (
2828 "strconv"
2929 "strings"
3030 "time"
31+
3132 jww "github.com/spf13/jwalterweatherman"
3233)
3334
@@ -39,13 +40,15 @@ const (
3940type Shopify struct {
4041 shopifyDomain string
4142 shopifySecretToken string
43+ // we need the public Store URL because with Redirect shipping_rates.json doesn't work
44+ shopifyPublicURL string
4245
4346 Products []Product
4447}
4548
4649// NewClient inits shopify client
47- func NewClient (domain string , secrettoken string ) Shopify {
48- shop := Shopify {shopifyDomain : domain , shopifySecretToken : secrettoken }
50+ func NewClient (domain string , secrettoken string , publicURL string ) Shopify {
51+ shop := Shopify {shopifyDomain : domain , shopifySecretToken : secrettoken , shopifyPublicURL : publicURL }
4952 return shop
5053}
5154
@@ -191,11 +194,10 @@ func (shopifyClient *Shopify) ShippingOptions(order Order) ([]ShippingRate, erro
191194
192195 urlStr = urlStr + v .Encode ()
193196
194- completeURL = fmt .Sprintf ("https:// %s%s%s " , shopifyClient .shopifyDomain , baseURLString , urlStr )
197+ completeURL = fmt .Sprintf ("%s%s" , shopifyClient .shopifyPublicURL , urlStr )
195198 jww .INFO .Printf ("[ShippingOptions] - Request URL: %s" , completeURL )
196199
197200 r , err = http .NewRequest ("GET" , completeURL , nil )
198-
199201 resp , err = client .Do (r )
200202
201203 defer resp .Body .Close ()
@@ -213,6 +215,11 @@ func (shopifyClient *Shopify) ShippingOptions(order Order) ([]ShippingRate, erro
213215 return shopifyResponse .ShippingRates , err
214216 }
215217
218+ if shopifyResponse .Error != nil {
219+ genericError := errors .New (strings .Join (shopifyResponse .Error , ", " ))
220+ return shopifyResponse .ShippingRates , genericError
221+ }
222+
216223 // Address not supported error handling
217224 if shopifyResponse .Country != nil || shopifyResponse .Zip != nil || shopifyResponse .Province != nil {
218225 var errorsArray []string
0 commit comments