Code Monkey home page Code Monkey logo

woographql-composite-products's Introduction

This is a Next.js project bootstrapped with create-next-app.

Getting Started

First, run the development server:

npm run dev
# or
yarn dev
# or
pnpm dev

Open http://localhost:3000 with your browser to see the result.

You can start editing the page by modifying app/page.js. The page auto-updates as you edit the file.

This project uses next/font to automatically optimize and load Inter, a custom Google Font.

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.

woographql-composite-products's People

Contributors

sorensenjg avatar

Stargazers

 avatar

Watchers

 avatar

woographql-composite-products's Issues

Wish: Support for conditions

Hi @sorensenjg

First I would like to thank you for your work on this package.
As the thread says, I wanted to ask wether it is possible to add support for the conditions set on the WP dashboard?

Regards

Akram

Query Cross-Sell Products

@sorensenjg Is there a way to query cross-sell products for composite products? I am trying to query both up-sell and cross-sell products but only found up-sell.

Composite Product not returning when resolved by URI

Problem

When querying a product by uri using the nodeByUri query, if the product is a "composite" product, there is an error returned:

Abstract type UniformResourceIdentifiable must resolve to an Object type at runtime for field RootQuery.nodeByUri with value "instance of WPGraphQL\WooCommerce\Model\Product", received "Product". Either the UniformResourceIdentifiable type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.

For example, I have a composite product with the uri: /product/battery-operated-rs/

If I run the following query:

{
  nodeByUri(uri: "/product/battery-operated-rs/") {
    uri
  }
}

I get the following response:

{
  "errors": [
    {
      "debugMessage": "Abstract type UniformResourceIdentifiable must resolve to an Object type at runtime for field RootQuery.nodeByUri with value \"instance of WPGraphQL\\WooCommerce\\Model\\Product\", received \"Product\". Either the UniformResourceIdentifiable type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.",
      "message": "Internal server error",
      "extensions": {
        "category": "internal"
      },
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "nodeByUri"
      ],
      ...

Resolution

I was able (with the help of @kidunot89) to resolve this with the following filter:

add_filter( 'graphql_interface_resolve_type', function( $type, $node, $interface ) {
  switch( true ) {
    case is_a( $node, '\WPGraphQL\WooCommerce\Model\Product' ) && 'composite' === $node->type:
      $type = 'CompositeProduct';
      break;
  }
  return $type;	
}, 10, 3 );

And with this filter in place, I can successfully query a composite product and get it back as expected:

CleanShot 2022-05-11 at 15 49 46


I believe this filter should live within this plugin as this plugin is the bridge between WooGraphQL and Composite products


related: jacobarriola/woographql-product-bundles#5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.