Merx – Plugin to create online shops with Kirby 3

, ,

Hi @plagasul,

thanks for your questions.

  1. As soon as you add something to the cart a cookie is set with durationNormal (two hours), see Kirby Reference options/session.
    When you use Stripe additional cookies are set by Stripe’s JavaScript.

  2. Orders are stored as order.txt pages within content/orders (or another folder, depending on your Merx configuration)

1 Like

Thank you for your answers,

So Orders ARE stored by MERX by default, then. Ok.

I have another question, bitte:

Do we actually need to provide MERX with both the Stripe/Paypal api key AND the secret ?

Thank you

No, you don’t need to set up any of the API Keys unless you want to use Stripe or PayPal. If you only want to use PayPal, you only need to provide the PayPal keys. Furthermore you don’t need the live keys as long as you are testing. The sandbox/live keys are toggled by the ww.merx.production option.

Yes, Thank you.

I meant if the secret key was also needed, but I got ahead of myself as I see this may be highly dependant on how do I set it up on Stripe’s side.

Thanks again

Same for me.
Just added exactly what the plainkit contains but don’t know why after clicking to “add product”, the page goes to /add and return the error page.
Tried to get more details with $ex->toArray() but didn’t get anymore.
I’m running with 3.3.5 and two languages, I have removed every plugins but it doesn’t come from here.
This is my code, the same as @jamiehunter

'routes' => [
    [
      'pattern' => 'add',
      'method' => 'post',
      'action'  => function () {
        $id = get('id');
        $quantity = get('quantity');
        try {
          cart()->add([
            'id' => $id,
            'quantity' => $quantity,
          ]);
          go('/');
        } catch (Exception $ex) {
          return $ex->getMessage();
        }
      },
    ],
  ],

Hey @Oziris,

two languages is a good hint. The html form’s action is add (See site/templates/home.php:3). Which is a bit sloppy. The action attribute should be <?= url('add') ?> to make sure it always points to domain.tld/add and the add route is triggered. I updated the Plainkit with this patch.

@jamiehunter does this help for your problem?

Changing add to <?= url('add') ?> into the form doesn’t change. It’s like the route is not triggered as expected, it’s always redirected to the “add” page.
:thinking:

Could you post the what you see in the network tab?

what if you add the language property:

'pattern' => 'add',
'language' => '*',
'method' => 'post',
'action'  => function () {

to the route?

I’ve set 'language' => '*', same redirect to the add page… This is my network screen capture :

Are you running the Kirby installation in a subdirectory (CREDAC2)?

  1. You can try to uncomment/modify # RewriteBase / in your .htaccess.
  2. Try to add get to your route and see what your request returns. It should be Item “” could not be added to cart.:
'pattern' => 'add',
'method' => 'post|get',
'action'  => function () {

Yes, I’m running into a subfolder. Uncommenting didn’t work. When I change to add into my route, the page is still getting into the /add page as an error, without any request returned.
It’s reacting as if the route didn’t want to be listened.

If you want to check my settings, I’ve set all my config into this link

EDIT : I had an other route for sitemap into my config file. This is the lines :

'routes' => [
  [
    'pattern' => 'sitemap.xml',
    'action'  => function() {
        $pages = site()->pages()->index();
        $ignore = kirby()->option('sitemap.ignore', ['error']);
        $content = snippet('sitemap', ['pages' => $pages, 'ignore' => $ignore, 'kirby' => kirby()], true);
        return new Kirby\Cms\Response($content, 'application/xml');
    }
  ],
  [
    'pattern' => 'sitemap',
    'action'  => function() {
      return go('sitemap.xml', 301);
    }
  ]
],

I removed these lines and I could get the *Item “” could not be added to cart.* message.

So sorry for my mistake about the route writting, I’m trying to fix that bug. I’m getting the error Item “” could not be added to cart.
I’ve set return $ex->toArray(); to show me what’s going wrong. I get this :

|exception|"Kirby\\Exception\\Exception"|
|---|---|
|message|"L’article \"editions/edition1\" n’a pas pu être ajouté au panier."|
|key|"error.merx.cart.add"|
|file|"CREDAC2/site/plugins/merx/src/cart.php"|
|line|49|
|details||
|exception|{}|
|code|500|

So this is pointing to the line 49 of the cart.php file on

throw new Exception([
                'key' => 'merx.cart.add',
                'data' => [
                    'id' => $cartItem['id'] ?? '',
                ],
                'details' => [
                    'exception' => $ex,
                ],
            ]);

I’ve checked my form, the input is setting the ID well like

<input type="hidden" name="id" value="editions/edition1">

Don’t really know where could it come from…

Hey @Oziris,

I’ve looked at your code and discovered two things.

  1. You have two routes keys in your config.php (the second at line 64). So the first routes (with the add route) are ignored.
  2. The page you want to add to the cart (editions/edition1) has to be a product page (product.fr.txt instead of edition.fr.txt)

Not sure if that is the right place in here, but does anybody already added mollie as Custom Payment gateway in merx?

2 Likes

Thank you very much for taking the time to look at the code. The second route was indeed a mistake on my part.
But I didn’t know we have to strictly named the file product as product.txt to make it work. This seems to be the right solution.

I am now faced with another problem, when I click on “add to cart”, I have an error message saying

A non well formed numeric value encountered

pointing on the line 28 inside : /site/plugins/merx/index.php

function formatPrice(float $price, bool $currencyPositionPrecedes = null, bool $currencySeperateBySpace = null): string

Weird, because this is my blueprint inside product.txt and the price and tax are here :

Price: 3

----

Tax: 7

----

Great job on merx @tobiasfabian. I’ve been playing around with it (through babyreport.de) to get a feel for it.

One thing I was looking at was product variants and stock control (I’ve seen the cookbooks for each). Having product child variants also use product.txt is a little limiting. It would be nice to use variant.txt for product children, is that a bunch of work? Alternatively within a product it would be nice to use a variants structure field with variant title and stock fields to handle this. Would make it a lot easier to manage. Is it possible to update the stock value within a structure field on the product page?

On another note with the mjml for the emails, is it possible to export php (I’m using the vscode plugin)? Whenever I do this I have to add the use merx php line to the top of each template.

I could identify the <?= formatPrice($item['sumTax']) ?> call, inside the cart snippet, is getting the error from formatPrice function although my taxes field are set inside my product.txt files.
Still investigating on this but don’t know where could it come from.

Is it a multi language site? What’s you locale setting? You can try the latest beta release, maybe this solves your problem.

Hey @smongey,

I looked at the code and with the latest commit removed the check for the product template since it’s no longer needed. As long as your page has a price field you now can add everything to your cart.

@Oziris this might be interesting for you as well. You can rename your product.txt pages to edition.txt :wink:

A variants structure field would also be possible. You can update the stock and set the new structure data by $structure->data(). I would prefer variant.txt pages since updating and saving structure fields feels a bit difficult to me.

mjml: I also used the VSCode plugin and then manually inserted the $page variables. For the shop I’m currently building I go for very simple html emails. Just paragraphs, links and maybe bold/italic text – no table layouts.

1 Like

Thanks a lot, your last release have solved my issue ! :+1:
I actually have several languages in my settings, Are there any prerequisites for this?

1 Like