wagnerwagner / merx

Merx is a plugin to create online shops with Kirby.
https://merx.wagnerwagner.de
102 stars 10 forks source link

'Item "{id}" could not be added to cart.' #33

Closed plagasul closed 3 years ago

plagasul commented 3 years ago

Hello,

I am getting the exception 'Item "{id}" could not be added to cart.' when trying to add certain products to the cart.

Contrary to regular products, which I can add without problems, these products sit in a subpage

content
  product A
  product B
  ...
  frame-options
    frame-product A
    frame-product B

These frame-products also have a different blueprint from regular products,frame-product.yml which goes like this:

title: Frame Product
icon: box

options:
  changeTitle: true
  changeStatus: true
  changeTemplate: false
  changeSlug: true
  delete: true

fields:
  price:
    label: Price
    type: number
    step: ,01
    width: 1/4
    placeholder: 0,00
    after: €
  width:
    label: Width
    type: number
    width: 1/4
    placeholder: 21
    after: cm
  height:
    label: Height
    type: number
    width: 1/4
    placeholder: 30
    after: cm
  passepartout:
    label: Passepartout?
    type: toggle
    text:
      - 'no'
      - 'yes'
    width: 1/4
    default: 'no'

This is an example .txt file of such product:

Title: Wood, white

----

Price: 20

----

Width: 21

----

Height: 30

----

Passepartout: true

The code that triggers the exception is simply:

cart()->add([
  'id' => 'wood-white'
]);

Which works fine by susbstituting the id by that of a regular product, such as 'cactus'.

As I am not getting 'No "id" is provided.' , 'Page not found.' or 'Page must have a price field.' I assume those are not the issues here (shouldn't be nevertheless).

So ¿what could be the issue?

Danke

tobiasfabian commented 3 years ago

Hey @plagasul,

the exception is thrown here.
https://github.com/wagnerwagner/merx/blob/43e9b8ddf195b1a6f540319dd49cda1de074a1b7/src/cart.php#L51-L57

Can you try to get the details.exception (Line 56 of cart.php) object of the Exception.

plagasul commented 3 years ago

I enclosed the add code in a try catch block, and dumped the exception object, is this what you meant ?

Does it seem to say Page not found is the issue ?

For products in subfolders should we pass the id with full path including the parent, like frame-options/white-frame or similar ?

Thanks

Kirby\Exception\Exception Object
(
    [data:protected] => Array
        (
            [id] => wood-white
        )

    [httpCode:protected] => 500
    [details:protected] => Array
        (
            [exception] => Exception Object
                (
                    [message:protected] => Page not found.
                    [string:Exception:private] => 
                    [code:protected] => 0
                    [file:protected] => /home/myuser/public_html/dev/dietz/site/plugins/merx/src/cart.php
                    [line:protected] => 41
                    [trace:Exception:private] => Array
                        (
                            [0] => Array
                                (
                                    [file] => /home/myuser/public_html/dev/dietz/site/templates/home.php
                                    [line] => 22
                                    [function] => add
                                    [class] => Wagnerwagner\Merx\Cart
                                    [type] => ->
                                )

                            [1] => Array
                                (
                                    [file] => /home/myuser/public_html/dev/dietz/kirby/src/Toolkit/Tpl.php
                                    [line] => 37
                                    [args] => Array
                                        (
                                            [0] => /home/myuser/public_html/dev/dietz/site/templates/home.php
                                        )

                                    [function] => require
                                )

                            [2] => Array
                                (
                                    [file] => /home/myuser/public_html/dev/dietz/kirby/src/Cms/Template.php
                                    [line] => 167
                                    [function] => load
                                    [class] => Kirby\Toolkit\Tpl
                                    [type] => ::
                                )

                            [3] => Array
                                (
                                    [file] => /home/myuser/public_html/dev/dietz/kirby/src/Cms/Page.php
                                    [line] => 1156
                                    [function] => render
                                    [class] => Kirby\Cms\Template
                                    [type] => ->
                                )

                            [4] => Array
                                (
                                    [file] => /home/myuser/public_html/dev/dietz/kirby/src/Cms/App.php
                                    [line] => 597
                                    [function] => render
                                    [class] => Kirby\Cms\Page
                                    [type] => ->
                                )

                            [5] => Array
                                (
                                    [file] => /home/myuser/public_html/dev/dietz/kirby/src/Cms/App.php
                                    [line] => 925
                                    [function] => io
                                    [class] => Kirby\Cms\App
                                    [type] => ->
                                )

                            [6] => Array
                                (
                                    [file] => /home/myuser/public_html/dev/dietz/index.php
                                    [line] => 5
                                    [function] => render
                                    [class] => Kirby\Cms\App
                                    [type] => ->
                                )

                        )

                    [previous:Exception:private] => 
                )

        )

    [isTranslated:protected] => 1
    [message:protected] => Item "wood-white" could not be added to cart.
    [string:Exception:private] => 
    [code:protected] => error.merx.cart.add
    [file:protected] => /home/myuser/public_html/dev/dietz/site/plugins/merx/src/cart.php
    [line:protected] => 50
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [file] => /home/myuser/public_html/dev/dietz/site/templates/home.php
                    [line] => 22
                    [function] => add
                    [class] => Wagnerwagner\Merx\Cart
                    [type] => ->
                )

            [1] => Array
                (
                    [file] => /home/myuser/public_html/dev/dietz/kirby/src/Toolkit/Tpl.php
                    [line] => 37
                    [args] => Array
                        (
                            [0] => /home/myuser/public_html/dev/dietz/site/templates/home.php
                        )

                    [function] => require
                )

            [2] => Array
                (
                    [file] => /home/myuser/public_html/dev/dietz/kirby/src/Cms/Template.php
                    [line] => 167
                    [function] => load
                    [class] => Kirby\Toolkit\Tpl
                    [type] => ::
                )

            [3] => Array
                (
                    [file] => /home/myuser/public_html/dev/dietz/kirby/src/Cms/Page.php
                    [line] => 1156
                    [function] => render
                    [class] => Kirby\Cms\Template
                    [type] => ->
                )

            [4] => Array
                (
                    [file] => /home/myuser/public_html/dev/dietz/kirby/src/Cms/App.php
                    [line] => 597
                    [function] => render
                    [class] => Kirby\Cms\Page
                    [type] => ->
                )

            [5] => Array
                (
                    [file] => /home/myuser/public_html/dev/dietz/kirby/src/Cms/App.php
                    [line] => 925
                    [function] => io
                    [class] => Kirby\Cms\App
                    [type] => ->
                )

            [6] => Array
                (
                    [file] => /home/myuser/public_html/dev/dietz/index.php
                    [line] => 5
                    [function] => render
                    [class] => Kirby\Cms\App
                    [type] => ->
                )

        )

    [previous:Exception:private] => 
)
plagasul commented 3 years ago

It seems to be the case the id passed to the cart needs to be full in case of products in subfolders. It, of course makes sense, the smae happens with page().

So I have to use frames-options/wood-white not just wood-white doh!

Thank you