-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
# see https://github.com/spree/spree/blob/master/backend/app/controllers/spree/admin/stock_items_controller.rb module Spree module Admin module StockItemsControllerDecorator def self.prepended(base) base.before_action :process_notifiees_on_stock_item, only: :update # We have not taken into account should stock_movement.save fails. # see https://github.com/spree/spree/blob/master/backend/app/controllers/spree/admin/stock_items_controller.rb#L13 base.before_action :process_notifiees_on_stock_movement, only: :create base.before_action :notify_notifiees, only: :destroy end private # We've made the executive decision by not keeping stocks. # Alert all customers that the product is available to purchase. def notify_notifiees stock_item_id = params[:id] stock_item = Spree::StockItem.find(stock_item_id) variant_id = stock_item.variant.id email_all_notifiees(variant_id) end def process_notifiees_on_stock_movement quantity = params[:stock_movement][:quantity].to_i variant_id = params[:variant_id] if quantity > 0 email_all_notifiees(variant_id) end end def email_all_notifiees(variant_id) product_id = Spree::Variant.find(variant_id).product.id notifiees = lookup_notifiees_by(product_id) send_notification_email(notifiees) # We said we'd delete their email address notifiees.destroy_all end def process_notifiees_on_stock_item stock_item_id = params[:id] stock_item = Spree::StockItem.find(stock_item_id) # Backorderable: boolean # stock_item.backorderable # Number of items in stock: integer # stock_item.count_on_hand if stock_item.count_on_hand > 0 variant_id = stock_item.variant.id email_all_notifiees(variant_id) end end def lookup_notifiees_by(product_id) ProductNotification.where(product_id: product_id) end def send_notification_email(notifiees) if notifiees.present? emails_to_send = notifiees.pluck(:email) # send the email end end end end end ::Spree::Admin::StockItemsController.prepend Spree::Admin::StockItemsControllerDecorator if ::Spree::Admin::StockItemsController.included_modules.exclude?(Spree::Admin::StockItemsControllerDecorator)
Related posts
-
Ask HN: Suggestions about platform to develop a customizable B2B marketplace
-
What is the right approach to handle an inventory system with Items and prices that may change over time? How do you adjust Item prices without affecting a past Sale that references it?
-
What headless ecommerce solution free that i can use without Shopify or WP?
-
Spree Commerce 4.3 released!
-
Show HN: Viezly – better code review from dependency diagram