Class: Prestashop::Mapper::Product
- Defined in:
- lib/prestashop/mapper/models/product.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#additional_shipping_cost ⇒ Object
Returns the value of attribute additional_shipping_cost.
-
#advanced_stock_management ⇒ Object
Returns the value of attribute advanced_stock_management.
-
#available_date ⇒ Object
Returns the value of attribute available_date.
-
#available_for_order ⇒ Object
Returns the value of attribute available_for_order.
- #available_later ⇒ Object
- #available_now ⇒ Object
-
#cache_default_attribute ⇒ Object
Returns the value of attribute cache_default_attribute.
-
#cache_has_attachment ⇒ Object
Returns the value of attribute cache_has_attachment.
-
#cache_is_pack ⇒ Object
Returns the value of attribute cache_is_pack.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#customizable ⇒ Object
Returns the value of attribute customizable.
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#description ⇒ Object
Returns the value of attribute description.
- #description_short ⇒ Object
-
#ean13 ⇒ Object
Returns the value of attribute ean13.
-
#ecotax ⇒ Object
Returns the value of attribute ecotax.
-
#height ⇒ Object
Returns the value of attribute height.
-
#id ⇒ Object
(also: #find?)
Find product by
reference
andid_supplier
, returnsid
. -
#id_categories ⇒ Object
Returns the value of attribute id_categories.
-
#id_category_default ⇒ Object
Returns the value of attribute id_category_default.
-
#id_features ⇒ Object
Returns the value of attribute id_features.
-
#id_lang ⇒ Object
Returns the value of attribute id_lang.
-
#id_manufacturer ⇒ Object
Returns the value of attribute id_manufacturer.
-
#id_product_redirect ⇒ Object
Returns the value of attribute id_product_redirect.
-
#id_shop_default ⇒ Object
Returns the value of attribute id_shop_default.
-
#id_supplier ⇒ Object
Returns the value of attribute id_supplier.
-
#id_tax_rules_group ⇒ Object
Returns the value of attribute id_tax_rules_group.
-
#indexed ⇒ Object
Returns the value of attribute indexed.
-
#is_virtual ⇒ Object
Returns the value of attribute is_virtual.
- #link_rewrite ⇒ Object
-
#location ⇒ Object
Returns the value of attribute location.
-
#manufacturer_name ⇒ Object
Returns the value of attribute manufacturer_name.
-
#meta_description ⇒ Object
writeonly
Sets the attribute meta_description.
-
#meta_keywords ⇒ Object
writeonly
Sets the attribute meta_keywords.
-
#meta_title ⇒ Object
writeonly
Sets the attribute meta_title.
-
#minimal_quantity ⇒ Object
Returns the value of attribute minimal_quantity.
- #name ⇒ Object
-
#new ⇒ Object
Returns the value of attribute new.
-
#on_sale ⇒ Object
Returns the value of attribute on_sale.
-
#online_only ⇒ Object
Returns the value of attribute online_only.
-
#position_in_category ⇒ Object
Returns the value of attribute position_in_category.
-
#price ⇒ Object
Returns the value of attribute price.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#quantity_discount ⇒ Object
Returns the value of attribute quantity_discount.
-
#redirect_type ⇒ Object
Returns the value of attribute redirect_type.
- #reference ⇒ Object
-
#show_price ⇒ Object
Returns the value of attribute show_price.
-
#supplier_reference ⇒ Object
Returns the value of attribute supplier_reference.
-
#text_fields ⇒ Object
Returns the value of attribute text_fields.
-
#type ⇒ Object
Returns the value of attribute type.
-
#unit_price_ratio ⇒ Object
Returns the value of attribute unit_price_ratio.
-
#unity ⇒ Object
Returns the value of attribute unity.
-
#upc ⇒ Object
Returns the value of attribute upc.
-
#uploadable_files ⇒ Object
Returns the value of attribute uploadable_files.
-
#visibility ⇒ Object
Returns the value of attribute visibility.
-
#weight ⇒ Object
Returns the value of attribute weight.
-
#wholesale_price ⇒ Object
Returns the value of attribute wholesale_price.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
-
#feature_hash(id_feature, id_feature_value) ⇒ Object
Generate hash of single feature.
-
#features_hash ⇒ Object
Generate hash of features.
- #hash ⇒ Object
- #id_categories_all ⇒ Object
-
#initialize(args = {}) ⇒ Product
constructor
A new instance of Product.
-
#update(options = {}) ⇒ Object
Update product with given options.
Methods inherited from Model
#hash_lang, #meta_description, #meta_keywords, #meta_title, model, resource
Methods included from Extension
Constructor Details
#initialize(args = {}) ⇒ Product
Returns a new instance of Product.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/prestashop/mapper/models/product.rb', line 16 def initialize args = {} @id = args[:id] @id_manufacturer = args[:id_manufacturer] @id_supplier = args.fetch(:id_supplier) @id_category_default = args[:id_category_default] @new = args[:new] @cache_default_attribute = args.fetch(:cache_default_attribute, 0) @id_tax_rules_group = args[:id_tax_rules_group] @position_in_category = args.fetch(:position_in_category, 0) @manufacturer_name = args[:manufacturer_name] @quantity = args[:quantity] @type = args.fetch(:type, 'simple') @id_shop_default = args.fetch(:id_shop_default, 1) @reference = args.fetch(:reference) @supplier_reference = args[:supplier_reference] @location = args[:location] @width = args[:width] @height = args[:height] @depth = args[:depth] @weight = args[:weight] @quantity_discount = args.fetch(:quantity_discount, 0) @ean13 = args[:ean13] @upc = args[:upc] @cache_is_pack = args.fetch(:cache_is_pack, 0) @cache_has_attachment = args.fetch(:cache_has_attachment, 0) @is_virtual = args.fetch(:is_virtual, 0) @on_sale = args.fetch(:on_sale, 0) @online_only = args.fetch(:online_only, 0) @ecotax = args.fetch(:ecotax, 0) @minimal_quantity = args.fetch(:minimal_quantity, 1) @price = args[:price] @wholesale_price = args[:wholesale_price] @unity = args[:unity] @unit_price_ratio = args[:unit_price_ratio] @additional_shipping_cost = args[:additional_shipping_cost] @customizable = args[:customizable] @text_fields = args[:text_fields] @uploadable_files = args[:uploadable_files] @active = args[:active] @redirect_type = args[:redirect_type] @id_product_redirect = args[:id_product_redirect] @available_for_order = args[:available_for_order] @available_date = args.fetch(:available_date, Date.today.strftime("%F")) @condition = args.fetch(:condition, 'new') @show_price = args[:show_price] @indexed = 0 @visibility = args.fetch(:visibility, 'both') @advanced_stock_management = args[:advanced_stock_management] # date_add # date_upd @meta_description = args[:meta_description] @meta_keywords = args[:meta_keywords] @meta_title = args[:meta_title] @link_rewrite = args[:link_rewrite] @name = args.fetch(:name) @description = args[:description] @description_short = args[:description_short] @available_now = args[:available_now] @available_later = args[:available_later] @id_lang = args.fetch(:id_lang) @id_categories = args[:id_categories] @id_features = args[:id_features] end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def active @active end |
#additional_shipping_cost ⇒ Object
Returns the value of attribute additional_shipping_cost.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def additional_shipping_cost @additional_shipping_cost end |
#advanced_stock_management ⇒ Object
Returns the value of attribute advanced_stock_management.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def advanced_stock_management @advanced_stock_management end |
#available_date ⇒ Object
Returns the value of attribute available_date.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def available_date @available_date end |
#available_for_order ⇒ Object
Returns the value of attribute available_for_order.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def available_for_order @available_for_order end |
#available_later ⇒ Object
105 106 107 |
# File 'lib/prestashop/mapper/models/product.rb', line 105 def available_later @available_later.plain.truncate(125) end |
#available_now ⇒ Object
101 102 103 |
# File 'lib/prestashop/mapper/models/product.rb', line 101 def available_now @available_now.plain.truncate(125) end |
#cache_default_attribute ⇒ Object
Returns the value of attribute cache_default_attribute.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def cache_default_attribute @cache_default_attribute end |
#cache_has_attachment ⇒ Object
Returns the value of attribute cache_has_attachment.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def @cache_has_attachment end |
#cache_is_pack ⇒ Object
Returns the value of attribute cache_is_pack.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def cache_is_pack @cache_is_pack end |
#condition ⇒ Object
Returns the value of attribute condition.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def condition @condition end |
#customizable ⇒ Object
Returns the value of attribute customizable.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def customizable @customizable end |
#depth ⇒ Object
Returns the value of attribute depth.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def depth @depth end |
#description ⇒ Object
Returns the value of attribute description.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def description @description end |
#description_short ⇒ Object
85 86 87 |
# File 'lib/prestashop/mapper/models/product.rb', line 85 def description_short @description_short ? @description_short.restricted.truncate(252) : (description.truncate(252) if description) end |
#ean13 ⇒ Object
Returns the value of attribute ean13.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def ean13 @ean13 end |
#ecotax ⇒ Object
Returns the value of attribute ecotax.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def ecotax @ecotax end |
#height ⇒ Object
Returns the value of attribute height.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def height @height end |
#id ⇒ Object Also known as: find?
Find product by reference
and id_supplier
, returns id
152 153 154 |
# File 'lib/prestashop/mapper/models/product.rb', line 152 def id @id ||= self.class.find_by 'filter[reference]' => reference, 'filter[id_supplier]' => id_supplier end |
#id_categories ⇒ Object
Returns the value of attribute id_categories.
13 14 15 |
# File 'lib/prestashop/mapper/models/product.rb', line 13 def id_categories @id_categories end |
#id_category_default ⇒ Object
Returns the value of attribute id_category_default.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def id_category_default @id_category_default end |
#id_features ⇒ Object
Returns the value of attribute id_features.
13 14 15 |
# File 'lib/prestashop/mapper/models/product.rb', line 13 def id_features @id_features end |
#id_lang ⇒ Object
Returns the value of attribute id_lang.
13 14 15 |
# File 'lib/prestashop/mapper/models/product.rb', line 13 def id_lang @id_lang end |
#id_manufacturer ⇒ Object
Returns the value of attribute id_manufacturer.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def id_manufacturer @id_manufacturer end |
#id_product_redirect ⇒ Object
Returns the value of attribute id_product_redirect.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def id_product_redirect @id_product_redirect end |
#id_shop_default ⇒ Object
Returns the value of attribute id_shop_default.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def id_shop_default @id_shop_default end |
#id_supplier ⇒ Object
Returns the value of attribute id_supplier.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def id_supplier @id_supplier end |
#id_tax_rules_group ⇒ Object
Returns the value of attribute id_tax_rules_group.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def id_tax_rules_group @id_tax_rules_group end |
#indexed ⇒ Object
Returns the value of attribute indexed.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def indexed @indexed end |
#is_virtual ⇒ Object
Returns the value of attribute is_virtual.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def is_virtual @is_virtual end |
#link_rewrite ⇒ Object
89 90 91 |
# File 'lib/prestashop/mapper/models/product.rb', line 89 def link_rewrite @link_rewrite ? @link_rewrite.parameterize : name.parameterize end |
#location ⇒ Object
Returns the value of attribute location.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def location @location end |
#manufacturer_name ⇒ Object
Returns the value of attribute manufacturer_name.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def manufacturer_name @manufacturer_name end |
#meta_description=(value) ⇒ Object (writeonly)
Sets the attribute meta_description
14 15 16 |
# File 'lib/prestashop/mapper/models/product.rb', line 14 def (value) @meta_description = value end |
#meta_keywords=(value) ⇒ Object (writeonly)
Sets the attribute meta_keywords
14 15 16 |
# File 'lib/prestashop/mapper/models/product.rb', line 14 def (value) @meta_keywords = value end |
#meta_title=(value) ⇒ Object (writeonly)
Sets the attribute meta_title
14 15 16 |
# File 'lib/prestashop/mapper/models/product.rb', line 14 def (value) @meta_title = value end |
#minimal_quantity ⇒ Object
Returns the value of attribute minimal_quantity.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def minimal_quantity @minimal_quantity end |
#name ⇒ Object
81 82 83 |
# File 'lib/prestashop/mapper/models/product.rb', line 81 def name @name.plain.truncate(125) end |
#new ⇒ Object
Returns the value of attribute new.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def new @new end |
#on_sale ⇒ Object
Returns the value of attribute on_sale.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def on_sale @on_sale end |
#online_only ⇒ Object
Returns the value of attribute online_only.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def online_only @online_only end |
#position_in_category ⇒ Object
Returns the value of attribute position_in_category.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def position_in_category @position_in_category end |
#price ⇒ Object
Returns the value of attribute price.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def price @price end |
#quantity ⇒ Object
Returns the value of attribute quantity.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def quantity @quantity end |
#quantity_discount ⇒ Object
Returns the value of attribute quantity_discount.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def quantity_discount @quantity_discount end |
#redirect_type ⇒ Object
Returns the value of attribute redirect_type.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def redirect_type @redirect_type end |
#reference ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/prestashop/mapper/models/product.rb', line 93 def reference if @reference and not @reference.to_s.empty? @reference.to_s.length > 32 ? Digest::MD5.hexdigest(@reference) : @reference else Digest::MD5.hexdigest(name) end end |
#show_price ⇒ Object
Returns the value of attribute show_price.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def show_price @show_price end |
#supplier_reference ⇒ Object
Returns the value of attribute supplier_reference.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def supplier_reference @supplier_reference end |
#text_fields ⇒ Object
Returns the value of attribute text_fields.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def text_fields @text_fields end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def type @type end |
#unit_price_ratio ⇒ Object
Returns the value of attribute unit_price_ratio.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def unit_price_ratio @unit_price_ratio end |
#unity ⇒ Object
Returns the value of attribute unity.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def unity @unity end |
#upc ⇒ Object
Returns the value of attribute upc.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def upc @upc end |
#uploadable_files ⇒ Object
Returns the value of attribute uploadable_files.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def uploadable_files @uploadable_files end |
#visibility ⇒ Object
Returns the value of attribute visibility.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def visibility @visibility end |
#weight ⇒ Object
Returns the value of attribute weight.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def weight @weight end |
#wholesale_price ⇒ Object
Returns the value of attribute wholesale_price.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def wholesale_price @wholesale_price end |
#width ⇒ Object
Returns the value of attribute width.
8 9 10 |
# File 'lib/prestashop/mapper/models/product.rb', line 8 def width @width end |
Class Method Details
.deactivate(id_supplier) ⇒ Object
187 188 189 190 191 192 193 194 |
# File 'lib/prestashop/mapper/models/product.rb', line 187 def deactivate id_supplier first = (Date.today-365).strftime("%F") last = (Date.today-1).strftime("%F") products = where 'filter[date_upd]' => "[#{first},#{last}]", date: 1, 'filter[id_supplier]' => id_supplier, 'filter[active]' => 1, limit: 1000 if products and !products.empty? products.map{|p| update(p, active: 0)} end end |
.fixed_hash(id) ⇒ Object
177 178 179 180 181 182 183 184 185 |
# File 'lib/prestashop/mapper/models/product.rb', line 177 def fixed_hash id product = find id product.delete(:position_in_category) product.delete(:manufacturer_name) product.delete(:quantity) product.delete(:type) product.delete(:associations) product end |
Instance Method Details
#feature_hash(id_feature, id_feature_value) ⇒ Object
Generate hash of single feature
163 164 165 |
# File 'lib/prestashop/mapper/models/product.rb', line 163 def feature_hash id_feature, id_feature_value { id: id_feature, id_feature_value: id_feature_value } if id_feature and id_feature_value end |
#features_hash ⇒ Object
Generate hash of features
168 169 170 |
# File 'lib/prestashop/mapper/models/product.rb', line 168 def features_hash id_features.map{|f| feature_hash(f[:id_feature], f[:id_feature_value])} if id_features end |
#hash ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/prestashop/mapper/models/product.rb', line 109 def hash product = { id_supplier: id_supplier, id_manufacturer: id_manufacturer, id_category_default: id_category_default, id_shop_default: id_shop_default, id_tax_rules_group: id_tax_rules_group, on_sale: on_sale, online_only: online_only, ean13: ean13, upc: upc, ecotax: ecotax, minimal_quantity: minimal_quantity, price: price, wholesale_price: wholesale_price, reference: reference, active: active, redirect_type: '404', available_for_order: available_for_order, condition: condition, show_price: show_price, name: hash_lang(name, id_lang), description: hash_lang(description, id_lang), description_short: hash_lang(description_short, id_lang), link_rewrite: hash_lang(link_rewrite, id_lang), meta_title: hash_lang(, id_lang), meta_description: hash_lang(, id_lang), meta_keywords: hash_lang(, id_lang), available_now: hash_lang(available_now, id_lang), available_later: hash_lang(available_later, id_lang), associations: {} } unless id_categories_all.empty? product[:associations][:categories] = {} product[:associations][:categories][:category] = hash_ids(id_categories_all) end if features_hash product[:associations][:product_features] = {} product[:associations][:product_features][:product_feature] = features_hash end product end |
#id_categories_all ⇒ Object
172 173 174 |
# File 'lib/prestashop/mapper/models/product.rb', line 172 def id_categories_all [id_category_default, id_categories].flatten.uniq end |
#update(options = {}) ⇒ Object
Update product with given options
158 159 160 |
# File 'lib/prestashop/mapper/models/product.rb', line 158 def update = {} self.class.update(id, ) end |