Shopify / shopify_transporter

The Transporter tool allows you to convert data from a third-party platform into a format that can be imported into Shopify.
MIT License
98 stars 43 forks source link

Does not extract or convert product categories. #136

Open JordanVerasamy opened 5 years ago

JordanVerasamy commented 5 years ago

CAUTION: Do not attach any sensitive information or PII

Please be careful not to include sensitive information in the files because this is a public repository (for example, real customer names, emails and addresses).

Problem:

Describe the problem you are experiencing with the gem.\

I want to migrate my product categories to Shopify.

(Some discussion about this exists in the Shopify Plus Partner slack. Can't share more details on public repo. DM me on slack if you're a Shopifolk and want to know more.)

Steps to Reproduce:

List the steps we can take to reproduce the problem:

1. 2.

zoephilipps commented 5 years ago

Would also like this feature. Or docs on how to accomplish this with the current version.

denisrpriebe commented 5 years ago

I ended up creating a custom pipeline to export categories from a Magento 1 instance into Shopify. By default, the Transporter tool actually extracts the category ids when the JSON file is created. What we need to do is set those category ids as tags on each product. Then in Shopify we can create automated collections based on products with matching category tag ids essentially grouping/categorizing them how they where in Magento 1.

After you have exported your products into a JSON file, you can do the following:

  1. Run the command:

    shopify_transporter generate ProductCategoriesToTags --object product create lib/product-categories-to-tags.rb
  2. Then add this code to your newly created product-categories-to-tags.rb file:

# frozen_string_literal: true
require 'shopify_transporter'

module CustomPipeline
  module Product
    class ProductCategoriesToTag < ShopifyTransporter::Pipeline::Stage
      def convert(input, record)

        if input.has_key?("category_ids")
            if input["categories"].has_key?("item")
                if input["category_ids"]["item"].is_a?(Array)
                    record['tags'] = input["category_ids"]["item"].join(', ')
                elsif input["category_ids"]["item"].is_a?(String)
                    record['tags'] = input["category_ids"]["item"]
                end
            end
        end

      end
    end
  end
end
  1. Finally, run the conversion command (shopify_transporter convert --object=product...) you use to generate your csv file. You CSV file should now have category ids in the "Tags" column.

Hope this helps!

Please excuse my poor Ruby code. I don't work with Ruby very often.

surajreddy commented 5 years ago

Thank you for sharing your approach @denisrpriebe! This is a great way to do this.