JS Error in Aimeos Lib
Forum rules
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
JS Error in Aimeos Lib
Hi Admin,
i am playing with the aimeos jsonapi and run into an error i couldn't fix.
My first attempt was that it has to do with my own extension, but after awhile of frustrating debugging and digging deeper into the code, i tried it on the aimeos demo site and saw that the error also exist there.
How i ran into the js error.
1. Open http://typo3.demo.aimeos.org/demo/detai ... article/0/
2. (Put the demo article into Basket) - Press Button "Add to Basket"
3. (Basket opens, with the demo Article attached)
4. (Add the coupon fixed) - Type "fixed" into coupon field
The error Occurs in the aimeos.js File at the updateBasket function on the second element of basket.included at line 385 when it tries to set the entry.links.self.href.
Entry.links is at the second element of basket.included undefined and therfore you will get bellow JS Error in Browser console. (See Pics Error-1 to Error-3)
i am playing with the aimeos jsonapi and run into an error i couldn't fix.
My first attempt was that it has to do with my own extension, but after awhile of frustrating debugging and digging deeper into the code, i tried it on the aimeos demo site and saw that the error also exist there.
How i ran into the js error.
1. Open http://typo3.demo.aimeos.org/demo/detai ... article/0/
2. (Put the demo article into Basket) - Press Button "Add to Basket"
3. (Basket opens, with the demo Article attached)
4. (Add the coupon fixed) - Type "fixed" into coupon field
The error Occurs in the aimeos.js File at the updateBasket function on the second element of basket.included at line 385 when it tries to set the entry.links.self.href.
Entry.links is at the second element of basket.included undefined and therfore you will get bellow JS Error in Browser console. (See Pics Error-1 to Error-3)
aimeos.js?1509296373:385 Uncaught TypeError: Cannot read property 'self' of undefined
at Object.updateBasket (aimeos.js?1509296373:385)
at Object.<anonymous> (aimeos.js?1509296373:337)
at Object.<anonymous> (jquery-2.2.4.min.js:2)
at i (jquery-2.2.4.min.js:2)
at Object.fireWith [as resolveWith] (jquery-2.2.4.min.js:2)
at z (jquery-2.2.4.min.js:4)
at XMLHttpRequest.<anonymous> (jquery-2.2.4.min.js:4)
- Attachments
-
- Error-1.jpg (247.26 KiB) Viewed 2712 times
-
- Error-2.jpg (110.95 KiB) Viewed 2712 times
-
- Error-3.jpg (114.23 KiB) Viewed 2712 times
Last edited by tenkraD on 14 Dec 2019, 14:44, edited 1 time in total.
Re: Uncaught TypeError Aimeos updateBasket / Jsonapi
Pic Step 2 and Step 4
- Attachments
-
- Step 2) Demo Article in Basket.jpg (118.86 KiB) Viewed 2711 times
-
- Step 4) Adding coupon fixed.jpg (170.54 KiB) Viewed 2711 times
Re: JS Error in Aimeos Lib
And while playing with the jsonapi i saw something in the template and im a bit confused.
File: aimeos/Resources/Private/Extensions/ai-client-jsonapi/client/jsonapi/templates/basket/standard.php
At line 262 it has this code
Shouldn't that href and allow be inside self array like this
Thanks for clarification
File: aimeos/Resources/Private/Extensions/ai-client-jsonapi/client/jsonapi/templates/basket/standard.php
At line 262 it has this code
Code: Select all
<?php if( $this->item->getId() === null ) : ?>
,
"basket/product": {
"href": "<?= $this->url( $target, $cntl, $action, ['resource' => 'basket', 'id' => $basketId, 'related' => 'product'], [], $config ); ?>",
"allow": ["POST"]
},
"basket/service": {
"href": "<?= $this->url( $target, $cntl, $action, ['resource' => 'basket', 'id' => $basketId, 'related' => 'service'], [], $config ); ?>",
"allow": ["POST"]
},
"basket/address": {
"href": "<?= $this->url( $target, $cntl, $action, ['resource' => 'basket', 'id' => $basketId, 'related' => 'address'], [], $config ); ?>",
"allow": ["POST"]
},
"basket/coupon": {
"href": "<?= $this->url( $target, $cntl, $action, ['resource' => 'basket', 'id' => $basketId, 'related' => 'coupon'], [], $config ); ?>",
"allow": ["POST"]
}
<?php else : ?>
Code: Select all
<?php if( $this->item->getId() === null ) : ?>
,
"basket/product": {
"self": {
"href": "<?= $this->url( $target, $cntl, $action, ['resource' => 'basket', 'id' => $basketId, 'related' => 'product'], [], $config ); ?>",
"allow": ["POST"]
}
},
"basket/service": {
"self": {
"href": "<?= $this->url( $target, $cntl, $action, ['resource' => 'basket', 'id' => $basketId, 'related' => 'service'], [], $config ); ?>",
"allow": ["POST"]
}
},
"basket/address": {
"self": {
"href": "<?= $this->url( $target, $cntl, $action, ['resource' => 'basket', 'id' => $basketId, 'related' => 'address'], [], $config ); ?>",
"allow": ["POST"]
}
},
"basket/coupon": {
"self": {
"href": "<?= $this->url( $target, $cntl, $action, ['resource' => 'basket', 'id' => $basketId, 'related' => 'coupon'], [], $config ); ?>",
"allow": ["POST"]
}
}
<?php else : ?>
Thanks for clarification
Last edited by tenkraD on 14 Dec 2019, 15:30, edited 2 times in total.
Re: JS Error in Aimeos Lib
No, the JSON:API response is correct at that place. It must be
But I think that is the wrong place you are looking for the problem because "entry.links" is already undefined. This is because it's a rebate product you can't change in the basket and therefore, the "links" section is missing:
https://github.com/aimeos/ai-client-jso ... d.php#L109
The the problem is a missing check in Javascript if "entry.links" exists because this isn't always the case.
Can you test that and create PR with a fix?
Code: Select all
"basket/product": {
"href": "<?= $this->url( $target, $cntl, $action, ['resource' => 'basket', 'id' => $basketId, 'related' => 'product'], [], $config ); ?>",
"allow": ["POST"]
},
https://github.com/aimeos/ai-client-jso ... d.php#L109
The the problem is a missing check in Javascript if "entry.links" exists because this isn't always the case.
Can you test that and create PR with a fix?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: JS Error in Aimeos Lib
A quick and dirty sollution would be this.
product.data("urldata", csrf);
if( typeof entry.links !== "undefined"){
product.data("url", entry.links.self.href);
}
//product.data("url", entry.links.self.href);
Re: JS Error in Aimeos Lib
Seems to be a good solution too
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star