Class: Rawbotz::StockProcessor
- Inherits:
-
Object
- Object
- Rawbotz::StockProcessor
- Includes:
- RawgentoModels
- Defined in:
- lib/rawbotz/processors/stock_processor.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#magento_shell_path ⇒ Object
Returns the value of attribute magento_shell_path.
Instance Method Summary collapse
-
#initialize(order, params) ⇒ StockProcessor
constructor
A new instance of StockProcessor.
-
#process! ⇒ Object
Add items to stock, setting them available if they were not before (and stock is positive).
Constructor Details
#initialize(order, params) ⇒ StockProcessor
Returns a new instance of StockProcessor.
10 11 12 13 14 15 |
# File 'lib/rawbotz/processors/stock_processor.rb', line 10 def initialize(order, params) @order = order @params = params @errors = [] @magento_shell_path = YAML.load_file(Rawbotz.conf_file_path)["local_shop"]["magento_shell_path"] end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
7 8 9 |
# File 'lib/rawbotz/processors/stock_processor.rb', line 7 def errors @errors end |
#magento_shell_path ⇒ Object
Returns the value of attribute magento_shell_path.
8 9 10 |
# File 'lib/rawbotz/processors/stock_processor.rb', line 8 def magento_shell_path @magento_shell_path end |
Instance Method Details
#process! ⇒ Object
Add items to stock, setting them available if they were not before (and stock is positive).
Returns and sets @error array which is empty if everything went smooth.
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 |
# File 'lib/rawbotz/processors/stock_processor.rb', line 21 def process! num_stocked = 0 @params.each do |param_name, param_value| if param_name.to_s.start_with?("qty_delivered_") && param_value != "" stock! param_name[14..-1], param_value num_stocked += 1 end end if @order.order_items.processible.where("num_stocked IS NULL").count == 0 @order.update(state: 'stocked', stocked_at: DateTime.now) else @errors << "Not all items stocked" end if num_stocked > 0 && num_stocked >= @errors.length && !magento_shell_path.nil? reindex_status = system("php #{@magento_shell_path} --reindex cataloginventory_stock") if reindex_status.nil? @errors << "Magento database reindexing failed" end end @errors end |