Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integração com o Solidus #42

Open
pailoro opened this issue Dec 16, 2019 · 2 comments
Open

Integração com o Solidus #42

pailoro opened this issue Dec 16, 2019 · 2 comments

Comments

@pailoro
Copy link

pailoro commented Dec 16, 2019

Olá, estou fazendo um projeto utilizando o Solidus no Rails, estou tentando integrar essa gem pra poder fazer o calculo do frete, mas o campo do cep para calcular nao aparece nem na pagina do produto nem no carrinho. Alguém já trabalhou com essa gem antes ou conhece outra forma de integração com os correios?

Quando vou no admin, na parte do envio recebo este erro:

The single-table inheritance mechanism failed to locate the subclass:
'Spree::Calculator::Shipping::CorreiosApi'. This error is raised
because the column 'type' is reserved for storing the class in case of
inheritance. Please rename this column if you didn't intend it to be
used for storing the inheritance class or overwrite
Spree::Calculator.inheritance_column to use another column for that
information.

Segue meu código.

Obrigado.

config/initializers/spree.rb

Rails.application.config.spree.calculators.shipping_methods << Spree::Calculator::Shipping::Correios

mode/spree/calculator/shippping/correios.rb

require 'correios-frete'
require_dependency 'spree/calculator'
require_dependency 'spree/shipping_calculator'

module Spree
  module Calculator::Shipping
    class Correios < ShippingCalculator
      preference :api_key, :string

      def compute_package(_package)
        # binding.pry
        calcula

        9090.90
      end

      def self.description
        "Correios API"
      end


      def calcula
        # binding.pry
        frete = Correios::Frete::Calculador.new :cep_origem => "22790-671",
                                                :cep_destino => "06783-090",
                                                :peso => 7.3,
                                                :comprimento => 30,
                                                :largura => 20,
                                                :altura => 35

        servicos = frete.calcular :sedex, :pac
        # binding.pry
      end
    end
  end
end
@CristopherVidalMachado
Copy link

Alguma solução por aqui?

@CristopherVidalMachado
Copy link

`require 'correios-frete'
module Spree
class Calculator::Shipping::CustomShippingCalculator < Spree::ShippingCalculator
def self.description
"Envio de pacotes via Sedex"
end

  def compute_package(package)
    p "gangnamsyle"
    p package
    frete = Correios::Frete::Calculador.new :cep_origem => "22790-671",
    :cep_destino => "06783-090",
    :peso => 7.3,
    :comprimento => 30,
    :largura => 20,
    :altura => 35
    
    sedex = frete.calcular :sedex
    sedex.valor
    
  end

def available?(order)
    order.currency == "BRL"
  end
end

end



Isso é o mais próximo que cheguei disto estar funcionando.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants