prestashop 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +56 -0
- data/README.md +111 -0
- data/Rakefile +9 -0
- data/lib/prestashop.rb +21 -0
- data/lib/prestashop/api.rb +9 -0
- data/lib/prestashop/api/connection.rb +225 -0
- data/lib/prestashop/api/converter.rb +152 -0
- data/lib/prestashop/api/error.rb +18 -0
- data/lib/prestashop/api/refinement.rb +14 -0
- data/lib/prestashop/client.rb +19 -0
- data/lib/prestashop/client/cache.rb +53 -0
- data/lib/prestashop/client/error.rb +9 -0
- data/lib/prestashop/client/implementation.rb +33 -0
- data/lib/prestashop/mapper.rb +9 -0
- data/lib/prestashop/mapper/extension.rb +161 -0
- data/lib/prestashop/mapper/model.rb +38 -0
- data/lib/prestashop/mapper/models.rb +1 -0
- data/lib/prestashop/mapper/models/address.rb +9 -0
- data/lib/prestashop/mapper/models/carrier.rb +9 -0
- data/lib/prestashop/mapper/models/cart.rb +9 -0
- data/lib/prestashop/mapper/models/cart_rule.rb +9 -0
- data/lib/prestashop/mapper/models/category.rb +114 -0
- data/lib/prestashop/mapper/models/combination.rb +81 -0
- data/lib/prestashop/mapper/models/contact.rb +9 -0
- data/lib/prestashop/mapper/models/content_management_system.rb +9 -0
- data/lib/prestashop/mapper/models/country.rb +15 -0
- data/lib/prestashop/mapper/models/currency.rb +9 -0
- data/lib/prestashop/mapper/models/customer.rb +9 -0
- data/lib/prestashop/mapper/models/customer_message.rb +9 -0
- data/lib/prestashop/mapper/models/customer_thread.rb +9 -0
- data/lib/prestashop/mapper/models/delivery.rb +9 -0
- data/lib/prestashop/mapper/models/employee.rb +9 -0
- data/lib/prestashop/mapper/models/group.rb +9 -0
- data/lib/prestashop/mapper/models/guest.rb +9 -0
- data/lib/prestashop/mapper/models/image.rb +52 -0
- data/lib/prestashop/mapper/models/image_type.rb +9 -0
- data/lib/prestashop/mapper/models/language.rb +15 -0
- data/lib/prestashop/mapper/models/manufacturer.rb +79 -0
- data/lib/prestashop/mapper/models/order.rb +9 -0
- data/lib/prestashop/mapper/models/order_carrier.rb +9 -0
- data/lib/prestashop/mapper/models/order_detail.rb +9 -0
- data/lib/prestashop/mapper/models/order_discount.rb +9 -0
- data/lib/prestashop/mapper/models/order_history.rb +9 -0
- data/lib/prestashop/mapper/models/order_invoice.rb +9 -0
- data/lib/prestashop/mapper/models/order_payment.rb +9 -0
- data/lib/prestashop/mapper/models/order_state.rb +9 -0
- data/lib/prestashop/mapper/models/price_range.rb +9 -0
- data/lib/prestashop/mapper/models/product.rb +198 -0
- data/lib/prestashop/mapper/models/product_feature.rb +69 -0
- data/lib/prestashop/mapper/models/product_feature_value.rb +60 -0
- data/lib/prestashop/mapper/models/product_option.rb +72 -0
- data/lib/prestashop/mapper/models/product_option_value.rb +56 -0
- data/lib/prestashop/mapper/models/product_supplier.rb +31 -0
- data/lib/prestashop/mapper/models/search.rb +9 -0
- data/lib/prestashop/mapper/models/shop.rb +9 -0
- data/lib/prestashop/mapper/models/shop_group.rb +9 -0
- data/lib/prestashop/mapper/models/specific_price.rb +9 -0
- data/lib/prestashop/mapper/models/specific_price_rule.rb +9 -0
- data/lib/prestashop/mapper/models/state.rb +9 -0
- data/lib/prestashop/mapper/models/stock.rb +9 -0
- data/lib/prestashop/mapper/models/stock_available.rb +35 -0
- data/lib/prestashop/mapper/models/stock_movement.rb +9 -0
- data/lib/prestashop/mapper/models/stock_movement_reason.rb +9 -0
- data/lib/prestashop/mapper/models/store.rb +9 -0
- data/lib/prestashop/mapper/models/supplier.rb +45 -0
- data/lib/prestashop/mapper/models/supply_order.rb +9 -0
- data/lib/prestashop/mapper/models/supply_order_detail.rb +9 -0
- data/lib/prestashop/mapper/models/supply_order_history.rb +9 -0
- data/lib/prestashop/mapper/models/supply_order_receipt_history.rb +9 -0
- data/lib/prestashop/mapper/models/supply_order_state.rb +9 -0
- data/lib/prestashop/mapper/models/tag.rb +9 -0
- data/lib/prestashop/mapper/models/tax.rb +24 -0
- data/lib/prestashop/mapper/models/tax_rule.rb +15 -0
- data/lib/prestashop/mapper/models/tax_rule_group.rb +9 -0
- data/lib/prestashop/mapper/models/translated_configuration.rb +9 -0
- data/lib/prestashop/mapper/models/warehouse.rb +9 -0
- data/lib/prestashop/mapper/models/warehouse_product_location.rb +9 -0
- data/lib/prestashop/mapper/models/weight_range.rb +9 -0
- data/lib/prestashop/mapper/models/zone.rb +9 -0
- data/lib/prestashop/mapper/refinement.rb +43 -0
- data/lib/prestashop/version.rb +3 -0
- metadata +279 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
using Prestashop::Mapper::Refinement
|
2
|
+
module Prestashop
|
3
|
+
module Mapper
|
4
|
+
class ProductSupplier < Model
|
5
|
+
resource :product_suppliers
|
6
|
+
model :product_supplier
|
7
|
+
|
8
|
+
attr_reader :id_product, :id_product_attribute, :id_supplier, :product_supplier_reference, :product_supplier_price_te, :id_currency
|
9
|
+
|
10
|
+
def initialize args = {}
|
11
|
+
@id_supplier = settings[:id_supplier]
|
12
|
+
|
13
|
+
@id_product = args.fetch(:id_product)
|
14
|
+
@id_product_attribute = args.fetch(:id_product_attribute, 0)
|
15
|
+
@id_currency = args.fetch(:id_currency, 0)
|
16
|
+
|
17
|
+
@product_supplier_reference = args[:product_supplier_reference]
|
18
|
+
@product_supplier_price_te = args[:product_supplier_price_te]
|
19
|
+
end
|
20
|
+
|
21
|
+
def hash
|
22
|
+
{ id_product: id_product,
|
23
|
+
id_product_attribute: id_product_attribute,
|
24
|
+
id_supplier: id_supplier,
|
25
|
+
product_supplier_reference: product_supplier_reference,
|
26
|
+
product_supplier_price_te: product_supplier_price_te,
|
27
|
+
id_currency: id_currency }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
using Prestashop::Mapper::Refinement
|
2
|
+
module Prestashop
|
3
|
+
module Mapper
|
4
|
+
class StockAvailable < Model
|
5
|
+
resource :stock_availables
|
6
|
+
model :stock_available
|
7
|
+
|
8
|
+
attr_accessor :id_product, :id_product_attribute, :id_shop, :id_shop_group, :quantity, :depends_on_stock, :out_of_stock
|
9
|
+
|
10
|
+
def initialize args = {}
|
11
|
+
@id = args[:id]
|
12
|
+
@id_product = args[:id_product]
|
13
|
+
@id_product_attribute = args.fetch(:id_product_attribute, 0)
|
14
|
+
@id_shop = args.fetch(:id_shop, 1)
|
15
|
+
@id_shop_group = args.fetch(:id_shop_group, 0)
|
16
|
+
@quantity = args.fetch(:quantity, 0)
|
17
|
+
@depends_on_stock = args.fetch(:depends_on_stock, 0)
|
18
|
+
@out_of_stock = args.fetch(:out_of_stock, 2)
|
19
|
+
end
|
20
|
+
|
21
|
+
def id
|
22
|
+
@id ||= if id_product_attribute == 0
|
23
|
+
self.class.find_by 'filter[id_product]' => id_product
|
24
|
+
else
|
25
|
+
self.class.find_by 'filter[id_product]' => id_product, 'filter[id_product_attribute]' => id_product_attribute
|
26
|
+
end
|
27
|
+
end
|
28
|
+
alias :find? :id
|
29
|
+
|
30
|
+
def update options = {}
|
31
|
+
self.class.update(id, options) if find?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
using Prestashop::Mapper::Refinement
|
2
|
+
module Prestashop
|
3
|
+
module Mapper
|
4
|
+
class Supplier < Model
|
5
|
+
resource :suppliers
|
6
|
+
model :supplier
|
7
|
+
|
8
|
+
attr_accessor :id, :link_rewrite, :name, :active, :description, :meta_title, :meta_description, :meta_keywords
|
9
|
+
attr_accessor :id_lang
|
10
|
+
|
11
|
+
def initialize args = {}
|
12
|
+
@id = args[:id]
|
13
|
+
@link_rewrite = args[:link_rewrite]
|
14
|
+
@name = args.fetch(:name)
|
15
|
+
@active = args.fetch(:active, 1)
|
16
|
+
# date_add
|
17
|
+
# date_upd
|
18
|
+
@description = args[:description]
|
19
|
+
@meta_title = args[:meta_title]
|
20
|
+
@meta_description = args[:meta_description]
|
21
|
+
@meta_keywords = args[:meta_keywords]
|
22
|
+
|
23
|
+
@id_lang = args[:id_lang]
|
24
|
+
end
|
25
|
+
|
26
|
+
# Hash is used as default source for #create
|
27
|
+
def hash
|
28
|
+
validate!
|
29
|
+
{ active: active, name: name }
|
30
|
+
end
|
31
|
+
|
32
|
+
# Find or create supplier from hash
|
33
|
+
def find_or_create
|
34
|
+
supplier = self.class.find_by 'filter[name]' => name
|
35
|
+
supplier ? supplier : create[:id]
|
36
|
+
end
|
37
|
+
|
38
|
+
# Supplier must have 1/0 as active and name must be string
|
39
|
+
def validate!
|
40
|
+
raise ArgumentError, 'active must be 0 or 1' unless active == 0 or active == 1
|
41
|
+
raise ArgumentError, 'name must string' unless name.kind_of?(String)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
using Prestashop::Mapper::Refinement
|
2
|
+
module Prestashop
|
3
|
+
module Mapper
|
4
|
+
class Tax < Model
|
5
|
+
resource :taxes
|
6
|
+
model :tax
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def get_by_id_country id
|
10
|
+
taxes = {}
|
11
|
+
TaxRule.get_by_id_country(id).each do |value|
|
12
|
+
taxes[find(value[:id_tax])[:rate].to_i.to_s] = value[:id_tax_rules_group]
|
13
|
+
end
|
14
|
+
taxes
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_by_country iso_code
|
18
|
+
id_country = Country.find_by iso_code: iso_code
|
19
|
+
get_by_id_country id_country
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
using Prestashop::Mapper::Refinement
|
2
|
+
module Prestashop
|
3
|
+
module Mapper
|
4
|
+
class TaxRule < Model
|
5
|
+
resource :tax_rules
|
6
|
+
model :tax_rule
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def get_by_id_country id
|
10
|
+
where 'filter[id_country]' => id, display: 'full'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'sanitize'
|
2
|
+
|
3
|
+
module Prestashop
|
4
|
+
module Mapper
|
5
|
+
module Refinement
|
6
|
+
refine String do
|
7
|
+
def plain
|
8
|
+
self.clean.delete('<>;=#{}')
|
9
|
+
end
|
10
|
+
|
11
|
+
def clean
|
12
|
+
Sanitize.clean self.unescape.gsub('<>','')
|
13
|
+
end
|
14
|
+
|
15
|
+
def restricted
|
16
|
+
Sanitize.clean(self.unescape.gsub('<>',''), Sanitize::Config::RESTRICTED)
|
17
|
+
end
|
18
|
+
|
19
|
+
def unescape
|
20
|
+
CGI.unescapeHTML(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def truncate number = 0
|
24
|
+
self.slice(0, number)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
refine Hash do
|
29
|
+
def clean!
|
30
|
+
reject{|k,v| v.nil? or v.empty?}
|
31
|
+
end
|
32
|
+
|
33
|
+
def find_lang value, id_lang
|
34
|
+
if self[:language].kind_of?(Array)
|
35
|
+
self[:language].find{|l| l[:val] == value and l[:attr][:id] == id_lang}
|
36
|
+
else
|
37
|
+
self[:language][:val] == value and self[:language][:attr][:id] == id_lang
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|