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,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,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Search < Model
5
+ resource :search
6
+ model :search
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Shop < Model
5
+ resource :shops
6
+ model :shop
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class ShopGroup < Model
5
+ resource :shop_groups
6
+ model :shop_group
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class SpecificPrice < Model
5
+ resource :specific_prices
6
+ model :specific_price
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class SpecificPriceRule < Model
5
+ resource :specific_price_rules
6
+ model :specific_price_rule
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class State < Model
5
+ resource :states
6
+ model :state
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Stock < Model
5
+ resource :stocks
6
+ model :stock
7
+ end
8
+ end
9
+ 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,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class StockMovement < Model
5
+ resource :stock_movements
6
+ model :stock_movement
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class StockMovementReason < Model
5
+ resource :stock_movement_reasons
6
+ model :stock_movement_reason
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Store < Model
5
+ resource :stores
6
+ model :store
7
+ end
8
+ end
9
+ 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,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class SupplyOrder < Model
5
+ resource :supply_orders
6
+ model :supply_order
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class SupplyOrderDetail < Model
5
+ resource :supply_order_details
6
+ model :supply_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 SupplyOrderHistory < Model
5
+ resource :supply_order_histories
6
+ model :supply_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 SupplyOrderReceiptHistory < Model
5
+ resource :supply_order_receipt_histories
6
+ model :supply_order_receipt_history
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class SupplyOrderState < Model
5
+ resource :supply_order_states
6
+ model :supply_order_state
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Tag < Model
5
+ resource :tags
6
+ model :tag
7
+ end
8
+ end
9
+ 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,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class TaxRuleGroup < Model
5
+ resource :tax_rule_groups
6
+ model :tax_rule_group
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class TranslatedConfiguration < Model
5
+ resource :translated_configurations
6
+ model :translated_configuration
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Warehouse < Model
5
+ resource :warehouses
6
+ model :warehouse
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class WarehouseProductLocation < Model
5
+ resource :warehouse_product_locations
6
+ model :warehouse_product_location
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class WeightRange < Model
5
+ resource :weight_ranges
6
+ model :weight_range
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ using Prestashop::Mapper::Refinement
2
+ module Prestashop
3
+ module Mapper
4
+ class Zone < Model
5
+ resource :zones
6
+ model :zone
7
+ end
8
+ end
9
+ 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
@@ -0,0 +1,3 @@
1
+ module Prestashop
2
+ VERSION = "2.0.0"
3
+ end