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

Catalog schema changes #4218

Merged
merged 150 commits into from May 17, 2018

Conversation

Projects
None yet
4 participants
@aldeed
Copy link
Member

commented Apr 26, 2018

Resolves #4196
Impact: breaking
Type: feature

Issue

The Catalog collection uses one schema while our GraphQL Catalog type uses a newer, better schema.

Solution

Update the Catalog collection schema and all code that writes to and reads from that collection.

Breaking changes

Method argument change

"products/updateProductPosition" method now takes a tag ID rather than tag name as its third argument

Media change

The media property on catalog items is still an array of objects, but the structure of those objects has changed.

BEFORE:

{
  metadata: {}, // the full metadata object from the Media doc
  thumbnail: "", // a URL
  small: "", // a URL
  medium: "", // a URL
  large: "", // a URL
  image: "", // a URL
}

AFTER:

{
  priority, // copied from metadata
  toGrid, // copied from metadata
  productId, // copied from metadata
  variantId, // copied from metadata
  URLs: {
    thumbnail: "", // a URL
    small: "", // a URL
    medium: "", // a URL
    large: "", // a URL
    original: "", // a URL
  }
}

Also, the media array is now sorted in ascending priority order.

Deleted and hidden variants change

When published to the catalog, the variants array on the catalog item now includes only those variants where isDeleted IS NOT true and isVisible IS true.

Product props separated from catalog item props

Most product properties that were formerly on the catalog item itself are now moved to a product object property.

Explicit property copying

Previously all product and variant props were blindly copied into the catalog item. Now, we explicitly copy only the props we want, sometimes changing their names.

Property name changes

  • variant.taxable -> variant.isTaxable
  • variant.variantId added, currently the same as variant._id but might not always be. A reference back to the variant in the Products collection.
  • product.taxable -> product.isTaxable
  • product.productId added, currently the same as product._id but might not always be. A reference back to the product in the Products collection.
  • product.handle -> product.slug
  • product.hashtags -> product.tagIds

product.twitterMsg and product.facebookMsg and product.googleplusMsg and product.pinterestMsg are converted to a product.socialMetadata array like this:

socialMetadata: [
  { service: "twitter", message: product.twitterMsg },
  { service: "facebook", message: product.facebookMsg },
  { service: "googleplus", message: product.googleplusMsg },
  { service: "pinterest", message: product.pinterestMsg }
]

New Pricing Object

We've deprecated the price property on catalog products, variants, and options. There is a new property called pricing, which is a map keyed by currency code in MongoDB, and in GraphQL is converted to an array.

The GraphQL schema:

"The product price or price range for a specific currency"
type ProductPricingInfo {
  """
  A comparison price value, usually MSRP. If `price` is null, this will also be null. That is,
  only purchasable variants will have a `compareAtPrice`.
  """
  compareAtPrice: Float

  "The code for the currency these pricing details applies to"
  currency: Currency!

  """
  UI should display this price. If a product has multiple potential prices depending on selected
  variants and options, then this is a price range string such as "$3.95 - $6.99". It includes the currency
  symbols.
  """
  displayPrice: String!

  "The price of the most expensive possible variant+option combination"
  maxPrice: Float!

  "The price of the least expensive possible variant+option combination"
  minPrice: Float!

  """
  For variants with no options and for options, this will always be set to a price. For variants
  with options and products, this will be `null`. There must be a price for a variant to be
  added to a cart or purchased. Otherwise you would instead add one of its child options to a cart.
  """
  price: Float
}

These are currently mapped as follows, but in the future you will be able to have different prices per currency that your shop supports.

pricing: {
      [shopCurrencyCode]: {
        compareAtPrice: variant.compareAtPrice || null,
        displayPrice: variantPriceInfo.range,
        maxPrice: variantPriceInfo.max,
        minPrice: variantPriceInfo.min,
        price: typeof variant.price === "number" ? variant.price : null
      }
    },

Catalog Item props

All product props other than positions are now on the product object, so there are a few new properties on the catalog item itself:

  • _id (this is no longer the same as the product ID)
  • shopId (stays here AND on product obj)
  • createdAt
  • updatedAt

ReactionProduct.getTag

The ReactionProduct.getTag helper function is renamed to ReactionProduct.getTagIdForPosition and returns the tag ID rather than name. If there's no tag in the route path, it returns "_default" rather than the lowercased shop name.

Testing

  1. Make sure publishing a product still works correctly.
  2. Make sure the product grid still displays correctly, both as admin and as anonymous customer.
  3. Test these things both with and without the revisions feature enabled.

aldeed and others added some commits Apr 23, 2018

refactor: started moving the ProductRevision object out of the server…
… hooks and into it's own dir/file, started demeteorizing ProductRevision object and methods
refactor: created two test for the isSoldOut function, updated isSold…
…Out to return the correct value if variant has nothing in the inventory
refactor: cleaning up the publishProductToCatalog function, fleshed o…
…ut the function's test and added a few more test cases
refacotr: publishProductToCatalogById function clean up added await t…
…o the db.findOne calls, created better test for the function and mocked out a few of it's dep functions

nnnnat and others added some commits May 9, 2018

test: updated publishProductToCatalog integration test to have correc…
…t Product mocks, and to test deep level product updates and deleting
chore: cleaned up isSoldOut logic to be similar to the other inventor…
…y status util functions, added another test to publishProductInventoryAdjustments to test for not found Catalog Items
refactor: created a new catalog util function getProductQuantity to r…
…emove the need for the revisions util function getVariantsQuantity, created test for new until functions
refactor: moved getPriceRange util function out of the revisions plug…
…in and into the catalog plugin, updated where it's being imported
fix: updated isLowQuantity util funcitons to check the options quanti…
…ty against the top level variants warningThreshold if any options come back as below the threshold make the CatalogProduct as low quantity

@aldeed aldeed changed the title [WIP] Catalog schema changes Catalog schema changes May 16, 2018

@jshimko jshimko referenced this pull request May 16, 2018

Merged

fetch data for PDP #75

@aldeed aldeed merged commit 7e3ad6e into release-1.12.0 May 17, 2018

9 of 10 checks passed

ci/circleci: snyk-security Your tests failed on CircleCI
Details
WIP ready for review
Details
ci/circleci: build Your tests passed on CircleCI!
Details
ci/circleci: docker-build Your tests passed on CircleCI!
Details
ci/circleci: docker-push Your tests passed on CircleCI!
Details
ci/circleci: dockerfile-lint Your tests passed on CircleCI!
Details
ci/circleci: eslint Your tests passed on CircleCI!
Details
ci/circleci: test-app Your tests passed on CircleCI!
Details
ci/circleci: test-unit Your tests passed on CircleCI!
Details
security/snyk No new issues
Details

@aldeed aldeed deleted the refactor-4196-aldeed-catalog-schema-changes branch May 17, 2018

@pmn4

This comment has been minimized.

@aldeed out of curiosity, why are we going away from the Reaction method (Reaction.getShopCurrency())?

This comment has been minimized.

Copy link
Member Author

replied May 23, 2018

It seems like that is only on the server?

@aldeed aldeed referenced this pull request May 24, 2018

Merged

Catalog schema migration #4272

@spencern spencern referenced this pull request May 31, 2018

Merged

Release 1.12.0 #4287

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.