Extending order item with custom field, class doesn´t load
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!
Extending order item with custom field, class doesn´t load
Hi all,
I´m trying to extend mshop_order_base with a custom field for a customer order reference number. I followed the instructions in the manual:
https://aimeos.org/docs/Developers/Libr ... gers_items
So far the DB table gets extended via setup but my class doesn´t seem to get loaded. I am in a TYPO3 9.5.5 environment running Aimeos 18.10.7. typo3conf/autoload includes my class but calling a template in FE with a method call to my property results in
This is my class
Cheers
Robert.
I´m trying to extend mshop_order_base with a custom field for a customer order reference number. I followed the instructions in the manual:
https://aimeos.org/docs/Developers/Libr ... gers_items
So far the DB table gets extended via setup but my class doesn´t seem to get loaded. I am in a TYPO3 9.5.5 environment running Aimeos 18.10.7. typo3conf/autoload includes my class but calling a template in FE with a method call to my property results in
Code: Select all
Call to undefined method Aimeos\MShop\Order\Item\Base\Standard::getCustref()
Code: Select all
<?php
namespace Aimeos\MShop\Order\Item\Base;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
class Leorder extends Standard {
protected $levalues;
/**
* @param \Aimeos\MShop\Price\Item\Iface $price Default price of the basket (usually 0.00)
* @param \Aimeos\MShop\Locale\Item\Iface $locale Locale item containing the site, language and currency
* @param array $values Associative list of key/value pairs containing, e.g. the order or user ID
* @param array $products List of ordered products implementing \Aimeos\MShop\Order\Item\Base\Product\Iface
* @param array $addresses List of order addresses implementing \Aimeos\MShop\Order\Item\Base\Address\Iface
* @param array $services List of order services implementing \Aimeos\MShop\Order\Item\Base\Service\Iface
* @param array $coupons Associative list of coupon codes as keys and ordered products implementing \Aimeos\MShop\Order\Item\Base\Product\Iface as values
*/
public function __construct(
\Aimeos\MShop\Price\Item\Iface $price, \Aimeos\MShop\Locale\Item\Iface $locale,
array $values = [], array $products = [], array $addresses = [],
array $services = [], array $coupons = []
) {
parent::__construct($price, $locale, $values, $products, $addresses, $services, $coupons);
$this->levalues = $values;
}
public function getCustref() {
if (isset($this->levalues['order.base.custref'])) {
return (string) $this->levalues['order.base.custref'];
}
return '';
}
public function setCustref($val) {
if ((string) $val !== $this->getCustref()) {
$this->levalues['order.base.custref'] = (string) $val;
$this->setModified();
}
return $this;
}
public function fromArray(array $list) {
$unknown = [];
$list = parent::fromArray($list);
foreach ($list as $key => $value) {
switch ($key) {
case 'order.base.custref':
$this->setCustref($value);
break;
default:
$unknown[ $key ] = $value;
}
}
return $unknown;
}
public function toArray($private = false) {
$list = parent::toArray($private);
if ($private === true) {
$list['order.base.custref'] = $this->getCustref();
}
return $list;
}
}
Robert.
Re: Extending order item with custom field, class doesn´t lo
You have to extend the order manager too which must create your new item class in the "createItemBase()" method.
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: Extending order item with custom field, class doesn´t lo
To extend the manager and create my custom item base I need a \Aimeos\MShop\Price\Item\Iface for initialization:
I have no idea on how to create one. new \Aimeos\MShop\Price\Item\Standard() ist definitely the wrong way, I guess?
This is my extended order manager:
Code: Select all
public function __construct(
\Aimeos\MShop\Price\Item\Iface $price, \Aimeos\MShop\Locale\Item\Iface $locale,
array $values = [], array $products = [], array $addresses = [],
array $services = [], array $coupons = []
) {
parent::__construct($price, $locale, $values, $products, $addresses, $services, $coupons);
$this->levalues = $values;
}
This is my extended order manager:
Code: Select all
<?php
/**
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Metaways Infosystems GmbH, 2011
* @copyright Aimeos (aimeos.org), 2015-2018
* @package MShop
* @subpackage Order
*/
namespace Aimeos\MShop\Order\Manager;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
/**
* Default order manager implementation.
*
* @package MShop
* @subpackage Order
*/
class Leorder
extends Standard {
/**
* Creates the manager that will use the given context object.
*
* @param \Aimeos\MShop\Context\Item\Iface $context Context object with required objects
*/
public function __construct(\Aimeos\MShop\Context\Item\Iface $context) {
parent::__construct($context);
}
/**
* Creates a new order item.
*
* @param array $values List of attributes for order item
*
* @return \Aimeos\MShop\Order\Item\Base\Leorder New order item
*/
protected function createItemBase(array $values = []) {
$locale = $this->getContext()->getLocale();
return new \Aimeos\MShop\Order\Item\Base\Leorder($values, $locale);
}
}
Re: Extending order item with custom field, class doesn´t lo
Hm, I can´t seem to get working.
As I read here: https://aimeos.org/docs/Developers/Libr ... gers_items, there´s definitely more to it but the information in the docs still leave questions open.
Is there maybe a code example somewhere covering all aspects, including how to code the saveItem() method and how to form the sql for config/mshop.php?
These parts are mentioned in the docs but I currently lack depth of Aimeos knowledge on how to set it up porperly.
As I read here: https://aimeos.org/docs/Developers/Libr ... gers_items, there´s definitely more to it but the information in the docs still leave questions open.
Is there maybe a code example somewhere covering all aspects, including how to code the saveItem() method and how to form the sql for config/mshop.php?
These parts are mentioned in the docs but I currently lack depth of Aimeos knowledge on how to set it up porperly.
Re: Extending order item with custom field, class doesn´t lo
Extending the saveItem() method is only copy&paste, adding your new column and renumbering the following columns. The SQL config for INSERT, UPDATE and SELECT has to be extended by your new column as well.
Others have done that in the past too. Maybe their posts help you to find the missing link:
https://www.google.com/search?q=site%3A ... +base+item
Others have done that in the past too. Maybe their posts help you to find the missing link:
https://www.google.com/search?q=site%3A ... +base+item
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: Extending order item with custom field, class doesn´t lo
Halfway there. I am able to see the new field in the account history when adding values directly in the database.
But my baskets don´t include the new field. Is there anything special when extending the order item?
Here´s a Gist of my current implementation. I had to alter the filenames Leorder.php since they must be unique in a Gist. They are LeshopItem.php and LeshopManager.php for that reason.
https://gist.github.com/boettner-it/081 ... 24907fe91b
But my baskets don´t include the new field. Is there anything special when extending the order item?
Here´s a Gist of my current implementation. I had to alter the filenames Leorder.php since they must be unique in a Gist. They are LeshopItem.php and LeshopManager.php for that reason.
https://gist.github.com/boettner-it/081 ... 24907fe91b
Re: Extending order item with custom field, class doesn´t lo
You need to add your new field in the SQL statements before the "siteid" column and you must add it to the GROUP BY clause of the SELECT statement. Everything else seems fine at the first glimpse.
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: Extending order item with custom field, class doesn´t lo
Besides the field order in SQL a Decorator was necessary to actually save the value to the object. I updated the Gist with all final changes:
https://gist.github.com/boettner-it/081 ... 24907fe91b
https://gist.github.com/boettner-it/081 ... 24907fe91b