Comments (26)
Hey, yes, it does.
You can do something like:
combination = Prestashop::Mapper::Combination.new(
id_lang: 1, id_product: 123, reference: 'unique-identifier')
combination.id_product_options = Prestashop::Mapper::ProductOption
.create_from_hash([{name: 'Color', value: 'Red'}, {name: 'Size', value: 'M'], 1)
combination.id_images = Prestashop::Mapper::Image.new(
resource: 'products', id_resource: 123, source: ['http://lorempixel.com/400/200/cats/']).upload
combination.create
from prestashop.
Hm. I cannot connect
Prestashop::Client::Implementation.create '69CHK6FQISWIIAYYBIUDD7KJR1T85N1X', 'http://192.168.99.100:8080/api/'
I am getting
connection.rb:19:in `initialize': Your credentials are invalid (Prestashop::Api::InvalidCredentials)
I checked the endpoint
$ curl -i "http://192.168.99.100:8080/api/"
HTTP/1.1 401 Unauthorized
Date: Sat, 14 Nov 2015 09:38:00 GMT
Server: Apache/2.4.10 (Debian)
WWW-Authenticate: Basic realm="Welcome to PrestaShop Webservice, please enter the authentication key as the login. No password required."
Set-Cookie: PrestaShop-3cd618dc39c755671f96cf31d8d2bcaf=cpiCOo9HhxOTe7oKsbceTSbpuSpwuYTQ6grKwCi3U32lgat5Gb0h4Wa30keE4uDm6HluuehLU8NDlUhZJE9rpQJpoJx1jC6W%2Bf1w3QewQHw%3D000079; expires=Fri, 04-Dec-2015 09:38:00 GMT; Max-Age=1728000; path=/; httponly
Content-Length: 16
Content-Type: text/html; charset=utf-8
and the key is copy & pasted.
The shop is version 1.6.1.2. Any idea?
from prestashop.
You can track communication between your app and store to see what's happening.
git pull
DEBUG=true rake console
from prestashop.
Thanks, that was helpful.
Seems it's getting a 503. Odd. Maybe I need to try with curl
first.
$ DEBUG=true bundle exec ruby importer.rb
I, [2015-11-14T11:12:54.641460 #46330] INFO -- : get http://192.168.99.100:8080/api/
D, [2015-11-14T11:12:54.641539 #46330] DEBUG -- request: Authorization: "Basic NjlDSEs2RlFJU1dJSUFZWUJJVUREN0tKUjFUODVOMVg6"
User-Agent: "Faraday v0.9.2"
I, [2015-11-14T11:12:54.710332 #46330] INFO -- Status: 503
D, [2015-11-14T11:12:54.710472 #46330] DEBUG -- response: date: "Sat, 14 Nov 2015 10:12:54 GMT"
server: "Apache/2.4.10 (Debian)"
access-time: "1447495974"
x-powered-by: "PrestaShop Webservice"
psws-version: "1.6.1.2"
execution-time: "0.002"
set-cookie: "PrestaShop-3cd618dc39c755671f96cf31d8d2bcaf=cpiCOo9HhxOTe7oKsbceTaH3sDXSGKvhpYpqcGTBZwKlgat5Gb0h4Wa30keE4uDm6HluuehLU8NDlUhZJE9rpZ2vnBBUExTnaCSUPcup7Sc%3D000079; expires=Fri, 04-Dec-2015 10:12:54 GMT; Max-Age=1728000; path=/; httponly"
content-length: "241"
connection: "close"
content-type: "text/xml;charset=utf-8"
from prestashop.
All good. The "save" to turn on the webservice got lost :)
from prestashop.
Good, glad to hear that :)
from prestashop.
almost there... when I run this
id_lang = Prestashop::Mapper::Language.find_by_iso_code('de')
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')
I run into
.../lib/prestashop/mapper/models/product.rb:70:in `fetch': key not found: :name (KeyError)
from .../lib/prestashop/mapper/models/product.rb:70:in `initialize'
from importer.rb:8:in `new'
form the code I could not yet figure out whether I need to provide the name - but it seems like that doesn't solve it anyway. Any suggestions what's still missing?
from prestashop.
Yes, you have to have a name, when you want to create product, I forgot.. https://github.com/werein/prestashop/blob/master/lib/prestashop/mapper/models/product.rb#L70
This should solve the problem..
Prestashop::Mapper::Product.new(id_lang: id_lang, id_supplier: id_supplier, reference: 'apple-macbook', name: 'MacBook')
I'll update readme later on.
from prestashop.
Yes, I tried that but that gives:
models/product.rb:90:in `link_rewrite': undefined method `parameterize' for "MacBook Pro":String (NoMethodError)
from .../lib/prestashop/mapper/models/product.rb:133:in `hash'
Seems there is some rails
leakage. Looks like I could provide my own link_rewrite
though.
Wouldn't it be smarter to test name
for parameterize
, too?
from prestashop.
You're right, it's extracted from rails. Yes, that would be great
from prestashop.
Slooowly getting there. For now I've just added ActiveSupport
. Now it's
/lib/prestashop/mapper/models/product.rb:102:in `available_now': undefined method `plain' for nil:NilClass (NoMethodError)
from .../lib/prestashop/mapper/models/product.rb:137:in `hash'
Not sure I get the usage of available_now
, available_for_order
, available_date
and available_later
yet.
But most importantly - where is the plain
coming from?
from prestashop.
Almost there. Now came across
/lib/prestashop/api/converter.rb:38:in `[]': no implicit conversion of Symbol into Integer (TypeError)
def self.parse_error response
parsed = parse(response)
if parsed[:errors] and parsed[:errors][:error] and parsed[:errors][:error][:message] // line 38
parsed[:errors][:error][:message]
else
raise ParserError
end
end
from prestashop.
parsed
looks like this:
{:errors=>
{:error=>
[
{:message=>"Internal error. To see this error please display the PHP errors."},
{:message=>"Internal error. To see this error please display the PHP errors."},
{:message=>"Internal error. To see this error please display the PHP errors."}
]
}
}
so apparently [:errors][:error]
is an array.
from prestashop.
To debug further I've set _PS_MODE_DEV_
to true
- now the error is gone. You gotta love PHP :-/
It creates the products either way though.
Do you see a reason why this could create an error?
require 'prestashop'
require 'active_support'
require 'active_support/all'
Prestashop::Client::Implementation.create '69CHK6FQISWIIAYYBIUDD7KJR1T85N1X', 'http://192.168.99.100:8080/api/'
id_lang = Prestashop::Mapper::Language.find_by_iso_code('de')
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-' + (0...16).map { (65 + rand(26)).chr }.join,
name: 'MacBook Pro'
)
if product.find?
# product.update price: '1299'
puts "product found"
else
product.quantity = 1,
# product.depends_on_stock = 0
product.weight = 10
product.on_sale = 0
product.available_now = ''
product.available_later = ''
product.description = 'My description'
product.price = '1299'
product.create
puts "product created"
end
from prestashop.
Even a more complex example works in dev mode - only though. This is just odd.
There are still a few open questions:
- what is a
reference
opposed to anid
and why are they limited to only 32 characters? - how to set the standard supplier of a product?
- how to set supplier article number and price of the product options?
from prestashop.
Plain is sanitising string..
I'll go through open questions.
- Reference is unique identifier, it's used to look up a product when you don't know the id. It's limited to 32 characters due to Prestashop limitations.
- What do you mean by standard supplier?
- Not sure what supplier article number is.
You can set price of products option like that:
@combination = Prestashop::Mapper::Combination.new(
id_lang: 'id-lang', id_product: 'product-id', reference: 'combination-reference')
if @combination.find?
@combination.price = 123
@combination.create
end
And I've no clue why it works only in DEV mode, do you have your own hosting or you use cloud solutions?
from prestashop.
Seems like the reference isn't really needed. If I don't know the id I would search for the name. Still not sure I get the idea behind this - but anway.
combination.price = 123
Great! The naming is a little of (as it's a price change) but that's fine :)
The supplier article number is the number you use for ordering the article by the supplier. Setting this makes it easier to map your article number to the supplier article number.
I've attached a screenshot.
from prestashop.
Another head scratcher is the tax. On the product I found id_tax_rules_group
but I am not quite sure what a "group" represents here? Looking at the model I am also not quite sure how use it
https://github.com/werein/prestashop/blob/master/lib/prestashop/mapper/models/tax_rule_group.rb
from prestashop.
It's how Prestashop handle VAT in countries, take a closer look how PS handle this.
Anyway, if you need to set a tax for product, I'd suggest to do something like this:
Prestashop::Mapper::Tax.get_by_country('cz')['21'] # => Tax ID for given country at this rate
In any case you can use low level API and make easier requests to the server..
from prestashop.
Hm - but that's getting me a tax id not a "tax_rules_group" id.
Low level you mean like using https://github.com/werein/prestashop/blob/master/lib/prestashop/api/connection.rb
from prestashop.
Actually you will get tax_rules_group
, for the country based on rate you specified my mistake.
It will go thought TaxRule
s for required country and maps Tax
rates to TaxRuleGroup
.id
..
For example you will get something like:
# For all `TaxRule` in country
{
"21": 40, # => "Tax.rate": "TaxRulesGroup.id"
"15": 41
}
Yes that's what I mean
from prestashop.
Perfect! I will give that a try.
Only thing that I am still struggling with are the supplier references. The docs here are pretty slim here:
http://doc.prestashop.com/display/PS16/Web+service+reference
Did you just call the endpoints and try? Or how did you come up with the impl?
I bet it hides behind the product_suppliers
endpoint.
from prestashop.
Found the model and trying like this
product_supplier = Prestashop::Mapper::ProductSupplier.new(
id_supplier: supplier,
id_product: product.id,
product_supplier_reference: '',
product_supplier_price_te: ''
).find_or_create
but getting
/lib/prestashop/mapper/models/product_supplier.rb:11:in `initialize': undefined local variable or method `settings' for #<Prestashop::Mapper::ProductSupplier:0x007fc13d4eff10> (NameError)
from importer2.rb:171:in `new'
from importer2.rb:171:in `<main>'
where are those settings are supposed to come from?
from prestashop.
Yes, it's behind that endpoint. I called API with ?synopsis
and that returned XML template. Here you can see available resources and actions
ProductSupplier
is ok now, you should pass id_supplier
as parameter, we were using some application wide settings. As I remember correctly ProductSupplier
wasn't allowed to create/update in earlier versions of PS, not sure how it is now
from prestashop.
@tcurdt you find any solution of that?
from prestashop.
@Haseeb717 sorry, it's been a while - I've moved on and cannot remember the details. I do remember it was painful though :)
from prestashop.
Related Issues (12)
- Typo in gemspec (homepage url) HOT 4
- Getting associations HOT 4
- can't add manufacturer with special symbols in name HOT 1
- Add 'price' parameter conform to API documentation
- Order with multiple cart_items HOT 3
- Error using PUT command in API HOT 2
- While updating Order returns TypeError: no implicit conversion of Symbol into Integer HOT 1
- allow upload of local images HOT 4
- Available API calls
- can't modify frozen String HOT 2
- connection not working correctly HOT 27
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prestashop.