werein / prestashop

Prestashop API for Ruby including low-level API access and Prestashop fields converted into PORO

Home Page:https://wereinhq.com/guides/prestashop

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

connection not working correctly

Haseeb717 opened this issue · comments

Prestashop::Client::Implementation.create 'api_key', 'api_url'
When I write this it doesnt work not give any response
Is this gem working fine?

Well that alone should not give any responses. That only create the client so you can connect to the shop.

shop_client = Prestashop::Client::Implementation.create 'api_key', 'api_url'
shop_client.connection.get :configurations, nil, {:filter => {:name => "[PS_SHOP_NAME|PS_VERSION_DB]"}, :display => '[name,value]'}

Of course the API should be enabled and the required resources open...
That should show something.

When I write it doesn't return anything and keep going . After some time give connection error
Prestashop::Client::Implementation.create 'api_key', 'api_url'

When I do the same from console I get the instance of it.

shop_client = Prestashop::Client::Implementation.create "FZS6H...BD", "http://shop.internet.com"
 => #<Prestashop::Client::Implementation:0x007fc9b6ea86e8 @connection=#<Prestashop::Api::Connection:0x007fc9b6ea8b48 @api_key="FZS6H...BD", @api_url="http://shop.internet.com/api/">, @cache=#<Prestashop::Client::Cache:0x007fc9b94b8e28>>

If I change the url it complains about not being able to make the connection. If I change the key then it complains about the credentials.

You must make sure the shop API is really accessible.

Works (y)
Can you give any example of this?
shop_client.connection.get :configurations, nil, {:filter => {:name => "[PS_SHOP_NAME|PS_VERSION_DB]"}, :display => '[name,value]'}

In git it is written that
Prestashop::Client.get :customer, 1
but it gives an error
NoMethodError: undefined method `get' for Prestashop::Client:Module

Yep.

The description is not correct.
Use, Prestashop::Client.connection.get :customers, 1 <--- customers, not customer

The configurations call I mentioned gives this for example:

{:configurations=>{:configuration=>[{:value=>"ps1614", :name=>"PS_SHOP_NAME"}, {:value=>"1.6.1.4", :name=>"PS_VERSION_DB"}]}} 

What version of PS you are connecting to?

2.0.0

Aha. I haven't yet checked anything with 2.0...
1.4, 1.5 and 1.6, but not 2.0 yet.

with 1.4,1.5 these commands working?

Well those examples I gave do work.
But depending on the PS version some more complex things might not work, and require some changes in PS code.

Try to stay away from 1.4 specially.
It would be actually sad if this gem didn't work with 2.0 as well...

Hopefully the owner can comment on the 2.0 support soon.

you mean this gem is not working properly?

Hmm. Nothing is perfect. Depends what you want to do with it.
Prestashop 1.4 is far from perfect. Maybe the whole Prestashop is far from perfect :-)

Basically I want to upload products,delete products,update and get products on prestashop in rails.
I see this gem but till now not succeeded
.

Well since I haven't used 2.0 I can't tell how far it gets.
I haven't created products with this gem, so I can't tell you how well it supports that.

It also depends on the PS APIs of each version you want to support.
For example 1.4 doesn't even allow you to filter orders by order state, very basic stuff missing sometimes...

I think the owner could tell you more, when he/she drops by.

Thanks :)

No prob.

There is already Prestashop 2.0?

Try Prestashop::Client.read instead of Prestashop::Client.get, or use connection as @josegrad mentioned. Looks like get alias is not forwarded

Creating/updating products shouldn't be problem with gem, it was actually purpose of this gem. Look here

But using low level API should be also possible

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

this returns all products for example

@jirikolarik Any information about product post?

Creating is about the same (post and create are aliases)

Prestashop::Client.create :products, payload

Where payload is XML which Prestashop expects, you can use converter, which converts hash into required format like that

payload = Prestashop::Api::Converter.build(:products, :product, hash)

Simplier solutions is using Product model

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

Prestashop::Api::Converter.build(:products, :product, hash)
it returns error
TypeError: no implicit conversion of Symbol into Integer

Take a look here

and in Prestashop::Mapper::Product.new
NoMethodError: undefined method `plain' for nil:NilClass

Prestashop::Api::RequestFailed: Internal error. To see this error please display the PHP errors.. XML SENT: :(

Hello, I am trying to use PrestaShop Gem, but when I am trying to update the Product, I am getting following error. Can You Please Give me solution.

:message => "[PHP Notice #8] Undefined index: id (/home/29468-81260.cloudwaysapps.com/nfmgdxmjnm/public_html/classes/Product.php, line 5147)"

@DhanashriJoshi seems like a problem with database.