Merx – Plugin to create online shops with Kirby 3

, ,

Thanks for your reply!

I am submitting the request by clicking the button. And this is what is written in the browser URL field. But I was expecting sth further like ?order=shoe23

I intended to pass the order-key through this process. But I am totally open to any other suggestions. How would you pass variables by URL? :clap:t3:

You forgot to echo the id, should be

<?= $item['id'] ?>

Unfortunately this doesn’t change the error behaviour :confused: It is referring to a 404 page not found

What if you remove the print_r command? And is $item['id'] defined?

Yes it is defined… Removing the print_r command didnt solve the problem, too :confused:

What if you call the correct URL in a REST tool like Insomnia/Rested/Postman?

hey @nurcihandem,

delete is not a valid value of the method attribute. (see. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-method).

You can do something like this.

Untested code ahead

<form class="form-checkout" method="post" action="<?= url('/shop-api/remove-from-cart')?>">
  <input type="hidden" name="id" value="<? $item['id'] ?>">
  <button type="submit" class="button">
    Entfernen
  </button>
</form>
[
'method' => 'post',
'pattern' => 'shop-api/remove-from-cart',
'action' => function() {
 try {
     $itemId = $_POST['id'];
     merx()->cart()->remove($itemId);
     return page('checkout');
 } catch(Kirby\Exception\Exception $ex) {
     return $ex->toArray();
 }
}
],

3 Likes

This is working! Big thanks to you both @pixelijn and @tobiasfabian :clap:t3:

1 Like

Hi! There is something about taxes that I don’t understand how it works.
Products can have a Tax percentage but the getSum() method returs the sum without computing the tax. I checked the two demos and in both cases the tax is calculated but is not added to the sum that the customer have to pay.

So my question is: how the tax can be added to the sum?

My final goal is to have a better idea on how to create something like you mentioned here Merx – Plugin to create online shops with Kirby 3 for the Merx site.
Could you please share that piece of code?

Thanks in advance! Best.

Hey @efavaro,

$cart->getSum() should include tax. You can use $cart-getTax() to get the summed up taxes of your cart.

Please be aware that the price of a product is the price including tax.

You can take take a look to the source code of merx.wagnerwagner.de on GitHub.

Hope that helps. Feel free to write again if you have further questions.

1 Like

Hello @tobiasfabian

I’m hoping to use your plugin. I’ve managed to get it working apart from the final completion of payment through PayPal. In my checkout.php controller, I have the following.

<?PHP
     if (merx()->cart()->isEmpty()) {
      go('/');
     }
     if (kirby()->request()->method() === 'POST') {
      try {
      $data = $_POST;
      $redirect = merx()->initializePayment($data);
      go($redirect);
     } catch (Exception $ex) {
      echo $ex->getMessage();
      dump($ex->getDetails());
     }
    }

and my config is:

    <?php

    use Kirby\Exception\Exception;

    return [
      'debug' => true,
      'ww.merx.production' => false,
      'ww.merx.currency' => 'GBP',
      'ww.merx.currencySymbol' => '£',
      'ww.merx.gateways' => [
        'paypal' => [
          'ww.merx.paypal.sandbox.clientID' => '',
          'ww.merx.paypal.sandbox.secret' => ''
        ],
        'credit-card' => [
          'ww.merx.stripe.live.publishable_key' => 'pk_test_',
          'ww.merx.stripe.live.publishable_key' => 'sk_test_'
        ]
      ],
      'routes' => [
        [
          'pattern' => 'add',
          'method' => 'post|get',
          'action'  => function () {
            $id = get('id');
            $quantity = get('quantity');
            try {
              cart()->add([
                'id' => $id,
                'quantity' => $quantity,
              ]);
              go('/');
            } catch (Exception $ex) {
              return $ex->getMessage();
            }
          },
        ],
        [
          'pattern' => 'remove',
          'method' => 'post|get',
          'action'  => function () {
            $id = get('id');
            try {
              cart()->remove($id);
              go('/checkout');
            } catch (Exception $ex) {
              return $ex->getMessage();
            }
          },
        ],
      ],
      'hooks' => [
        'ww.merx.cart' => function ($cart) {
          if ($cart->count() > 0) {
            $cart->remove('shipping');
            if ($cart->getSum() < 2) {
              $cart->add([
                'id' => 'shipping',
              ]);
            }
          }
        }
      ],
    ];

I expected the go($redirect); to send to PayPal but instead, it loads the order.php of the order. Is there something / a setup step I’m missing?

Open question to all!

Hey @randomobject,

Thanks for giving Merx a chance.

Your checkout.php controller looks good from here.

Your ww.merx.gateways config option is not correct. The gateway option is meant for custom gateways.

PayPal and Credit Card are default Payment Methods / default gateways.

The PayPal/Stripe keys are meant to be set like this:

// config.php
<?php
return [
  'debug' => true,
  'ww.merx.production' => false,
   // … other options
  'ww.merx.paypal.sandbox.clientID' => '',
  'ww.merx.paypal.sandbox.secret' => '',
  'ww.merx.stripe.test.publishable_key' => 'pk_test_',
  'ww.merx.stripe.test.publishable_key' => 'sk_test_'
];

Cheers Tobias.

1 Like

Hi @tobiasfabian

Thanks for this, it’s working perfectly. Apologies for apparently not reading the docs right! :+1:t3:

On another note, do you offer a discount if I buy 2 (poss more) licenses?

Ta, Victor

1 Like

If you want to buy many licenses you can get in contact via mail (merx@wagnerwagner.de).

Thank you! I’m glad to see that the Merx website is open source.

1 Like

Hey, does anybody have an idea about how to set the custom public and private api keys of Stripe and Paypal into the application? Can’t imagine where they should be referred.

Thanks in advance!
Nurcihan

Hello,

I am creating a jewelery shop with Kirby and Merx. The products have many variations, and the buyer should be able to add variations of the same product to the cart. Currently, I am using a single content file for the product’s content and variations.

Is there any way to be able to add products with the same id to the cart, or do I have to create subpages for every variation combination?

Hey @nurcihandem,

you have to add the keys to your site/config/config.php.

1 Like

Hey @alexpi,
I’ve suggested a possible solution on GitHub

@tobiasfabian Great, thanks!