         externalId: externalId
       ]
     rest.POST "/orders/#{orderId}", data, (error, response, body) ->
-      if error
+      if error?
         deferred.reject "Error on setting sync info: " + error
       else if response.statusCode isnt 200
         humanReadable = JSON.stringify body, null, ' '

        channelID = channel.id
        return true
      return channelID is channel.id
    if order.lineItems
      for li in order.lineItems
        if li.supplyChannel
          return false unless checkChannelId li.supplyChannel
        continue unless li.variant
        continue unless li.variant.prices
        for p in li.variant.prices
          if p.channel
            return false unless checkChannelId p.channel
    true


  distribute: (masterOrder) ->
    masterSKUs = @extractSKUs masterOrder

    @getTaxCategory(@retailerRest)
    .then (taxCategory) =>

      gets = _.map masterSKUs, (sku) =>
        @getRetailerProductByMasterSKU(sku)

      Q.all(gets)
      .then (retailerProducts) =>
        masterSKU2retailerSKU = @matchSKUs retailerProducts

        retailerOrder = @replaceSKUs masterOrder, masterSKU2retailerSKU
        retailerOder = @replaceTaxCategories retailerOrder, taxCategory
        retailerOrder = @removeIdsAndVariantData retailerOrder

        @importOrder(retailerOrder)
      .then (newOrder) =>
        Q.all([
          @inventoryUpdater.ensureChannelByKey @masterRest, @retailerRest._options.config.project_key, CHANNEL_ROLES
          @inventoryUpdater.ensureChannelByKey @retailerRest, 'master', CHANNEL_ROLES
        ])
        .spread (channelInMaster, channelInRetailer) =>
          Q.all([
            @addSyncInfo(@masterRest, masterOrder.id, masterOrder.version, channelInMaster.id, newOrder.id)
            @addSyncInfo(@retailerRest, newOrder.id, newOrder.version, channelInRetailer.id, masterOrder.id)
          ])

  matchSKUs: (retailerProducts) ->
    allVariants = _.flatten _.map(retailerProducts, (p) -> [p.masterVariant].concat(p.variants or []))
