Merx Starterkit / E-commerce (cart problem)

I’m trying to get Merx Starterkit to work.
You need PHP8 minimum, on PHP7… it didn’t work.

I seem to still get an error, my cart doesn’t fill up…
Anyone know how I might solve this?

I follow the installation and didn’t touch the code (except for the HTTPS in .htaccess)

Have you tried to set the RewriteBase to your root (/merx-starterkit) – Line 22 in .htaccess.

Hello all,

I am getting exactly the same error message as the topic creator. My Kirby installation is in a subfolder. The .htaccess file is created correctly, incl. RewriteBase.
Has anyone found a solution to this problem?

Thanks a lot!

I had a similar issue on my local environment. For me, writing the whole fetch path in the js file worked.
So instead of fetch('/api/shop/{...}') I used fetch('http://localhost:8888/api/shop/{...}').

2 Likes

Thanks for the quick reply.

After the suggested change, at least the text “The cart is empty.” now appears.

However, when adding a product I get the error: “Call to a member function exists() on float”.

Can you see where in the code the error is thrown?

Console is showing this error:

POST https://domain.de/2022/api/shop/cart 500
request @ cart.js:75
add @ cart.js:207
(anonymous) @ product.js:9```

“Call to a member function exists() on float” gets shown by the Kirby debug screen right? Do you see, in which file the exists() function is that causes the error?

The error message “Call to a member function exists() on float” appears as a pop-up when you press the add-to-cart button. Unfortunately, a concrete file is not displayed.

I think this probably appears when the existence of the tax field in the product is checked. Did you change the product page model in any way?
Also you could try commenting out

public function tax(): float
    {
        if ($this->content()->tax()->isEmpty()) {
            return 0;
        }
        return $this->kirby()->option('taxRates')[$this->content()->tax()->toString()];
    }

or changing it so that tax() doesn’t return a float in the product.php model. Maybe this causes the problem.

Great, thank you very much! Once you comment out the tax function, it works.

I would like to keep the tax function though. Where exactly could be the error here?

I have not changed the product model.

The problem is, that the Merx core at ProductList.php checks if the tax field exists, whereas the tax function in the model the tax function returns a float.

I think changing it to something like this could work:

public function tax(): Field
    {
        if ($this->content()->tax()->isEmpty()) {
            return new Field($this, 'tax', 0);
        }
        return new Field($this, 'tax', $this->kirby()->option('taxRates')[$this->content()->tax()->toString()]);
    }

I am getting:

Argument 2 passed to Kirby\Cms\App::trigger() must be of the type array, object given, called in /Users/TE-NT/Sites/localhost/merx-starterkit/site/plugins/merx/src/cart.php on line 22

as a pop up when i refresh or click add-to-cart button

Hello,

I have the same problem as @Jarneuyt, the cart is not showing. Did you find a solution ?

thanks in advance

The cart works again by modifying the url of the file assets/js/cart.js

return fetch(`/api/shop/${endpoint}`,

remove the / from the path or indicate the full url.

api/shop/${endpoint} or http://mywebsite.com/api/shop/${endpoint}

the checkout page does not work after clicking on the “buy” button.

here is the error:
JSON.parse: unexpected character at line 1 column 1 of the JSON data

Hey there, I have the same problem as the original post. The cart pops up but is empty after I click on Add to cart. It’s the same for localhost (MAMP) and on my webserver. Any ideas how to solve it?

Thanks a lot!

1 Like