Forked from octave/facebook_data_feed_controller.rb
Created
November 22, 2018 02:37
-
-
Save ychaker/b370553f0418ac9cdf727bcede3267ea to your computer and use it in GitHub Desktop.
Basic Facebook CSV Product Feed Support for Solidus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FacebookDataFeedController < ApplicationController | |
def export | |
@products = Spree::Product.available | |
respond_to do |format| | |
format.csv { send_data @products.to_fb_csv, filename: "facebook-data-feed.csv" } | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Spree::Product.class_eval do | |
def self.to_fb_csv | |
variants = all.uniq.map {|p| p.variants.present? ? p.variants : p.variant }.flatten(1) | |
CSV.generate do |csv| | |
csv << ['id','title','availability','description','condition','price','link','image_link','brand'] | |
variants.each do |v| | |
csv << [v.sku, v.name, v.in_stock? ? 'in stock' : 'out of stock', v.product.meta_description, 'new', v.price, ENV['BASE_URL'] + v.slug, v.display_image.attachment.url(:original), ENV['BRAND_NAME']] | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
get '/facebook-data-feed' => 'facebook_data_feed#export' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment