Aimeos Laravel - 在产品添加表单中添加自定义字段
Aimeos Laravel - Add Custom Field in Product Add Form
我是 Aimeos 新手,需要帮助!在 Aimeos Laravel 包的帮助下,我正在 Laravel 中构建一个电子商务网站。
我已经创建了自己的 Aimeos 扩展。现在 Aimeos 产品表单有 "SKU" 字段。我想添加另一个名为 "Old SKU." 的字段 因此,我覆盖了表单部分(基本)的现有模板并添加了新字段。这是目录结构“./ext/myextension/admin/jqadm/templates/product”,用于更改产品表单的模板。
我还借助这篇文档扩展了"mshop_product":Aimeos - Schema update并在table中添加了一个字段,字段名"oldcode."
但我面临的问题是我无法将此值保存在 table。
我遵循了这个 link:Aimeos - Extend managers items 但它非常混乱。
我创建了一个项目Class
namespace Aimeos\MAdmin\Product\Item;
class Myproject extends Standard
{
private $myvalues;
public function __construct( array $values, ... )
{
parent::__construct( $values, ... )
$this->myvalues = $values;
}
public function getMyId()
{
if( isset( $this->myvalues['myid'] ) ) {
return (string) $this->myvalues['myid'];
}
return '';
}
public function setMyId( $val )
{
if( (string) $val !== $this->getMyId() )
{
$this->values['myid'] = (string) $myid;
$this->setModified();
}
return $this;
}
public function fromArray( array $list )
{
$unknown = [];
$list = parent::fromArray( $list );
foreach( $list as $key => $value )
{
switch( $key )
{
case 'myid': $this->setMyId( $value ); break;
default: $unknown[$key] = $value;
}
}
return $unknown;
}
public function toArray( $private = false )
{
$list = parent::toArray( $private );
if( $private === true ) {
$list['myid'] = $this->getMyId();
}
return $list;
}
}
并且我创建了管理器 Class:
namespace Aimeos\MAdmin\Product\Manager;
class Myproject extends Standard
{
private $searchConfig = array(
'product.oldcode'=> array(
'code'=>'product.oldcode',
'internalcode'=>'mpro."oldcode"',
'label'=>'Product oldcode',
'type'=> 'string', // integer, float, etc.
'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR, // _INT, _FLOAT, etc.
),
);
public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true )
{
// a modified copy of the code from the parent class
// extended by a bind() call and updated bind positions (first parameter)
}
public function getSearchAttributes( $withsub = true )
{
$list = parent::getSearchAttributes( $withsub );
foreach( $this->searchConfig as $key => $fields ) {
$list[$key] = new \Aimeos\MW\Criteria\Attribute\Standard( $fields );
}
return $list;
}
protected function createItemBase( array $values = [] /* , ... */ )
{
return new \Aimeos\MShop\Product\Item\Myproject( $values /* , ... */ );
}
}
而且我还添加了一个配置文件:
return [
'product' => [
'manager' => [
'name' => 'Myproject'
],
],
];
但是没有保存值。
因此,在与许多事情作斗争之后,我找到了解决方案。我的代码中有很多错误。可以找到我的代码的工作版本 here
我是 Aimeos 新手,需要帮助!在 Aimeos Laravel 包的帮助下,我正在 Laravel 中构建一个电子商务网站。
我已经创建了自己的 Aimeos 扩展。现在 Aimeos 产品表单有 "SKU" 字段。我想添加另一个名为 "Old SKU." 的字段 因此,我覆盖了表单部分(基本)的现有模板并添加了新字段。这是目录结构“./ext/myextension/admin/jqadm/templates/product”,用于更改产品表单的模板。
我还借助这篇文档扩展了"mshop_product":Aimeos - Schema update并在table中添加了一个字段,字段名"oldcode."
但我面临的问题是我无法将此值保存在 table。
我遵循了这个 link:Aimeos - Extend managers items 但它非常混乱。
我创建了一个项目Class
namespace Aimeos\MAdmin\Product\Item;
class Myproject extends Standard
{
private $myvalues;
public function __construct( array $values, ... )
{
parent::__construct( $values, ... )
$this->myvalues = $values;
}
public function getMyId()
{
if( isset( $this->myvalues['myid'] ) ) {
return (string) $this->myvalues['myid'];
}
return '';
}
public function setMyId( $val )
{
if( (string) $val !== $this->getMyId() )
{
$this->values['myid'] = (string) $myid;
$this->setModified();
}
return $this;
}
public function fromArray( array $list )
{
$unknown = [];
$list = parent::fromArray( $list );
foreach( $list as $key => $value )
{
switch( $key )
{
case 'myid': $this->setMyId( $value ); break;
default: $unknown[$key] = $value;
}
}
return $unknown;
}
public function toArray( $private = false )
{
$list = parent::toArray( $private );
if( $private === true ) {
$list['myid'] = $this->getMyId();
}
return $list;
}
}
并且我创建了管理器 Class:
namespace Aimeos\MAdmin\Product\Manager;
class Myproject extends Standard
{
private $searchConfig = array(
'product.oldcode'=> array(
'code'=>'product.oldcode',
'internalcode'=>'mpro."oldcode"',
'label'=>'Product oldcode',
'type'=> 'string', // integer, float, etc.
'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR, // _INT, _FLOAT, etc.
),
);
public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true )
{
// a modified copy of the code from the parent class
// extended by a bind() call and updated bind positions (first parameter)
}
public function getSearchAttributes( $withsub = true )
{
$list = parent::getSearchAttributes( $withsub );
foreach( $this->searchConfig as $key => $fields ) {
$list[$key] = new \Aimeos\MW\Criteria\Attribute\Standard( $fields );
}
return $list;
}
protected function createItemBase( array $values = [] /* , ... */ )
{
return new \Aimeos\MShop\Product\Item\Myproject( $values /* , ... */ );
}
}
而且我还添加了一个配置文件:
return [
'product' => [
'manager' => [
'name' => 'Myproject'
],
],
];
但是没有保存值。
因此,在与许多事情作斗争之后,我找到了解决方案。我的代码中有很多错误。可以找到我的代码的工作版本 here