Вопрос

I'm trying to post a product with the mws api with ruby on rails and spree. But, always this message is displayed:

undefined method `sku' for #<Spree::Admin::MeController:0xce1cec0>

require 'mws-connect'

class Spree::Admin::MeController < Spree::Admin::ResourceController
      def index

        mws = Mws.connect(
            merchant: 'merchant',
            access: 'access',
            secret: 'secret'
        )

        sku = '12345678'
        product = Mws::Product sku {
          upc '123435566654'
          tax_code 'GEN_TAX_CODE'
          name 'Some Product 123'
          brand 'Some Brand'
          msrp 19.99, 'USD'
          manufacturer 'Some Manufacturer'
          category :ce
          details {
            cable_or_adapter {
              cable_length as_distance 5, :feet
            }
          }
        }
        submission_id = mws.feeds.products.add(product)
        result = mws.feeds.get(submission_id)
        puts "Submission: #{result.transaction_id} - #{result.status}"

      end

can someone helpme?

Это было полезно?

Решение

Your syntax isn't doing what you want to be doing. In this section:

    product = Mws::Product sku {
      upc '123435566654'
      tax_code 'GEN_TAX_CODE'
      name 'Some Product 123'
      brand 'Some Brand'
      msrp 19.99, 'USD'
      manufacturer 'Some Manufacturer'
      category :ce
      details {
        cable_or_adapter {
          cable_length as_distance 5, :feet
        }
      }
    }

you are encountering an error due to the ambiguous parameters being passed. Ruby is having trouble figuring out which function to call. If you think about it like this.

product = Mws::Product(sku(bunch of stuff))

This is what you're doing. It's trying to call a function sku and pass the results to Mws::Product. Since the function sku doesn't exist, it's failing.

You'll want to familiarize yourself with the syntax of ruby, as this block of code is not valid Ruby syntax. You can see some syntax examples for a Hash at http://www.ruby-doc.org/core-2.0/Hash.html

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top