Sha256: bc2f78be504d34fe7a32b97906df0727d93e7c91d01ad1cecbc47a13abc3db6d

Contents?: true

Size: 1 KB

Versions: 34

Compression:

Stored size: 1 KB

Contents

module Workarea
  module Recommendation
    class UserActivityBased
      def initialize(user_activity)
        @user_activity = user_activity
      end

      def results
        if @user_activity.product_ids.blank? && @user_activity.category_ids.blank?
          popular_product_ids.take(max_results)
        else
          related_product_ids.take(max_results)
        end
      end

      def max_results
        # accommodate some missing or undisplayable products
        Workarea.config.per_page
      end

      def popular_product_ids
        Insights::TopProducts
          .current
          .results
          .map { |r| r['product_id'] }
          .take(max_results)
      end

      def related_product_ids
        query = Workarea::Search::RelatedProducts.new(
          product_ids: @user_activity.product_ids,
          category_ids: @user_activity.category_ids,
          exclude_product_ids: @user_activity.product_ids
        )

        query.results.map { |r| r[:catalog_id] }
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-core-3.4.45 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.44 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.43 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.42 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.41 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.40 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.39 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.38 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.37 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.36 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.35 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.34 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.33 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.32 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.31 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.30 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.29 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.28 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.27 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.4.26 app/queries/workarea/recommendation/user_activity_based.rb