Git Product home page Git Product logo

prestashop's Introduction

Prestashop

Build Status Code Climate Test coverage Version Dependencies

Prestashop API for Ruby

Is extrected from service used for synchronization suppliers catalogue with Prestashop Cloud via API on client side available here https://syncmystore.com/en

Installation

Add this line to your application's Gemfile:

gem 'prestashop', github: 'werein/prestashop'

Use branch: 'master' for local repository in case of bundler global config

Usage

Create new client for connect to your Prestashop WebService

Prestashop::Client::Implementation.create 'api_key', 'api_url'

Now you are able to communicate with Prestashop WebService

Low-level API

To call API request directly you can use this class.

Head / Check

Call HEAD on WebService API, returns +true+ if was request successfull or raise error, when request failed.

Prestashop::Client.head :customer, 2 # => true
Prestashop::Client.check :customer, 3 # => true
Get / Read

Call GET on WebService API, returns parsed Prestashop response or raise error, when request failed.

Prestashop::Client.get :customer, 1       # => {id: 1 ...}
Prestashop::Client.read :customer, [1,2]  # => [{id: 1}, {id: 2}]

When you are using get, you can also filter, sort or limit response. In case, when you need to get all users you need to set user id as nil

Available options:

  • filter
  • display
  • sort
  • limit
  • schema
  • date
Post / Create

Call POST on WebService API, returns parsed Prestashop response if was request successfull or raise error, when request failed.

Prestashop::Client.post :customer, { name: 'Steve' } # => true
Put / Update

Call PUT on WebService API, returns parsed Prestashop response if was request successfull or raise error, when request failed.

Prestashop::Client.put :customer, 1, {surname: 'Jobs'} # => true
Prestashop::Client.update :customer, 1, {nope: 'Jobs'} # => false
Delete / Destroy

Call DELETE on WebService API, returns +true+ if was request successfull or raise error, when request failed.

Prestashop::Client.delete :customer, 1 # => true

Mapper

Please read inline docs inside lib/prestashop/mapper/extension.rb, available models are defined in lib/prestashop/mapper/models

After reading that you can do something like this

id_lang = Prestashop::Mapper::Language.find_by_iso_code('cs')
id_supplier = Prestashop::Mapper::Supplier.new(name: 'apple').find_or_create

product = Prestashop::Mapper::Product.new(id_lang: id_lang, id_supplier: id_supplier, reference: 'apple-macbook')

if product.find?
  product.update price: '1299'
else
  product.description = 'My description'
  product.price = '1299'
  product.create
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

prestashop's People

Contributors

giomessina avatar jirikolarik avatar peterklogborg avatar plugowski avatar xykox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

prestashop's Issues

Typo in gemspec (homepage url)

Hi,
Just a quick notice: you have a typo in your gemspec, so the URL on rubygems.org pointing to the guides is wrong.
cheers!
Marian

product variants?

Does the API support a full import/export of products including variants and maybe even images yet?
Looks like that's the "product options" case, right?

Order with multiple cart_items

Hi,

I know that you was already surprised that someone is still using that repository but yeah, and I have new problem.

I want to create an order so I'm using Prestashop::Api::Converter.build to create proper payload but I have a problem when I want to build couple the same XML elements like under cart_items:

<cart_rows>
   <cart_row/>
   <cart_row/>
   <cart_row/>
   <cart_row/>
</cart_rows>

So I tried to pass array as items, but it doesn't work :(

cart_rows = []
      order.order_products.each do |product|
        cart_rows.push({
           id_product: product.product_id,
           quantity: product.qty
         })
      end

{
          id_shop: 1,
          id_customer: customer[:customer][:id],
          id_currency: currency_id,
          id_lang: language_id,
          id_address_delivery: address[:address][:id],
          id_address_invoice: address[:address][:id],
          id_carrier: carrier_id,
          secure_key: customer[:customer][:secure_key],
          associations: {
              cart_rows: cart_rows
          }
      }

And of course I cant create hash with the same symbols, do you have any solution for that?

can't add manufacturer with special symbols in name

For creating manufacturer with name "D & G" i use this code (with PS 1.6):

manufacturer = Prestashop::Mapper::Manufacturer.new(id_lang: 'id_lang', name: "D & G")
manufacturer.find_or_create

In result, manufacturer with name "D &amp; G" created.
How can I create manufacturer with name: "D & G"?

can't modify frozen String

Just started testing with Prestashop 1.6.1.4
Running Prestashop::Client::Implementation.create 'api_key', 'api_url' gives the error can't modify frozen String...

Ruby: 2.3.0
Rails: 4.2.6

Getting associations

Should this be possible?

shop_client.connection.read :orders, nil, {:filter => { :current_state => 4 }, :display => '[associations]'}

It just returns an error with PS 1.6
One option is to display full but there's a lot of stuff there which I don't need.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.