prestashop 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +56 -0
  3. data/README.md +111 -0
  4. data/Rakefile +9 -0
  5. data/lib/prestashop.rb +21 -0
  6. data/lib/prestashop/api.rb +9 -0
  7. data/lib/prestashop/api/connection.rb +225 -0
  8. data/lib/prestashop/api/converter.rb +152 -0
  9. data/lib/prestashop/api/error.rb +18 -0
  10. data/lib/prestashop/api/refinement.rb +14 -0
  11. data/lib/prestashop/client.rb +19 -0
  12. data/lib/prestashop/client/cache.rb +53 -0
  13. data/lib/prestashop/client/error.rb +9 -0
  14. data/lib/prestashop/client/implementation.rb +33 -0
  15. data/lib/prestashop/mapper.rb +9 -0
  16. data/lib/prestashop/mapper/extension.rb +161 -0
  17. data/lib/prestashop/mapper/model.rb +38 -0
  18. data/lib/prestashop/mapper/models.rb +1 -0
  19. data/lib/prestashop/mapper/models/address.rb +9 -0
  20. data/lib/prestashop/mapper/models/carrier.rb +9 -0
  21. data/lib/prestashop/mapper/models/cart.rb +9 -0
  22. data/lib/prestashop/mapper/models/cart_rule.rb +9 -0
  23. data/lib/prestashop/mapper/models/category.rb +114 -0
  24. data/lib/prestashop/mapper/models/combination.rb +81 -0
  25. data/lib/prestashop/mapper/models/contact.rb +9 -0
  26. data/lib/prestashop/mapper/models/content_management_system.rb +9 -0
  27. data/lib/prestashop/mapper/models/country.rb +15 -0
  28. data/lib/prestashop/mapper/models/currency.rb +9 -0
  29. data/lib/prestashop/mapper/models/customer.rb +9 -0
  30. data/lib/prestashop/mapper/models/customer_message.rb +9 -0
  31. data/lib/prestashop/mapper/models/customer_thread.rb +9 -0
  32. data/lib/prestashop/mapper/models/delivery.rb +9 -0
  33. data/lib/prestashop/mapper/models/employee.rb +9 -0
  34. data/lib/prestashop/mapper/models/group.rb +9 -0
  35. data/lib/prestashop/mapper/models/guest.rb +9 -0
  36. data/lib/prestashop/mapper/models/image.rb +52 -0
  37. data/lib/prestashop/mapper/models/image_type.rb +9 -0
  38. data/lib/prestashop/mapper/models/language.rb +15 -0
  39. data/lib/prestashop/mapper/models/manufacturer.rb +79 -0
  40. data/lib/prestashop/mapper/models/order.rb +9 -0
  41. data/lib/prestashop/mapper/models/order_carrier.rb +9 -0
  42. data/lib/prestashop/mapper/models/order_detail.rb +9 -0
  43. data/lib/prestashop/mapper/models/order_discount.rb +9 -0
  44. data/lib/prestashop/mapper/models/order_history.rb +9 -0
  45. data/lib/prestashop/mapper/models/order_invoice.rb +9 -0
  46. data/lib/prestashop/mapper/models/order_payment.rb +9 -0
  47. data/lib/prestashop/mapper/models/order_state.rb +9 -0
  48. data/lib/prestashop/mapper/models/price_range.rb +9 -0
  49. data/lib/prestashop/mapper/models/product.rb +198 -0
  50. data/lib/prestashop/mapper/models/product_feature.rb +69 -0
  51. data/lib/prestashop/mapper/models/product_feature_value.rb +60 -0
  52. data/lib/prestashop/mapper/models/product_option.rb +72 -0
  53. data/lib/prestashop/mapper/models/product_option_value.rb +56 -0
  54. data/lib/prestashop/mapper/models/product_supplier.rb +31 -0
  55. data/lib/prestashop/mapper/models/search.rb +9 -0
  56. data/lib/prestashop/mapper/models/shop.rb +9 -0
  57. data/lib/prestashop/mapper/models/shop_group.rb +9 -0
  58. data/lib/prestashop/mapper/models/specific_price.rb +9 -0
  59. data/lib/prestashop/mapper/models/specific_price_rule.rb +9 -0
  60. data/lib/prestashop/mapper/models/state.rb +9 -0
  61. data/lib/prestashop/mapper/models/stock.rb +9 -0
  62. data/lib/prestashop/mapper/models/stock_available.rb +35 -0
  63. data/lib/prestashop/mapper/models/stock_movement.rb +9 -0
  64. data/lib/prestashop/mapper/models/stock_movement_reason.rb +9 -0
  65. data/lib/prestashop/mapper/models/store.rb +9 -0
  66. data/lib/prestashop/mapper/models/supplier.rb +45 -0
  67. data/lib/prestashop/mapper/models/supply_order.rb +9 -0
  68. data/lib/prestashop/mapper/models/supply_order_detail.rb +9 -0
  69. data/lib/prestashop/mapper/models/supply_order_history.rb +9 -0
  70. data/lib/prestashop/mapper/models/supply_order_receipt_history.rb +9 -0
  71. data/lib/prestashop/mapper/models/supply_order_state.rb +9 -0
  72. data/lib/prestashop/mapper/models/tag.rb +9 -0
  73. data/lib/prestashop/mapper/models/tax.rb +24 -0
  74. data/lib/prestashop/mapper/models/tax_rule.rb +15 -0
  75. data/lib/prestashop/mapper/models/tax_rule_group.rb +9 -0
  76. data/lib/prestashop/mapper/models/translated_configuration.rb +9 -0
  77. data/lib/prestashop/mapper/models/warehouse.rb +9 -0
  78. data/lib/prestashop/mapper/models/warehouse_product_location.rb +9 -0
  79. data/lib/prestashop/mapper/models/weight_range.rb +9 -0
  80. data/lib/prestashop/mapper/models/zone.rb +9 -0
  81. data/lib/prestashop/mapper/refinement.rb +43 -0
  82. data/lib/prestashop/version.rb +3 -0
  83. metadata +279 -0
@@ -0,0 +1,81 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Combination < Model
5
+ resource :combinations
6
+ model :combination
7
+
8
+ attr_accessor :id_lang, :id_product_options, :id_images
9
+ attr_accessor :id, :id_product, :location, :ean13, :upc, :quantity, :reference, :supplier_reference, :wholesale_price,
10
+ :price, :ecotax, :weight, :unit_price_impact, :minimal_quantity, :default_on, :available_date
11
+
12
+ def initialize args = {}
13
+ @id = args[:id]
14
+ @id_product = args.fetch(:id_product)
15
+ @location = args[:location]
16
+ @ean13 = args[:ean]
17
+ @upc = args[:upc]
18
+ @quantity = args.fetch(:quantity, 0)
19
+ @reference = args.fetch(:reference)
20
+ @supplier_reference = args[:supplier_reference]
21
+ @wholesale_price = args[:wholesale_price]
22
+ @price = args[:price]
23
+ @ecotax = args[:ecotax]
24
+ @weight = args[:weight]
25
+ @unit_price_impact = args[:unit_price_impact]
26
+ @minimal_quantity = args.fetch(:minimal_quantity, 1)
27
+ @default_on = args.fetch(:default_on, 0)
28
+ @available_date = Date.today.strftime("%F")
29
+
30
+ @id_product_options = args[:id_product_options]
31
+ @id_images = args[:id_images]
32
+
33
+ @id_lang = args.fetch(:id_lang)
34
+ end
35
+
36
+ # ID of combination, or find ID by +reference+ and +id_product+
37
+ def id
38
+ @id ||= self.class.find_by 'filter[reference]' => reference, 'filter[id_product]' => id_product
39
+ end
40
+ alias :find? :id
41
+
42
+ def hash
43
+ combination = {
44
+ id_product: id_product,
45
+ reference: reference,
46
+ supplier_reference: supplier_reference,
47
+ minimal_quantity: minimal_quantity,
48
+ default_on: default_on,
49
+ available_date: available_date,
50
+ price: price,
51
+ quantity: quantity,
52
+ associations: {}
53
+ }
54
+ if id_product_options
55
+ combination[:associations][:product_option_values] = {}
56
+ combination[:associations][:product_option_values][:product_option_value] = hash_ids(id_product_options)
57
+ end
58
+ if id_images
59
+ combination[:associations][:images] = {}
60
+ combination[:associations][:images][:image] = hash_ids(id_images)
61
+ end
62
+ combination
63
+ end
64
+
65
+ def update options = {}
66
+ self.class.update(id, options)
67
+ end
68
+
69
+ class << self
70
+ def deactivate supplier
71
+ first = (Date.today-365).strftime("%F")
72
+ last = (Date.today-1).strftime("%F")
73
+ combinations = where 'filter[date_upd]' => "[#{first},#{last}]", date: 1, 'filter[supplier_reference]' => supplier, limit: 1000
74
+ if combinations and !combinations.empty?
75
+ combinations.map{|c| delete(c)}
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Contact < Model
5
+ resource :contacts
6
+ model :contact
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class ContentManagementSystem < Model
5
+ resource :content_management_system
6
+ model :content_management_system
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Country < Model
5
+ resource :countries
6
+ model :country
7
+
8
+ class << self
9
+ def find_by_iso_code iso_code
10
+ find_by 'filter[iso_code]' => iso_code
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Currency < Model
5
+ resource :currencies
6
+ model :currency
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Customer < Model
5
+ resource :customers
6
+ model :customer
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class CustomerMessage < Model
5
+ resource :customer_messages
6
+ model :customer_message
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class CustomerThread < Model
5
+ resource :customer_threads
6
+ model :customer_thread
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Delivery < Model
5
+ resource :deliveries
6
+ model :delivery
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Employee < Model
5
+ resource :employees
6
+ model :employee
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Group < Model
5
+ resource :groups
6
+ model :group
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Guest < Model
5
+ resource :guests
6
+ model :guest
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,52 @@
1
+ require 'open-uri'
2
+
3
+ using Prestashop::Mapper::Refinement
4
+ module Prestashop
5
+ module Mapper
6
+ class Image < Model
7
+ resource :images
8
+ model :image
9
+
10
+ attr_accessor :id, :resource, :id_resource, :source, :file
11
+
12
+ def initialize args = {}
13
+ @id = args[:id]
14
+ @resource = args.fetch(:resource)
15
+ @id_resource = args.fetch(:id_resource)
16
+ @source = args.fetch(:source)
17
+ end
18
+
19
+ def images
20
+ source.kind_of?(Array) ? source : [source]
21
+ end
22
+
23
+ def upload
24
+ result = []
25
+ images.each do |image|
26
+ result << uploader(image)
27
+ end unless images.empty?
28
+ result
29
+ end
30
+
31
+ def uploader source
32
+ if source =~ URI::regexp
33
+ source = URI::encode(source)
34
+ self.file = MiniMagick::Image.open(source)
35
+ file.format 'png' unless %w(jpg jpeg png gif).include?(file[:format])
36
+ result = Client.upload 'images', resource, id_resource, payload, file
37
+ result[:image][:id] if result
38
+ else
39
+ false # Not valid url
40
+ end
41
+ rescue MiniMagick::Invalid
42
+ false # It's not valid image
43
+ rescue OpenURI::HTTPError
44
+ false # Image not found
45
+ end
46
+
47
+ def payload
48
+ { image: Faraday::UploadIO.new(file.path, 'image') }
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class ImageType < Model
5
+ resource :image_types
6
+ model :image_type
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Language < Model
5
+ resource :languages
6
+ model :language
7
+
8
+ class << self
9
+ def find_by_iso_code iso_code
10
+ find_by 'filter[iso_code]' => iso_code
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,79 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Manufacturer < Model
5
+ resource :manufacturers
6
+ model :manufacturer
7
+
8
+ attr_accessor :id, :active
9
+ attr_accessor :id_lang
10
+ attr_writer :link_rewrite, :name, :description, :short_description, :meta_title, :meta_description, :meta_keywords
11
+
12
+ def initialize args = {}
13
+ @id = args[:id]
14
+ @active = args.fetch(:active, 1)
15
+ @link_rewrite = args[:link_rewrite]
16
+ @name = args[:name]
17
+ # date_add
18
+ # date_upd
19
+ @description = args[:description]
20
+ @short_description = args[:short_description]
21
+ @meta_title = args[:meta_title]
22
+ @meta_description = args[:meta_description]
23
+ @meta_keywords = args[:meta_keywords]
24
+
25
+ @id_lang = args.fetch(:id_lang)
26
+ end
27
+
28
+ def name
29
+ @name.plain.truncate(125)
30
+ end
31
+
32
+ def description
33
+ @description.plain.truncate(252) if @description
34
+ end
35
+
36
+ def short_description
37
+ @short_description ? @short_description.plain.truncate(252) : ( description.plain.truncate(252) if description )
38
+ end
39
+
40
+ def hash
41
+ validate!
42
+ { active: active,
43
+ name: name,
44
+ description: hash_lang(description, id_lang),
45
+ short_description: hash_lang(short_description, id_lang),
46
+ meta_title: hash_lang(name, id_lang),
47
+ meta_description: hash_lang(short_description, id_lang),
48
+ meta_keywords: hash_lang(meta_keywords, id_lang) }
49
+ end
50
+
51
+ def find_or_create
52
+ if name and !name.empty?
53
+ manufacturer = self.class.find_in_cache name
54
+ unless manufacturer
55
+ manufacturer = create
56
+ Client.clear_manufacturers_cache
57
+ end
58
+ manufacturer[:id]
59
+ end
60
+ end
61
+
62
+ def validate!
63
+ raise ArgumentError, 'id lang must be number' unless id_lang.kind_of?(Integer)
64
+ raise ArgumentError, 'active must be number' unless active.kind_of?(Integer)
65
+ raise ArgumentError, 'name must string' unless name.kind_of?(String)
66
+ end
67
+
68
+ class << self
69
+ def find_in_cache name
70
+ Client.manufacturers_cache.find{|m| m[:name] == name } if Client.manufacturers_cache
71
+ end
72
+
73
+ def cache
74
+ all display: '[id,name]'
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Order < Model
5
+ resource :orders
6
+ model :order
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class OrderCarrier < Model
5
+ resource :order_carriers
6
+ model :order_carrier
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class OrderDetail < Model
5
+ resource :order_details
6
+ model :order_detail
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class OrderDiscount < Model
5
+ resource :order_discounts
6
+ model :order_discount
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class OrderHistory < Model
5
+ resource :order_histories
6
+ model :order_history
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class OrderInvoice < Model
5
+ resource :order_invoices
6
+ model :order_invoice
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class OrderPayment < Model
5
+ resource :order_payments
6
+ model :order_payment
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class OrderState < Model
5
+ resource :order_states
6
+ model :order_state
7
+ end
8
+ end
9
+ end