Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Allow plugins to register functions to handle GraphQL transformation of catalog product media items #4988

Merged
merged 3 commits into from
Feb 20, 2019

Conversation

dancastellon
Copy link
Contributor

@dancastellon dancastellon commented Feb 14, 2019

Resolves #4987
Impact: minor
Type: feature

Issue

Currently, all media is assumed to be hosted within Reaction's database. There is a core transformation function - xformProductMedia - that is called from within several GraphQL resolvers - Cart.items, OrderFulfillmentGroup.items, CatalogProduct.media, CatalogProduct.primaryImage, and CatalogProduct.variants. Because this function is hard-coded within the resolvers, it makes it difficult to override with a custom media transformation function, which is the case when media is hosted elsewhere (Cloudinary for example).

Solution

This PR replaces direct calls to xformProductMedia in GraphQL resolvers with getFunctionsOfType("xformCatalogProductMedia"). This allows any plugin to register a function that can transform a media object for a catalog product. It also renames xformProductMedia to xformFileCollectionsProductMedia, moves it to the core files plugin, and registers it via a new register.js file in that plugin.

Breaking changes

None

Testing

  1. Clone the latest SDI Cloudinary plugin (or PR) into /imports/plugins/custom
  2. Reset Reaction and run upload an image for the default product that is created on first startup.
  3. Confirm you see the image in the grid, PDP, cart, checkout, and order confirmation screens.
  4. Visit Reaction's dashboard and configure the Cloudinary plugin.
  5. Insert this product into the Catalog collection:
{
    "_id" : "kEcAvh3xxQvuRGuK9",
    "product" : {
        "_id" : "2051342",
        "createdAt" : ISODate("2019-01-24T10:39:13.192Z"),
        "description" : "...",
        "inventoryAvailableToSell" : 20,
        "inventoryInStock" : 20,
        "isBackorder" : false,
        "isDeleted" : false,
        "isLowQuantity" : false,
        "isSoldOut" : false,
        "isVisible" : true,
        "media" : [],
        "price" : {
            "range" : "0.00 - 0.00",
            "min" : 1,
            "max" : 1
        },
        "pricing" : {
            "USD" : {
                "compareAtPrice" : null,
                "displayPrice" : "$0.00",
                "maxPrice" : 1,
                "minPrice" : 1,
                "price" : null
            }
        },
        "primaryImage" : {
            "filename" : "2051342_001_main.jpg",
            "alt" : "NIKE Women's Tapered Double Dry Pants - BLACK/DESRTSAND-010",
            "title" : "NIKE Women's Tapered Double Dry Pants - BLACK/DESRTSAND-010",
            "productId" : "2051342",
            "type" : "hi-res",
            "priority" : 0,
            "toGrid" : 0,
            "variantId" : "2051342-BLACK/DESRTSAND-010"
        },
        "productId" : "2051342",
        "shopId" : "J8Bhq3uTtdgwZx3rz",
        "slug" : "nike-women-s-tapered-double-dry-pants",
        "supportedFulfillmentTypes" : [ 
            "shipping"
        ],
        "title" : "NIKE Women's Tapered Double Dry Pants",
        "type" : "product-simple",
        "tagIds" : [],
        "updatedAt" : ISODate("2019-02-11T21:39:07.560Z"),
        "variants" : [ 
            {
                "_id" : "2051342-BLACK/DESRTSAND-010",
                "canBackorder" : false,
                "createdAt" : ISODate("2019-01-24T10:39:13.192Z"),
                "index" : 0,
                "inventoryAvailableToSell" : 20,
                "inventoryInStock" : 20,
                "inventoryManagement" : false,
                "inventoryPolicy" : false,
                "isBackorder" : false,
                "isLowQuantity" : false,
                "isSoldOut" : false,
                "media" : [ 
                    {
                        "filename" : "2051342_001_main.jpg",
                        "alt" : "NIKE Women's Tapered Double Dry Pants - BLACK/DESRTSAND-010",
                        "title" : "NIKE Women's Tapered Double Dry Pants - BLACK/DESRTSAND-010",
                        "productId" : "2051342",
                        "type" : "hi-res",
                        "priority" : 0,
                        "toGrid" : 0,
                        "variantId" : "2051342-BLACK/DESRTSAND-010"
                    }, 
                    {
                        "filename" : "2051342_001_alt1.jpg",
                        "alt" : "NIKE Women's Tapered Double Dry Pants - BLACK/DESRTSAND-010",
                        "title" : "NIKE Women's Tapered Double Dry Pants - BLACK/DESRTSAND-010",
                        "productId" : "2051342",
                        "type" : "hi-res",
                        "priority" : 0,
                        "toGrid" : 0,
                        "variantId" : "2051342-BLACK/DESRTSAND-010"
                    }, 
                    {
                        "filename" : "2051342_001_sw_25x25.jpg",
                        "alt" : "BLACK/DESRTSAND-010",
                        "title" : "BLACK/DESRTSAND-010",
                        "productId" : "2051342",
                        "type" : "swatch",
                        "priority" : 0,
                        "toGrid" : 0,
                        "variantId" : "2051342-BLACK/DESRTSAND-010"
                    }
                ],
                "optionTitle" : "BLACK/DESRTSAND-010",
                "price" : 1,
                "pricing" : {
                    "USD" : {
                        "compareAtPrice" : null,
                        "displayPrice" : "$0.00",
                        "maxPrice" : 1,
                        "minPrice" : 1,
                        "price" : 1
                    }
                },
                "primaryImage" : null,
                "shopId" : "J8Bhq3uTtdgwZx3rz",
                "title" : "BLACK/DESRTSAND-010",
                "updatedAt" : ISODate("2019-01-24T10:39:13.192Z"),
                "variantId" : "2051342-BLACK/DESRTSAND-010",
                "options" : [ 
                    {
                        "_id" : "33135100016",
                        "canBackorder" : false,
                        "createdAt" : ISODate("2019-01-24T10:39:13.192Z"),
                        "index" : 0,
                        "inventoryAvailableToSell" : 20,
                        "inventoryInStock" : 20,
                        "inventoryManagement" : false,
                        "inventoryPolicy" : false,
                        "isBackorder" : false,
                        "isLowQuantity" : false,
                        "isSoldOut" : false,
                        "media" : [],
                        "optionTitle" : "M",
                        "price" : 1,
                        "pricing" : {
                            "USD" : {
                                "compareAtPrice" : null,
                                "displayPrice" : "$0.00",
                                "maxPrice" : 1,
                                "minPrice" : 1,
                                "price" : 1
                            }
                        },
                        "primaryImage" : null,
                        "shopId" : "J8Bhq3uTtdgwZx3rz",
                        "title" : "M",
                        "updatedAt" : ISODate("2019-01-24T10:39:13.192Z"),
                        "variantId" : "33135100016",
                        "isTaxable" : false
                    }, 
                    {
                        "_id" : "33135100018",
                        "canBackorder" : false,
                        "createdAt" : ISODate("2019-01-24T10:39:13.192Z"),
                        "index" : 0,
                        "inventoryAvailableToSell" : 20,
                        "inventoryInStock" : 20,
                        "inventoryManagement" : false,
                        "inventoryPolicy" : false,
                        "isBackorder" : false,
                        "isLowQuantity" : false,
                        "isSoldOut" : false,
                        "media" : [],
                        "optionTitle" : "XL",
                        "price" : 1,
                        "pricing" : {
                            "USD" : {
                                "compareAtPrice" : null,
                                "displayPrice" : "$0.00",
                                "maxPrice" : 1,
                                "minPrice" : 1,
                                "price" : 1
                            }
                        },
                        "primaryImage" : null,
                        "shopId" : "J8Bhq3uTtdgwZx3rz",
                        "title" : "XL",
                        "updatedAt" : ISODate("2019-01-24T10:39:13.192Z"),
                        "variantId" : "33135100018",
                        "isTaxable" : false
                    }, 
                    {
                        "_id" : "33135100017",
                        "canBackorder" : false,
                        "createdAt" : ISODate("2019-01-24T10:39:13.192Z"),
                        "index" : 0,
                        "inventoryAvailableToSell" : 20,
                        "inventoryInStock" : 20,
                        "inventoryManagement" : false,
                        "inventoryPolicy" : false,
                        "isBackorder" : false,
                        "isLowQuantity" : false,
                        "isSoldOut" : false,
                        "media" : [],
                        "optionTitle" : "L",
                        "price" : 1,
                        "pricing" : {
                            "USD" : {
                                "compareAtPrice" : null,
                                "displayPrice" : "$0.00",
                                "maxPrice" : 1,
                                "minPrice" : 1,
                                "price" : 1
                            }
                        },
                        "primaryImage" : null,
                        "shopId" : "J8Bhq3uTtdgwZx3rz",
                        "title" : "L",
                        "updatedAt" : ISODate("2019-01-24T10:39:13.192Z"),
                        "variantId" : "33135100017",
                        "isTaxable" : false
                    }, 
                    {
                        "_id" : "33135100015",
                        "canBackorder" : false,
                        "createdAt" : ISODate("2019-01-24T10:39:13.192Z"),
                        "index" : 0,
                        "inventoryAvailableToSell" : 20,
                        "inventoryInStock" : 20,
                        "inventoryManagement" : false,
                        "inventoryPolicy" : false,
                        "isBackorder" : false,
                        "isLowQuantity" : false,
                        "isSoldOut" : false,
                        "media" : [],
                        "optionTitle" : "S",
                        "price" : 1,
                        "pricing" : {
                            "USD" : {
                                "compareAtPrice" : null,
                                "displayPrice" : "$0.00",
                                "maxPrice" : 1,
                                "minPrice" : 1,
                                "price" : 1
                            }
                        },
                        "primaryImage" : null,
                        "shopId" : "J8Bhq3uTtdgwZx3rz",
                        "title" : "S",
                        "updatedAt" : ISODate("2019-01-24T10:39:13.192Z"),
                        "variantId" : "33135100015",
                        "isTaxable" : false
                    }
                ],
                "isTaxable" : false
            }
        ],
        "vendor" : "NIKE"
    },
    "shopId" : "J8Bhq3uTtdgwZx3rz",
    "createdAt" : ISODate("2019-01-23T05:51:07.140Z"),
    "updatedAt" : ISODate("2019-02-11T21:40:50.163Z")
}
  1. Visit storefront and confirm you see the Cloudinary image in the grid, PDP, cart, checkout, and order confirmation screens.

@dancastellon dancastellon force-pushed the feat-4987-dancastellon-plugins-transform-media branch from 1062817 to d9b6327 Compare February 14, 2019 22:17
@dancastellon dancastellon changed the title [WIP] Feat: Allow plugins to register functions to handle GraphQL transformation of catalog product media items Feat: Allow plugins to register functions to handle GraphQL transformation of catalog product media items Feb 14, 2019
Signed-off-by: Daniel Castellon <[email protected]>
@dancastellon dancastellon force-pushed the feat-4987-dancastellon-plugins-transform-media branch from b48ef61 to af6e281 Compare February 14, 2019 22:49
Copy link
Collaborator

@brent-hoover brent-hoover left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will want to get a doc PR in for this too

@dancastellon dancastellon merged commit 923a69c into develop Feb 20, 2019
@jeffcorpuz jeffcorpuz mentioned this pull request Mar 1, 2019
@machikoyasuda machikoyasuda deleted the feat-4987-dancastellon-plugins-transform-media branch March 19, 2019 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants