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

Add Carts #979

Closed
wants to merge 14 commits into from
Closed

Add Carts #979

wants to merge 14 commits into from

Conversation

scottdixon
Copy link
Contributor

In preparation for Checkout API deprecation, this PR adds Carts.

This is my first contribution to the library, please let me know what can be improved :)

Creating a Cart

const input = {
  lines: {
    merchandiseId: 'gid://shopify/ProductVariant/13666012889144',
    quantity: 5,
    attributes: [{key: "MyKey", value: "MyValue"}]
  },
  note: 'This is a cart note!'
];

// Create a cart
client.cart.create(input).then((cart) => {
  // Do something with the cart
});

Fetching a Cart

const cartId = 'gid://shopify/Cart/Z2NwLWV1cm9wZS13ZXN0NDowMUhOTTI0QVZYV1NOSEVNOUVCQ1JSNUhSVg'

client.cart.fetch(cartId).then((cart) => {
  // Do something with the cart
});

Updating Cart Attributes

const cartId = 'gid://shopify/Cart/Z2NwLXVzLWVhc3QxOjAxSE5WWTAyVjlETjFDNVowVFZEWVMwMVJR';
const attributes = [{key: "MyKey", value: "MyValue"}];

client.cart.updateAttributes(cartId, attributes).then((cart) => {
  // Do something with the updated cart
});

Updating Buyer Identity

const cartId = 'gid://shopify/Cart/Z2NwLXVzLWVhc3QxOjAxSE5WWTAyVjlETjFDNVowVFZEWVMwMVJR';
const buyerIdentity = {email: "hello@hi.com"};

client.cart.updateBuyerIdentity(cartId, buyerIdentity).then((cart) => {
  // Do something with the updated cart
});

Updating Discount Codes

const cartId = 'gid://shopify/Cart/Z2NwLXVzLWVhc3QxOjAxSE5WWTAyVjlETjFDNVowVFZEWVMwMVJR';
const discountCodes = [{code: "MyCode"}];

client.cart.updateDiscountCodes(cartId, discountCodes).then((cart) => {
  // Do something with the updated cart
});

Adding Cart Line Items

const cartId = 'gid://shopify/Cart/Z2NwLXVzLWVhc3QxOjAxSE5WWTAyVjlETjFDNVowVFZEWVMwMVJR';
const lines = [{merchandiseId: 'gid://shopify/Product/123456', quantity: 5}];

client.cart.addLineItems(cartId, lines).then((cart) => {
  // Do something with the updated cart
});

Removing Cart Line Items

const cartId = 'gid://shopify/Cart/Z2NwLXVzLWVhc3QxOjAxSE5WWTAyVjlETjFDNVowVFZEWVMwMVJR';
const lineIdsToRemove = ['gid://shopify/CartLineItem/123456'];

client.cart.addLineItems(cartId, lineIdsToRemove).then((cart) => {
  // Do something with the updated cart
});

Updating Cart Line Items

const cartId = 'gid://shopify/Cart/Z2NwLXVzLWVhc3QxOjAxSE5WWTAyVjlETjFDNVowVFZEWVMwMVJR';
const lines = [{id: 'gid://shopify/CartLineItem/123456', quantity: 5}];

client.cart.updateLineItems(cartId, lines).then((cart) => {
  // Do something with the updated cart
});

Updating Cart Notes

const cartId = 'gid://shopify/Cart/Z2NwLXVzLWVhc3QxOjAxSE5WWTAyVjlETjFDNVowVFZEWVMwMVJR';
const note = 'A note for the cart';

client.cart.updateNote(cartId, note).then((cart) => {
  // Do something with the updated cart
}

@benjaminsehl
Copy link
Member

Closing this for now pending further discussion.

@tonyyb
Copy link

tonyyb commented Jun 24, 2024

Hi,

This PR was closed without more details but can you tell us if an implementation is scheduled in this library please ?

Thank you !

@aoliverio-ev
Copy link

Hey @benjaminsehl are there any updates as to if/when this work will be resumed? TY

@AllanPooley
Copy link

Hey @scottdixon thank you for your work on this 🙏 @benjaminsehl has there since been an update?

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.

5 participants