Sha256: f6eafaec8ca33e010c541feddc87552b75c5a39b76b3405a2cdb94c0e75513b3

Contents?: true

Size: 868 Bytes

Versions: 1

Compression:

Stored size: 868 Bytes

Contents

module Workarea
  decorate Storefront::CartsController, with: :cart_sharing do
    decorated do
      before_action :set_sharable_token
    end
    def from
      if order = Order.find_by(sharable_token: params[:token]) rescue nil

        add_sharable_items(order.items) 
        flash[:success] = t('workarea.storefront.cart_sharing.success')
      else
        flash[:error] = t('workarea.storefront.cart_sharing.failure')
      end

      redirect_to cart_path
    end

    private
    def add_sharable_items(items)
      this_order = self.current_order
      this_order.items = this_order.items + items 
      this_order.save
    end

    def set_sharable_token
      return true if self.current_order.sharable_token.present?
      self.current_order.sharable_token =  Workarea::Order.generate_unique_secure_token
      self.current_order.save
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-cart_sharing-1.0.3.pre app/controllers/workarea/storefront/carts_controller.decorator