class Prestashop::Mapper::Product
Attributes
active[RW]
additional_shipping_cost[RW]
advanced_stock_management[RW]
available_date[RW]
available_for_order[RW]
available_later[W]
available_now[W]
cache_default_attribute[RW]
cache_has_attachment[RW]
cache_is_pack[RW]
condition[RW]
customizable[RW]
depth[RW]
description[RW]
description_short[W]
ean13[RW]
ecotax[RW]
height[RW]
id[W]
id_categories[RW]
id_category_default[RW]
id_features[RW]
id_lang[RW]
id_manufacturer[RW]
id_product_redirect[RW]
id_shop_default[RW]
id_supplier[RW]
id_tax_rules_group[RW]
indexed[RW]
is_virtual[RW]
link_rewrite[W]
location[RW]
manufacturer_name[RW]
meta_description[W]
meta_keywords[W]
meta_title[W]
minimal_quantity[RW]
name[W]
new[RW]
on_sale[RW]
online_only[RW]
position_in_category[RW]
price[RW]
quantity[RW]
quantity_discount[RW]
redirect_type[RW]
reference[W]
show_price[RW]
supplier_reference[RW]
text_fields[RW]
type[RW]
unit_price_ratio[RW]
unity[RW]
upc[RW]
uploadable_files[RW]
visibility[RW]
weight[RW]
wholesale_price[RW]
width[RW]
Public Class Methods
deactivate(id_supplier)
click to toggle source
# 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)
click to toggle source
# 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
new(args = {})
click to toggle source
# 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
Public Instance Methods
available_later()
click to toggle source
# File lib/prestashop/mapper/models/product.rb, line 105 def available_later @available_later.plain.truncate(125) end
available_now()
click to toggle source
# File lib/prestashop/mapper/models/product.rb, line 101 def available_now @available_now.plain.truncate(125) end
description_short()
click to toggle source
# 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
feature_hash(id_feature, id_feature_value)
click to toggle source
Generate hash of single feature
# 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()
click to toggle source
Generate hash of features
# 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()
click to toggle source
# 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(meta_title, id_lang), meta_description: hash_lang(meta_description, id_lang), meta_keywords: hash_lang(meta_keywords, 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()
click to toggle source
Find product by reference
and id_supplier
, returns id
# 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
Also aliased as: find?
id_categories_all()
click to toggle source
# File lib/prestashop/mapper/models/product.rb, line 172 def id_categories_all [id_category_default, id_categories].flatten.uniq end
link_rewrite()
click to toggle source
# File lib/prestashop/mapper/models/product.rb, line 89 def link_rewrite @link_rewrite ? @link_rewrite.parameterize : name.parameterize end
name()
click to toggle source
# File lib/prestashop/mapper/models/product.rb, line 81 def name @name.plain.truncate(125) end
reference()
click to toggle source
# 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
update(options = {})
click to toggle source
Update product with given options
# File lib/prestashop/mapper/models/product.rb, line 158 def update options = {} self.class.update(id, options) end