From 6dc2a3cd6292e3d719f65643156d153dfc5bfa3d Mon Sep 17 00:00:00 2001 From: Flavio Auciello Date: Fri, 17 Apr 2020 08:02:26 +0200 Subject: [PATCH 1/2] Test against Shopify Product CSVs Refs. - https://github.com/shopifypartners/product-csvs.git - https://www.shopify.com/partners/blog/shopify-upload-products-csv These new examples are failing. We fix in next commits. --- spec/features/solidus_importer/import_spec.rb | 47 ++++++++++++++++ spec/fixtures/solidus_importer/apparel.csv | 23 ++++++++ .../solidus_importer/home-and-garden.csv | 22 ++++++++ spec/fixtures/solidus_importer/jewelery.csv | 55 +++++++++++++++++++ .../shopify_products_apparel.csv | 23 ++++++++ 5 files changed, 170 insertions(+) create mode 100644 spec/fixtures/solidus_importer/apparel.csv create mode 100644 spec/fixtures/solidus_importer/home-and-garden.csv create mode 100644 spec/fixtures/solidus_importer/jewelery.csv create mode 100644 spec/fixtures/solidus_importer/shopify_products_apparel.csv diff --git a/spec/features/solidus_importer/import_spec.rb b/spec/features/solidus_importer/import_spec.rb index 40d96292..108cb07d 100644 --- a/spec/features/solidus_importer/import_spec.rb +++ b/spec/features/solidus_importer/import_spec.rb @@ -66,6 +66,53 @@ end end + context 'with Shopify Product CSVs' do + before do + allow(URI).to receive(:open) + end + + context 'with the export from Shopify Product CSVs - Apparel' do + let(:import_file) { solidus_importer_fixture_path('apparel.csv') } + let(:import_type) { :products } + let!(:shipping_category) { create(:shipping_category) } + + it 'imports a some products and a blue shirt with no variants' do + expect { import }.to change(Spree::Product, :count).from(0) + expect(import.state).to eq('completed') + + product = Spree::Product.find_by(slug: 'ocean-blue-shirt') + + expect(product.variants.count).to be_zero + end + end + + context 'with the export from Shopify Product CSVs - Jewelry' do + let(:import_file) { solidus_importer_fixture_path('jewelery.csv') } + let(:import_type) { :products } + let!(:shipping_category) { create(:shipping_category) } + + it 'imports a some products and a clay pot with two variants' do + expect { import }.to change(Spree::Product, :count).from(0) + expect(import.state).to eq('completed') + + product = Spree::Product.find_by(slug: 'clay-plant-pot') + + expect(product.variants.count).to eq 2 + end + end + + context 'with the export from Shopify Product CSVs - Home and Garden' do + let(:import_file) { solidus_importer_fixture_path('home-and-garden.csv') } + let(:import_type) { :products } + let!(:shipping_category) { create(:shipping_category) } + + it 'imports a some products' do + expect { import }.to change(Spree::Product, :count).from(0) + expect(import.state).to eq('completed') + end + end + end + context 'with a orders file' do let(:import_file) { solidus_importer_fixture_path('orders.csv') } let(:import_type) { :orders } diff --git a/spec/fixtures/solidus_importer/apparel.csv b/spec/fixtures/solidus_importer/apparel.csv new file mode 100644 index 00000000..0484abcd --- /dev/null +++ b/spec/fixtures/solidus_importer/apparel.csv @@ -0,0 +1,23 @@ +Handle,Title,Body (HTML),Vendor,Type,Tags,Published,Option1 Name,Option1 Value,Option2 Name,Option2 Value,Option3 Name,Option3 Value,Variant SKU,Variant Grams,Variant Inventory Tracker,Variant Inventory Qty,Variant Inventory Policy,Variant Fulfillment Service,Variant Price,Variant Compare At Price,Variant Requires Shipping,Variant Taxable,Variant Barcode,Image Src,Image Position,Image Alt Text,Gift Card,SEO Title,SEO Description,Google Shopping / Google Product Category,Google Shopping / Gender,Google Shopping / Age Group,Google Shopping / MPN,Google Shopping / AdWords Grouping,Google Shopping / AdWords Labels,Google Shopping / Condition,Google Shopping / Custom Product,Google Shopping / Custom Label 0,Google Shopping / Custom Label 1,Google Shopping / Custom Label 2,Google Shopping / Custom Label 3,Google Shopping / Custom Label 4,Variant Image,Variant Weight Unit,Variant Tax Code +ocean-blue-shirt,Ocean Blue Shirt,Ocean blue cotton shirt with a narrow collar and buttons down the front and long sleeves. Comfortable fit and tiled kalidoscope patterns. ,partners-demo,,men,true,Title,Default Title,,,,,,0,,1,deny,manual,50,,true,true,,https://burst.shopifycdn.com/photos/young-man-in-bright-fashion_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +classic-varsity-top,Classic Varsity Top,"Womens casual varsity top, This grey and black buttoned top is a sport-inspired piece complete with an embroidered letter. ",partners-demo,,women,true,Size,Small,,,,,,0,,1,deny,manual,60,,true,true,,https://burst.shopifycdn.com/photos/casual-fashion-woman_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +classic-varsity-top,,,,,,,,Medium,,,,,,0,,1,deny,manual,60,,true,true,,,,,,,,,,,,,,,,,,,,,,kg, +classic-varsity-top,,,,,,,,Large,,,,,,0,,1,deny,manual,60,,true,true,,,,,,,,,,,,,,,,,,,,,,kg, +yellow-wool-jumper,Yellow Wool Jumper,Knitted jumper in a soft wool blend with low dropped shoulders and wide sleeves and think cuffs. Perfect for keeping warm during Fall. ,partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,80,,true,true,,https://burst.shopifycdn.com/photos/autumn-photographer-taking-picture_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +floral-white-top,Floral White Top,Stylish sleeveless white top with a floral pattern. ,partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,75,,true,true,,https://burst.shopifycdn.com/photos/city-woman-fashion_925x@2x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +striped-silk-blouse,Striped Silk Blouse,Ultra-stylish black and red striped silk blouse with buckle collar and matching button pants. ,partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,50,,true,true,,https://burst.shopifycdn.com/photos/striped-blouse-fashion_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +classic-leather-jacket,Classic Leather Jacket,"Womans zipped leather jacket. Adjustable belt for a comfortable fit, complete with shoulder pads and front zip pocket. ",partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,80,,true,true,,https://burst.shopifycdn.com/photos/leather-jacket-and-tea_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +dark-denim-top,Dark Denim Top,"Classic dark denim top with chest pockets, long sleeves with buttoned cuffs, and a ripped hem effect.",partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,60,,true,true,,https://burst.shopifycdn.com/photos/young-female-models-denim_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +navy-sport-jacket,Navy Sports Jacket,"Long-sleeved navy waterproof jacket in thin, polyester fabric with a soft mesh inside. The durable water-repellent finish means you'll be kept comfortable and protected when out in all weathers.",partners-demo,,men,true,Title,Default Title,,,,,,0,,1,deny,manual,60,,true,true,,https://burst.shopifycdn.com/photos/mens-fall-fashion-jacket_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +dark-winter-jacket,Soft Winter Jacket,"Thick black winter jacket, with soft fleece lining. Perfect for those cold weather days.",partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,50,,true,true,,https://burst.shopifycdn.com/photos/smiling-woman-on-snowy-afternoon_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +black-leather-bag,Black Leather Bag,"Womens black leather bag, with ample space. Can be worn over the shoulder, or remove straps to carry in your hand. ",partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,30,,true,true,,https://burst.shopifycdn.com/photos/black-bag-over-the-shoulder_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +zipped-jacket,Zipped Jacket,Dark navy and light blue men's zipped waterproof jacket with an outer zipped chestpocket for easy storeage.,partners-demo,,men,true,Title,Default Title,,,,,,0,,1,deny,manual,65,,true,true,,https://burst.shopifycdn.com/photos/menswear-blue-zip-up-jacket_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +silk-summer-top,Silk Summer Top,Silk womens top with short sleeves and number pattern.,partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,70,,true,true,,https://burst.shopifycdn.com/photos/young-hip-woman-at-carnival_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +longsleeve-cotton-top,Long Sleeve Cotton Top,"Black cotton womens top, with long sleeves, no collar and a thick hem. ",partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,50,,true,true,,https://burst.shopifycdn.com/photos/woman-outside-brownstone_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +chequered-red-shirt,Chequered Red Shirt,"Classic mens plaid flannel shirt with long sleeves, in chequered style, with two chest pockets.",partners-demo,,men,true,Title,Default Title,,,,,,0,,1,deny,manual,50,,true,true,,https://burst.shopifycdn.com/photos/red-plaid-shirt_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +white-cotton-shirt,White Cotton Shirt,Plain white cotton long sleeved shirt with loose collar. Small buttons and front pocket. ,partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,30,,true,true,,https://burst.shopifycdn.com/photos/smiling-woman-poses_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +olive-green-jacket,Olive Green Jacket,Loose fitting olive green jacket with buttons and large pockets. Multicoloured pattern on the front of the shoulders.,partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,65,,true,true,,https://burst.shopifycdn.com/photos/urban-fashion_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +blue-silk-tuxedo,Blue Silk Tuxedo,Blue silk tuxedo with marbled aquatic pattern and dark lining. Sleeves are complete with rounded hem and black buttons.,partners-demo,,men,true,Title,Default Title,,,,,,0,,1,deny,manual,70,,true,true,,https://burst.shopifycdn.com/photos/man-adjusts-blue-tuxedo-bowtie_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +red-sports-tee,Red Sports Tee,Women's red sporty t-shirt with colorful details on the sleeves and a small white pocket.,partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,50,,true,true,,https://burst.shopifycdn.com/photos/womens-red-t-shirt_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +striped-skirt-and-top,Striped Skirt and Top,Black cotton top with matching striped skirt. ,partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,50,,true,true,,https://burst.shopifycdn.com/photos/woman-in-the-city_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +led-high-tops,LED High Tops,"Black high top shoes with green LED lights in the sole, tied up with laces and a buckle. ",partners-demo,,men,true,Title,Default Title,,,,,,0,,1,deny,manual,80,,true,true,,https://burst.shopifycdn.com/photos/putting-on-your-shoes_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, \ No newline at end of file diff --git a/spec/fixtures/solidus_importer/home-and-garden.csv b/spec/fixtures/solidus_importer/home-and-garden.csv new file mode 100644 index 00000000..82fca4e9 --- /dev/null +++ b/spec/fixtures/solidus_importer/home-and-garden.csv @@ -0,0 +1,22 @@ +Handle,Title,Body (HTML),Vendor,Type,Tags,Published,Option1 Name,Option1 Value,Option2 Name,Option2 Value,Option3 Name,Option3 Value,Variant SKU,Variant Grams,Variant Inventory Tracker,Variant Inventory Qty,Variant Inventory Policy,Variant Fulfillment Service,Variant Price,Variant Compare At Price,Variant Requires Shipping,Variant Taxable,Variant Barcode,Image Src,Image Position,Image Alt Text,Gift Card,SEO Title,SEO Description,Google Shopping / Google Product Category,Google Shopping / Gender,Google Shopping / Age Group,Google Shopping / MPN,Google Shopping / AdWords Grouping,Google Shopping / AdWords Labels,Google Shopping / Condition,Google Shopping / Custom Product,Google Shopping / Custom Label 0,Google Shopping / Custom Label 1,Google Shopping / Custom Label 2,Google Shopping / Custom Label 3,Google Shopping / Custom Label 4,Variant Image,Variant Weight Unit,Variant Tax Code,Cost per item +clay-plant-pot,Clay Plant Pot,

Classic blown clay pot for plants

,Company 123,Outdoor,"Pot, Plants",true,Size,Regular,,,,,,0,,1,deny,manual,9.99,,true,true,,https://burst.shopifycdn.com/photos/single-sprout-in-a-pot_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg,, +clay-plant-pot,,,,,,,,Large,,,,,,0,,3,deny,manual,15.99,,true,true,,https://burst.shopifycdn.com/photos/pot-with-a-single-sprout_925x.jpg,2,,,,,,,,,,,,,,,,,,,kg,, +copper-light,Copper Light,

Stylish copper bedside light

,Company 123,Indoor,"Copper, Bedroom",true,Title,Default Title,,,,,,0,,2,deny,manual,59.99,75,true,true,,https://burst.shopifycdn.com/photos/copper-light-in-bedroom_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg,, +cream-sofa,Cream Sofa,

Comfortable cream sofa with wooden base

,Company 123,Indoor,"Couch, Wood",true,Title,Default Title,,,,,,0,,4,deny,manual,500,750,true,true,,https://burst.shopifycdn.com/photos/condominium-interior-livingroom_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg,, +antique-drawers,Antique Drawers,

Antique wooden chest of drawers

,Company 123,Indoor,"Antique, Bedroom",true,Title,Default Title,,,,,,0,,2,deny,manual,250,300,true,true,,https://burst.shopifycdn.com/photos/babys-room_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg,, +white-bed-clothes,White Bed Clothes,

Sleek white bed clothes

,Company 123,Indoor,Bed,true,Title,Default Title,,,,,,0,,1,deny,manual,29.99,35,true,true,,https://burst.shopifycdn.com/photos/bright-hotel-room-bed_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg,, +pink-armchair,Pink Armchair,

Stylish pink armchair

,Company 123,Indoor,Chair,true,Title,Default Title,,,,,,0,,0,deny,manual,750,,true,true,,https://burst.shopifycdn.com/photos/soft-pink-cushioned-armchair-in-stately-salon_925x.jpg,,,false,,,,,,,,,,,,,,,,,kg,, +wooden-outdoor-table,Wooden Outdoor Table,

Chic wooden outdoor garden table

,Rustic LTD,Outdoor,"Wood, Garden",true,Title,Default Title,,,,,,0,,3,deny,manual,99.99,,true,true,,https://burst.shopifycdn.com/photos/cafe-patio_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg,, +brown-throw-pillows,Brown Throw Pillows,

Stylish brown throw pillows

,Rustic LTD,Indoor,Pillows,true,Title,Default Title,,,,,,0,,5,deny,manual,19.99,25.99,true,true,,https://burst.shopifycdn.com/photos/bedroom-bed-with-brown-throw-pillows_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg,, +white-ceramic-pot,White Ceramic Pot,

Homemade white ceramic flower pot

,Rustic LTD,Indoor,"Pot, Plants",true,Title,Default Title,,,,,,0,,1,deny,manual,15.99,30,true,true,,https://burst.shopifycdn.com/photos/house-plant-in-white-pot_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg,, +yellow-watering-can,Yellow watering can,

Vintage vibrant watering can

,Rustic LTD,Outdoor,Plants,true,Title,Default Title,,,,,,0,,4,deny,manual,40.99,50,true,true,,https://burst.shopifycdn.com/photos/flowers-in-yellow-watering-can_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg,, +gardening-hand-trowel,Gardening hand trowel,

Metal gardening hand trowel with wooden handle

,Rustic LTD,Outdoor,Plants,true,Title,Default Title,,,,,,0,,2,deny,manual,10.99,25,true,true,,https://burst.shopifycdn.com/photos/spring-gardening-set-up_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg,, +biodegradable-cardboard-pots,Biodegradable cardboard pots,

Biodegradable outdoor cardboard pots

,Rustic LTD,Outdoor,"Garden, Plants",true,Title,Default Title,,,,,,0,shopify,8,deny,manual,10,,true,true,,https://burst.shopifycdn.com/photos/potted-seeds_925x.jpg,,,false,,,,,,,,,,,,,,,,,kg,, +grey-sofa,Grey Sofa,

Large four seater grey sofa

,Rustic LTD,Indoor,Sofa,true,Title,Default Title,,,,,,0,,6,deny,manual,29.99,35,true,true,,https://burst.shopifycdn.com/photos/large-grey-sofa-by-brick-wall_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg,, +wooden-outdoor-slats,Wooden outdoor slats,

Wooden outdoor fencing slats

,Rustic LTD,Outdoor,"Wood, Garden",true,Title,Default Title,,,,,,0,,0,deny,manual,25.99,35,true,true,,https://burst.shopifycdn.com/photos/house-plant-on-wooden-slat-wall_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg,, +wooden-fence,Wooden Fence,

Wooden garden fence

,Rustic LTD,Outdoor,"Garden, Wood",true,Title,Default Title,,,,,,0,,5,deny,manual,200,300,true,true,,https://burst.shopifycdn.com/photos/picket-fence-flowers_925x.jpg,,,false,,,,,,,,,,,,,,,,,kg,, +yellow-sofa,Yellow Sofa,

Two seater yellow sofa with wooden legs

,Home Sweet Home,Indoor,Sofa,true,Title,Default Title,,,,,,0,,5,deny,manual,99.99,150,true,true,,https://burst.shopifycdn.com/photos/yellow-couch-by-black-and-white-mural_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg,, +knitted-throw-pillows,Knitted Throw Pillows,

Homemade knitted throw pillows in a variety of colors

,Home Sweet Home,Indoor,Pillows,true,Title,Default Title,,,,,,0,,1,deny,manual,19.99,25.99,true,true,,https://burst.shopifycdn.com/photos/yellow-sofa-with-throw-pillows_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg,, +vanilla-candle,Vanilla candle,

Vanilla scent candle in jar

,Home Sweet Home,Indoor,Candle,true,Title,Default Title,,,,,,0,,5,deny,manual,15.99,30,true,true,,https://burst.shopifycdn.com/photos/diy-organic-candle_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg,, +black-bean-bag,Black Beanbag,

Black leather beanbag

,Company 123,Indoor,"Black, Leather",true,Title,Default Title,,,,,,0,,6,deny,manual,69.99,80,true,true,,https://burst.shopifycdn.com/photos/comfortable-living-room-cat_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg,, +bedside-table,Bedside Table,

Wooden bedside table

,Company 123,Indoor,"Wood, Bedroom",true,Title,Default Title,,,,,,0,,1,deny,manual,69.99,85,true,true,,https://burst.shopifycdn.com/photos/dark-wall-bedside-table_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg,, \ No newline at end of file diff --git a/spec/fixtures/solidus_importer/jewelery.csv b/spec/fixtures/solidus_importer/jewelery.csv new file mode 100644 index 00000000..691a635d --- /dev/null +++ b/spec/fixtures/solidus_importer/jewelery.csv @@ -0,0 +1,55 @@ +Handle,Title,Body (HTML),Vendor,Type,Tags,Published,Option1 Name,Option1 Value,Option2 Name,Option2 Value,Option3 Name,Option3 Value,Variant SKU,Variant Grams,Variant Inventory Tracker,Variant Inventory Qty,Variant Inventory Policy,Variant Fulfillment Service,Variant Price,Variant Compare At Price,Variant Requires Shipping,Variant Taxable,Variant Barcode,Image Src,Image Position,Image Alt Text,Gift Card,SEO Title,SEO Description,Google Shopping / Google Product Category,Google Shopping / Gender,Google Shopping / Age Group,Google Shopping / MPN,Google Shopping / AdWords Grouping,Google Shopping / AdWords Labels,Google Shopping / Condition,Google Shopping / Custom Product,Google Shopping / Custom Label 0,Google Shopping / Custom Label 1,Google Shopping / Custom Label 2,Google Shopping / Custom Label 3,Google Shopping / Custom Label 4,Variant Image,Variant Weight Unit,Variant Tax Code +chain-bracelet,7 Shakra Bracelet,"7 chakra bracelet, in blue or black.",Company 123,Bracelet,Beads,true,Color,Blue,,,,,,0,,1,deny,manual,42.99,44.99,true,true,,https://burst.shopifycdn.com/photos/7-chakra-bracelet_925x.jpg,1,,false,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/navy-blue-chakra-bracelet_925x.jpg,kg, +chain-bracelet,,,,,,,,Black,,,,,,0,,0,deny,manual,42.99,44.99,true,true,,https://burst.shopifycdn.com/photos/navy-blue-chakra-bracelet_925x.jpg,2,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/7-chakra-bracelet_925x.jpg,kg, +leather-anchor,Anchor Bracelet Mens,Black leather bracelet with gold or silver anchor for men.,Company 123,Bracelet,"Anchor, Gold, Leather, Silver",true,Color,Gold,,,,,,0,,1,deny,manual,69.99,85,true,true,,https://burst.shopifycdn.com/photos/anchor-bracelet-mens_925x.jpg,1,,false,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/anchor-bracelet-mens_925x.jpg,kg, +leather-anchor,,,,,,,,Silver,,,,,,0,,0,deny,manual,55,85,true,true,,https://burst.shopifycdn.com/photos/anchor-bracelet-for-men_925x.jpg,2,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/anchor-bracelet-for-men_925x.jpg,kg, +leather-anchor,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/leather-anchor-bracelet-for-men_925x.jpg,3,,,,,,,,,,,,,,,,,,,, +bangle-bracelet,Bangle Bracelet,Gold bangle bracelet with studded jewels.,Company 123,Bracelet,"Diamond, Gem, Gold",true,Title,Default Title,,,,,,0,,1,deny,manual,39.99,43.99,true,true,,https://burst.shopifycdn.com/photos/bangle-bracelet-with-jewels_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +bangle-bracelet-with-feathers,Boho Bangle Bracelet,Gold boho bangle bracelet with multicolor tassels.,Company 123,Bracelet,Gold,true,Title,Default Title,,,,,,0,,1,deny,manual,42.99,44.99,true,true,,https://burst.shopifycdn.com/photos/bangle-bracelet-with-feathers_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +boho-earrings,Boho Earrings,Turquoise globe earrings on 14k gold hooks.,Company 123,Earrings,"Silver, Turquoise",true,Title,Default Title,,,,,,28,,1,deny,manual,27.99,35.99,true,true,,https://burst.shopifycdn.com/photos/boho-earrings_925x.jpg,1,,false,,,,,,,,,,,,,,,,,oz, +boho-earrings,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/inspired-woman_925x.jpg,2,,,,,,,,,,,,,,,,,,,, +boho-earrings,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/necklace-earrings-set_925x.jpg,3,,,,,,,,,,,,,,,,,,,, +choker-with-bead,Choker with Bead,Black choker necklace with 14k gold bead.,Company 123,Necklace,"Gold, Leather",true,Title,Default Title,,,,,,0,,1,deny,manual,14.99,19.99,true,true,,https://burst.shopifycdn.com/photos/black-choker-with-bead_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +choker-with-bead,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/choker-with-bead_925x.jpg,2,,,,,,,,,,,,,,,,,,,, +choker-with-gold-pendant,Choker with Gold Pendant,"Black cord choker with gold pendant. Beautifully died black leather shapes a choker necklace with findings of 14k yellow gold, displaying gold pendant in a gorgeous balance of dark and light, delicate and strong.
",Company 123,Necklace,"Choker, Gold, Leather, Pendant",true,Title,Default Title,,,,,,0,,1,deny,manual,29.99,,true,true,,https://burst.shopifycdn.com/photos/choker-with-gold-pendant_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +choker-with-gold-pendant,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/choker-pendant-closeup_925x.jpg,2,,,,,,,,,,,,,,,,,,,, +choker-with-triangle,Choker with Triangle,Black choker with silver triangle pendant.,Company 123,Necklace,"Leather, Silver, Triangle",true,Title,Default Title,,,,,,0,,1,deny,manual,47.99,49.99,true,true,,https://burst.shopifycdn.com/photos/choker-with-triangle_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +dainty-gold-neclace,Dainty Gold Necklace,Dainty gold necklace with two pendants.,Company 123,Necklace,"Gold, Pendant",true,Title,Default Title,,,,,,0,,1,deny,manual,63.99,69.99,true,true,,https://burst.shopifycdn.com/photos/dainty-gold-necklace_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +dainty-gold-neclace,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/womens-gold-necklace_925x.jpg,2,,,,,,,,,,,,,,,,,,,, +dreamcatcher-pendant-necklace,Dreamcatcher Pendant Necklace,"Turquoise beaded dream catcher necklace. Silver feathers adorn this beautiful dream catcher, which move and twinkle as you walk.",Sterling Ltd,Necklace,"Dreamcatcher, Pendant, Silver, Turquoise",true,Title,Default Title,,,,,,0,,1,deny,manual,23.99,41.99,true,true,,https://burst.shopifycdn.com/photos/dreamcatcher-pendant-necklace_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +dreamcatcher-pendant-necklace,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/gold-dream-catcher-necklace_925x.jpg,2,,,,,,,,,,,,,,,,,,,, +galaxy-earrings,Galaxy Earrings,"One set of galaxy earrings, with sterling silver clasps.",Sterling Ltd,Earrings,"Blue, Galaxy, Silver",true,Title,Default Title,,,,,,0,,1,deny,manual,37.99,45.99,true,true,,https://burst.shopifycdn.com/photos/galaxy-earrings_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +gemstone,Gemstone Necklace,"

Gemstone pendant, housed in sterling silver, with sterling silver chain.

+",Sterling Ltd,Necklace,"Blue, Gem, Purple, Silver, Turquoise",true,Colour,Blue,,,,,,0,,1,deny,manual,27.99,29.99,true,true,,https://burst.shopifycdn.com/photos/blue-gemstone-pendant_925x.jpg,1,,false,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/blue-gemstone-pendant_925x.jpg,kg, +gemstone,,,,,,,,Purple,,,,,,0,,0,deny,manual,27.99,29.99,true,true,,https://burst.shopifycdn.com/photos/gemstone-necklace_925x.jpg,2,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/purple-gemstone-necklace_925x.jpg,kg, +gemstone,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/womens-necklace_925x.jpg,3,,,,,,,,,,,,,,,,,,,, +gemstone,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/purple-gemstone-necklace_925x.jpg,4,,,,,,,,,,,,,,,,,,,, +gold-bird-necklace,Gold Bird Necklace,"14k Gold delicate necklace, with bird between two chains.",Company 123,Necklace,"Bird, Gold",true,Title,Default Title,,,,,,0,,1,deny,manual,79.99,,true,true,,https://burst.shopifycdn.com/photos/gold-bird-necklace_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +looped-earrings,Gold Elephant Earrings,"Small 14k gold elephant earrings, with opal ear detail.",Company 123,Earrings,"Gold, Silver",true,Title,Default Title,,,,,,0,,1,deny,manual,54.99,,true,true,,https://burst.shopifycdn.com/photos/elephant-earrings_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +guardian-angel-earrings,Guardian Angel Earrings,Sterling silver guardian angel earrings with diamond gemstones.,Sterling Ltd,Earrings,"Angel, Silver",true,Title,Default Title,,,,,,0,,1,deny,manual,19.99,,true,true,,https://burst.shopifycdn.com/photos/guardian-angel-earrings_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +guardian-angel-earrings,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/guardian-angel-earring-closeup_925x.jpg,2,,,,,,,,,,,,,,,,,,,, +moon-charm-bracelet,Moon Charm Bracelet,Moon 14k gold chain friendship bracelet.,Company 123,Bracelet,"Gold, Moon",true,Title,Default Title,,,,,,0,,1,deny,manual,47.99,49.99,true,true,,https://burst.shopifycdn.com/photos/womens-hand-moon-bracelet-_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +moon-charm-bracelet,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/moon-friendship-bracelet_925x.jpg,2,,,,,,,,,,,,,,,,,,,, +moon-charm-bracelet,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/womens-hand-charm-bracelet_925x.jpg,3,,,,,,,,,,,,,,,,,,,, +origami-crane-necklace,Origami Crane Necklace,Sterling silver origami crane necklace.,Sterling Ltd,Necklace,"Crane, Origami, Silver",true,Title,Default Title,,,,,,0,,1,deny,manual,75.99,,true,true,,https://burst.shopifycdn.com/photos/origami-crane-necklace-gold_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +origami-crane-necklace,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/silver-origami-necklace_925x.jpg,2,,,,,,,,,,,,,,,,,,,, +origami-crane-necklace,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/origami-crane-necklace_925x.jpg,3,,,,,,,,,,,,,,,,,,,, +origami-crane-necklace,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/womens-green-turtleneck_925x.jpg,4,,,,,,,,,,,,,,,,,,,, +pretty-gold-necklace,Pretty Gold Necklace,14k gold and turquoise necklace. Stunning beaded turquoise on gold and pendant filled double chain design.,Company 123,Necklace,"Gold, Turquoise",true,Title,Default Title,,,,,,0,,1,deny,manual,44.95,63.99,true,true,,https://burst.shopifycdn.com/photos/pretty-gold-necklace_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +pretty-gold-necklace,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/necklace-earrings-set_925x.jpg,2,,,,,,,,,,,,,,,,,,,, +pretty-gold-necklace,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/inspired-woman_925x.jpg,3,,,,,,,,,,,,,,,,,,,, +silver-threader-necklace,Silver Threader Necklace,Sterling silver chain thread through circle necklace.,Sterling Ltd,Necklace,Silver,true,Title,Default Title,,,,,,0,,1,deny,manual,14.99,19.99,true,true,,https://burst.shopifycdn.com/photos/silver-threader-necklace_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +silver-threader-necklace,,,,,,,,,,,,,,,,,,,,,,,,https://burst.shopifycdn.com/photos/threader-necklace-closeup_925x.jpg,2,,,,,,,,,,,,,,,,,,,, +stylish-summer-neclace,Stylish Summer Necklace,Double chained gold boho necklace with turquoise pendant.,Company 123,Necklace,"Gold, Turquoise",true,Title,Default Title,,,,,,0,,1,deny,manual,44.99,,true,true,,https://burst.shopifycdn.com/photos/stylish-summer-necklace_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, \ No newline at end of file diff --git a/spec/fixtures/solidus_importer/shopify_products_apparel.csv b/spec/fixtures/solidus_importer/shopify_products_apparel.csv new file mode 100644 index 00000000..0484abcd --- /dev/null +++ b/spec/fixtures/solidus_importer/shopify_products_apparel.csv @@ -0,0 +1,23 @@ +Handle,Title,Body (HTML),Vendor,Type,Tags,Published,Option1 Name,Option1 Value,Option2 Name,Option2 Value,Option3 Name,Option3 Value,Variant SKU,Variant Grams,Variant Inventory Tracker,Variant Inventory Qty,Variant Inventory Policy,Variant Fulfillment Service,Variant Price,Variant Compare At Price,Variant Requires Shipping,Variant Taxable,Variant Barcode,Image Src,Image Position,Image Alt Text,Gift Card,SEO Title,SEO Description,Google Shopping / Google Product Category,Google Shopping / Gender,Google Shopping / Age Group,Google Shopping / MPN,Google Shopping / AdWords Grouping,Google Shopping / AdWords Labels,Google Shopping / Condition,Google Shopping / Custom Product,Google Shopping / Custom Label 0,Google Shopping / Custom Label 1,Google Shopping / Custom Label 2,Google Shopping / Custom Label 3,Google Shopping / Custom Label 4,Variant Image,Variant Weight Unit,Variant Tax Code +ocean-blue-shirt,Ocean Blue Shirt,Ocean blue cotton shirt with a narrow collar and buttons down the front and long sleeves. Comfortable fit and tiled kalidoscope patterns. ,partners-demo,,men,true,Title,Default Title,,,,,,0,,1,deny,manual,50,,true,true,,https://burst.shopifycdn.com/photos/young-man-in-bright-fashion_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +classic-varsity-top,Classic Varsity Top,"Womens casual varsity top, This grey and black buttoned top is a sport-inspired piece complete with an embroidered letter. ",partners-demo,,women,true,Size,Small,,,,,,0,,1,deny,manual,60,,true,true,,https://burst.shopifycdn.com/photos/casual-fashion-woman_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +classic-varsity-top,,,,,,,,Medium,,,,,,0,,1,deny,manual,60,,true,true,,,,,,,,,,,,,,,,,,,,,,kg, +classic-varsity-top,,,,,,,,Large,,,,,,0,,1,deny,manual,60,,true,true,,,,,,,,,,,,,,,,,,,,,,kg, +yellow-wool-jumper,Yellow Wool Jumper,Knitted jumper in a soft wool blend with low dropped shoulders and wide sleeves and think cuffs. Perfect for keeping warm during Fall. ,partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,80,,true,true,,https://burst.shopifycdn.com/photos/autumn-photographer-taking-picture_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +floral-white-top,Floral White Top,Stylish sleeveless white top with a floral pattern. ,partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,75,,true,true,,https://burst.shopifycdn.com/photos/city-woman-fashion_925x@2x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +striped-silk-blouse,Striped Silk Blouse,Ultra-stylish black and red striped silk blouse with buckle collar and matching button pants. ,partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,50,,true,true,,https://burst.shopifycdn.com/photos/striped-blouse-fashion_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +classic-leather-jacket,Classic Leather Jacket,"Womans zipped leather jacket. Adjustable belt for a comfortable fit, complete with shoulder pads and front zip pocket. ",partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,80,,true,true,,https://burst.shopifycdn.com/photos/leather-jacket-and-tea_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +dark-denim-top,Dark Denim Top,"Classic dark denim top with chest pockets, long sleeves with buttoned cuffs, and a ripped hem effect.",partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,60,,true,true,,https://burst.shopifycdn.com/photos/young-female-models-denim_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +navy-sport-jacket,Navy Sports Jacket,"Long-sleeved navy waterproof jacket in thin, polyester fabric with a soft mesh inside. The durable water-repellent finish means you'll be kept comfortable and protected when out in all weathers.",partners-demo,,men,true,Title,Default Title,,,,,,0,,1,deny,manual,60,,true,true,,https://burst.shopifycdn.com/photos/mens-fall-fashion-jacket_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +dark-winter-jacket,Soft Winter Jacket,"Thick black winter jacket, with soft fleece lining. Perfect for those cold weather days.",partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,50,,true,true,,https://burst.shopifycdn.com/photos/smiling-woman-on-snowy-afternoon_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +black-leather-bag,Black Leather Bag,"Womens black leather bag, with ample space. Can be worn over the shoulder, or remove straps to carry in your hand. ",partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,30,,true,true,,https://burst.shopifycdn.com/photos/black-bag-over-the-shoulder_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +zipped-jacket,Zipped Jacket,Dark navy and light blue men's zipped waterproof jacket with an outer zipped chestpocket for easy storeage.,partners-demo,,men,true,Title,Default Title,,,,,,0,,1,deny,manual,65,,true,true,,https://burst.shopifycdn.com/photos/menswear-blue-zip-up-jacket_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +silk-summer-top,Silk Summer Top,Silk womens top with short sleeves and number pattern.,partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,70,,true,true,,https://burst.shopifycdn.com/photos/young-hip-woman-at-carnival_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +longsleeve-cotton-top,Long Sleeve Cotton Top,"Black cotton womens top, with long sleeves, no collar and a thick hem. ",partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,50,,true,true,,https://burst.shopifycdn.com/photos/woman-outside-brownstone_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +chequered-red-shirt,Chequered Red Shirt,"Classic mens plaid flannel shirt with long sleeves, in chequered style, with two chest pockets.",partners-demo,,men,true,Title,Default Title,,,,,,0,,1,deny,manual,50,,true,true,,https://burst.shopifycdn.com/photos/red-plaid-shirt_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +white-cotton-shirt,White Cotton Shirt,Plain white cotton long sleeved shirt with loose collar. Small buttons and front pocket. ,partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,30,,true,true,,https://burst.shopifycdn.com/photos/smiling-woman-poses_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +olive-green-jacket,Olive Green Jacket,Loose fitting olive green jacket with buttons and large pockets. Multicoloured pattern on the front of the shoulders.,partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,65,,true,true,,https://burst.shopifycdn.com/photos/urban-fashion_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +blue-silk-tuxedo,Blue Silk Tuxedo,Blue silk tuxedo with marbled aquatic pattern and dark lining. Sleeves are complete with rounded hem and black buttons.,partners-demo,,men,true,Title,Default Title,,,,,,0,,1,deny,manual,70,,true,true,,https://burst.shopifycdn.com/photos/man-adjusts-blue-tuxedo-bowtie_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +red-sports-tee,Red Sports Tee,Women's red sporty t-shirt with colorful details on the sleeves and a small white pocket.,partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,50,,true,true,,https://burst.shopifycdn.com/photos/womens-red-t-shirt_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +striped-skirt-and-top,Striped Skirt and Top,Black cotton top with matching striped skirt. ,partners-demo,,women,true,Title,Default Title,,,,,,0,,1,deny,manual,50,,true,true,,https://burst.shopifycdn.com/photos/woman-in-the-city_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, +led-high-tops,LED High Tops,"Black high top shoes with green LED lights in the sole, tied up with laces and a buckle. ",partners-demo,,men,true,Title,Default Title,,,,,,0,,1,deny,manual,80,,true,true,,https://burst.shopifycdn.com/photos/putting-on-your-shoes_925x.jpg,1,,false,,,,,,,,,,,,,,,,,kg, \ No newline at end of file From 9293e57ec5ad80349d24ed643b91edc91d5bf592 Mon Sep 17 00:00:00 2001 From: Flavio Auciello Date: Fri, 17 Apr 2020 08:02:26 +0200 Subject: [PATCH 2/2] Fix product/variant processors I found some product export sample CSV files in [this repository](https://github.com/shopifypartners/product-csvs.git). I've added some spec examples to test our import against those files. These tests are failing, so we need to change some of our assumptions about import logic: + `Variant SKU` is optional, so if present use it, generate new one otherwise. + when `Title` field is present we update a product. + when no `OptionValue1` is blank or `Default Title`, we update the master variant. --- lib/solidus_importer/processors/product.rb | 17 +++--- lib/solidus_importer/processors/variant.rb | 37 ++++++++---- spec/features/solidus_importer/import_spec.rb | 10 +++- .../processors/product_spec.rb | 12 ---- .../processors/variant_spec.rb | 60 ++++++++++++------- 5 files changed, 81 insertions(+), 55 deletions(-) diff --git a/lib/solidus_importer/processors/product.rb b/lib/solidus_importer/processors/product.rb index bf700a19..c25471b7 100644 --- a/lib/solidus_importer/processors/product.rb +++ b/lib/solidus_importer/processors/product.rb @@ -23,21 +23,20 @@ def check_data end def prepare_product - Spree::Product.find_or_initialize_by(slug: @data['Handle']) do |product| + Spree::Product.find_or_initialize_by(slug: @data['Handle']) + end + + def process_product + prepare_product.tap do |product| product.slug = @data['Handle'] product.price = options[:price] product.shipping_category = options[:shipping_category] - end.tap do |product| + # Apply the row attributes product.name = @data['Title'] unless @data['Title'].nil? - end - end - def process_product - if @data['Variant SKU'].present? - Spree::Product.find_by!(slug: @data['Handle']) - else - prepare_product.tap(&:save!) + # Save the product + product.save! end end end diff --git a/lib/solidus_importer/processors/variant.rb b/lib/solidus_importer/processors/variant.rb index a0381d26..8c9147a5 100644 --- a/lib/solidus_importer/processors/variant.rb +++ b/lib/solidus_importer/processors/variant.rb @@ -3,32 +3,47 @@ module SolidusImporter module Processors class Variant < Base + attr_accessor :product + def call(context) @data = context.fetch(:data) - return unless variant? + self.product = context.fetch(:product) || raise(ArgumentError, 'missing :product in context') - product = context.fetch(:product) - variant = process_variant(product) - context.merge!(variant: variant) + context.merge!(variant: process_variant) end private - def prepare_variant(product) - Spree::Variant.find_or_initialize_by(sku: @data['Variant SKU']) do |variant| + def prepare_variant + return product.master if master_variant? + + @prepare_variant ||= Spree::Variant.find_or_initialize_by(sku: sku) do |variant| variant.product = product - end.tap do |variant| + end + end + + def process_variant + prepare_variant.tap do |variant| # Apply the row attributes variant.weight = @data['Variant Weight'] unless @data['Variant Weight'].nil? + + # Save the product + variant.save! end end - def process_variant(product) - prepare_variant(product).tap(&:save!) + def master_variant? + ov1 = @data['Option1 Value'] + ov1.blank? || ov1 == 'Default Title' + end + + def sku + @data['Variant SKU'] || generate_sku end - def variant? - @variant ||= @data['Variant SKU'].present? + def generate_sku + variant_part = @data['Option1 Value'].parameterize + "#{product.slug}-#{variant_part}" end end end diff --git a/spec/features/solidus_importer/import_spec.rb b/spec/features/solidus_importer/import_spec.rb index 108cb07d..ea701454 100644 --- a/spec/features/solidus_importer/import_spec.rb +++ b/spec/features/solidus_importer/import_spec.rb @@ -95,9 +95,11 @@ expect { import }.to change(Spree::Product, :count).from(0) expect(import.state).to eq('completed') - product = Spree::Product.find_by(slug: 'clay-plant-pot') + product = Spree::Product.find_by(slug: 'gemstone') expect(product.variants.count).to eq 2 + expect(product.variants.find_by(sku: 'gemstone-blue')).to be_present + expect(product.variants.find_by(sku: 'gemstone-purple')).to be_present end end @@ -109,6 +111,12 @@ it 'imports a some products' do expect { import }.to change(Spree::Product, :count).from(0) expect(import.state).to eq('completed') + + product = Spree::Product.find_by(slug: 'clay-plant-pot') + + expect(product.variants.count).to eq 2 + expect(product.variants.find_by(sku: 'clay-plant-pot-large')).to be_present + expect(product.variants.find_by(sku: 'clay-plant-pot-regular')).to be_present end end end diff --git a/spec/lib/solidus_importer/processors/product_spec.rb b/spec/lib/solidus_importer/processors/product_spec.rb index d47ff999..22f78dcb 100644 --- a/spec/lib/solidus_importer/processors/product_spec.rb +++ b/spec/lib/solidus_importer/processors/product_spec.rb @@ -41,18 +41,6 @@ expect(product.reload.name).to eq('A product name') end end - - context 'with an existing invalid product' do - let!(:product) do - create(:product, slug: data['Handle']).tap { |product| product.update_column(:name, '') } - end - - before { data['Title'] = nil } - - it 'raises an exception' do - expect { described_method }.to raise_error(ActiveRecord::RecordInvalid, /Name can't be blank/) - end - end end end end diff --git a/spec/lib/solidus_importer/processors/variant_spec.rb b/spec/lib/solidus_importer/processors/variant_spec.rb index 91e61c38..d9ffd81a 100644 --- a/spec/lib/solidus_importer/processors/variant_spec.rb +++ b/spec/lib/solidus_importer/processors/variant_spec.rb @@ -14,11 +14,7 @@ end it 'raises an exception' do - if Spree.solidus_gem_version < Gem::Version.new('2.8') - expect { described_method }.to raise_error(RuntimeError, /No master variant found/) - else - expect { described_method }.to raise_error(ActiveRecord::RecordInvalid, /Product must exist/) - end + expect { described_method }.to raise_error(ArgumentError, 'missing :product in context') end end @@ -27,38 +23,58 @@ { data: data, product: product } end let(:data) { build(:solidus_importer_row_variant, :with_import).data } - let(:product) { build_stubbed(:product, slug: data['Handle']) } - let(:result) { context.merge(variant: Spree::Variant.last) } + let!(:product) { create(:product, slug: data['Handle']) } before do - allow(product).to receive(:touch) allow(Spree::ShippingCategory).to receive(:last).and_return(build_stubbed(:shipping_category)) end - it 'creates a new variant' do - expect { described_method }.to change { Spree::Variant.count }.by(1) - expect(described_method).to eq(result) + context 'when "Option1 Value" is "Some value"' do + let(:result) { context.merge(variant: product.variants.first) } + + before { data.merge! 'Option1 Value' => 'Some value' } + + it 'creates a new variant' do + expect { described_method }.to change { Spree::Variant.count }.by(1) + expect(described_method).to eq(result) + expect(product.variants.first.weight).to eq 20.0 + end end - context 'with an existing valid variant' do - let!(:variant) { create(:variant, sku: data['Variant SKU'], weight: 10.0) } + context 'when "Option1 Value" is "Default Title"' do + let(:result) { context.merge(variant: product.master) } - it 'updates the variant' do + before { data.merge! 'Option1 Value' => 'Default Title' } + + it 'updates master variant' do expect { described_method }.not_to(change { Spree::Variant.count }) expect(described_method).to eq(result) - expect(variant.reload.weight.to_f).to eq(data['Variant Weight']) + expect(product.master.weight).to eq 20.0 end end - context 'with an existing invalid variant' do - let!(:variant) do - create(:variant, sku: data['Variant SKU'], weight: 10.0).tap do |variant| - variant.update_column(:product_id, nil) - end + context 'when "Option1 Value" is blank' do + let(:result) { context.merge(variant: product.master) } + + before { data.merge! 'Option1 Value' => nil } + + it 'updates master variant' do + expect { described_method }.not_to(change { Spree::Variant.count }) + expect(described_method).to eq(result) + expect(product.master.weight).to eq 20.0 end + end + + context 'with an existing valid variant' do + let(:result) { context.merge(variant: variant) } + let!(:variant) { create(:variant, sku: data['Variant SKU'], weight: 10.0) } - it 'raises an exception' do - expect { described_method }.to raise_error(ActiveRecord::RecordInvalid, /Product must exist/) + before { data.merge! 'Option1 Value' => 'Some value' } + + it 'updates the variant' do + expect { described_method }.not_to(change { Spree::Variant.count }) + expect(described_method).to eq(result) + expect(variant.reload.weight.to_f).to eq(data['Variant Weight']) end end end