Class: Magentwo::SalesRule

Inherits:
Base
  • Object
show all
Defined in:
lib/model/sales_rule.rb

Constant Summary collapse

Attributes =
%i(rule_id name store_labels description website_ids customer_group_ids uses_per_customer is_active condition action_condition stop_rules_processing is_advanced sort_order simple_action discount_amount discount_step apply_to_shipping times_used is_rss coupon_type use_auto_generation uses_per_coupon simple_free_shipping)

Constants inherited from Base

Base::DatasetMethods

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

[], all, base_path, #call, call, #check_presence, dataset, #delete, each, each_page, first, get, #initialize, lower_case_name, map, #save, #to_h, #validate

Constructor Details

This class inherits a constructor from Magentwo::Base

Class Method Details

.get_pathObject



21
22
23
# File 'lib/model/sales_rule.rb', line 21

def get_path
  "#{base_path}/search"
end

.unique_identifierObject



25
26
27
# File 'lib/model/sales_rule.rb', line 25

def unique_identifier
  :rule_id
end

Instance Method Details

#couponsObject



11
12
13
14
# File 'lib/model/sales_rule.rb', line 11

def coupons
  self.check_presence :rule_id
  Magentwo::Coupon.filter(:rule_id => self.rule_id).all
end

#generate(quantity: 1, length: 16, format: (:alpha), delimiter: "-", delimiter_at_every: 4) ⇒ Object



6
7
8
9
# File 'lib/model/sales_rule.rb', line 6

def generate quantity:1, length:16, format:(:alpha), delimiter:"-", delimiter_at_every:4
  self.check_presence :rule_id
  Magentwo::Coupon.generate self.rule_id, quantity:quantity, length:length, format:format, delimiter:delimiter, delimiter_at_every:delimiter_at_every
end

#to_jsonObject



16
17
18
# File 'lib/model/sales_rule.rb', line 16

def to_json
  Hash["rule", self.to_h].to_json
end