Aimeos Laravel - 在产品添加表单

时间:2018-03-30 12:43:16

标签: php laravel e-commerce

我是Aimeos的新手,所以需要帮助!我正在Aimeos Laravel Package的帮助下在Laravel建立一个电子商务网站。

我创建了自己的Aimeos扩展程序。现在Aimeos产品形式有“SKU”字段。我想添加另一个名为“Old SKU”的字段。因此,我覆盖了表单部分(Basic)的现有模板并添加了新字段。这是用于更改Product表单模板的目录结构“./ext/myextension/admin/jqadm/templates/product”。

我还借助此文档扩展了“mshop_product”:Aimeos - Schema update并在表格中添加了一个字段,字段名称为“oldcode”。

但我面临的问题是我无法将此值保存在表格中。

我点了这个链接:Aimeos - Extend managers items,但这很令人困惑。

我创建了一个Item 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;
        }
}

我创建了经理类:

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'
        ],
    ],
];

但价值没有得到保存。

1 个答案:

答案 0 :(得分:0)

所以,经过很多事情的努力,我已经整理出了解决方案。我的代码中有很多错误。我的代码的工作版本可以找到here

相关问题