Jump to content

Mini-minimal setup


Recommended Posts

Hi there,

I think what would help is a very minimal setup, a demo without ajax/htmx, templating etc. In the absence of that, here is a super basic question:

1. How do I add and remove a product to the cart purely via the API? This is for me to understand the basics. I'm imagining it would be something like

$cart = $padloper->getCart();

if(!$cart->addProduct(product_id)) {
  echo 'problems adding';

if(!$cart->removeProduct(product_id)) {
  echo 'problems removing';

tx J

  • Like 1
Link to comment
Share on other sites

1 minute ago, joe_g said:

Thanks, I'm mostly looking for a way to remove a product from the cart, I can't seem to find thatin the link you attached


Yes, that link is only about adding.

27 minutes ago, joe_g said:

The argument you pass here should be the ID of the cart item, not the product ID, i.e.,


namespace ProcessWire;
// ==================
/** @var array $cartItems */
$cartItems = $padloper->getCart();
bd($cartItems, __METHOD__ . ': $cartItems at line #' . __LINE__);
foreach ($cartItems as $cartID => $cartItem) {
  /** @var stdClass $cartItem */
  echo "The ID of the cart item is: {$cartID}<br>";
  // OR
  // echo "The ID of the cart item is: {$cart->id}<br>";
  // OR
  // $padloper->cart->removeProduct($cartID);


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...