如何在 fe varient 中使用新字段扩展 TYPO3 手推车产品?
How to extend TYPO3 cart product with new field in fe varient?
我正在尝试使用 fe 变体扩展一个新字段。我添加了以下代码:
ext_tables.sql
#
# Table structure for table 'tx_cartproducts_domain_model_product_fevariant'
#
CREATE TABLE tx_cartproducts_domain_model_product_fevariant (
note text,
);
/myext/Configuration/TCA/Overrides/tx_cartproducts_domain_model_product_fevariant.php
<?php
defined('TYPO3_MODE') or die();
$temporaryColumns = [
'note' => [
'exclude' => 1,
'label' => 'Note',
'config' => [
'type' => 'text',
'eval' => 'trim',
],
],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tx_cartproducts_domain_model_product_fevariant',
$temporaryColumns
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'tx_cartproducts_domain_model_product_fevariant',
'note',
'',
'after:title'
);
现在,后端按预期工作,在前端呈现值。我添加了如下模型:
myext/Classes/Domain/Model/Product/FeVariant.php
<?php
namespace Vendor\myext\Domain\Model\Product;
class FeVariant extends \Extcode\CartProducts\Domain\Model\Product\FeVariant
{
/**
* note
*
* @var string
*/
protected $note = '';
/**
* Returns note
*
* @return string
*/
public function getNote()
{
return $this->note;
}
/**
* Sets note
*
* @param string $note
*/
public function setNote($note)
{
$this->note = $note;
}
}
并添加了 class 映射,如下所示
myext/Configuration/Extbase/Persistence/Classes.php
<?php
declare(strict_types=1);
return [
\Vendor\myext\Domain\Model\Product\FeVariant::class => [
'tableName' => 'tx_cartproducts_domain_model_product_fevariant',
],
];
我也找到了参考 here,但它也不适用于 fe_variant。
我认为你必须在 ext_localconf.php
中添加一些行
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\Extcode\CartProducts\Domain\Model\Product\FeVariant::class] = [
'className' => \Vendor\myext\Domain\Model\Product\FeVariant::class
];
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class)
->registerImplementation(
\Extcode\CartProducts\Domain\Model\Product\FeVariant::class,
\Vendor\myext\Domain\Model\Product\FeVariant::class
);
我正在尝试使用 fe 变体扩展一个新字段。我添加了以下代码:
ext_tables.sql
#
# Table structure for table 'tx_cartproducts_domain_model_product_fevariant'
#
CREATE TABLE tx_cartproducts_domain_model_product_fevariant (
note text,
);
/myext/Configuration/TCA/Overrides/tx_cartproducts_domain_model_product_fevariant.php
<?php
defined('TYPO3_MODE') or die();
$temporaryColumns = [
'note' => [
'exclude' => 1,
'label' => 'Note',
'config' => [
'type' => 'text',
'eval' => 'trim',
],
],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tx_cartproducts_domain_model_product_fevariant',
$temporaryColumns
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'tx_cartproducts_domain_model_product_fevariant',
'note',
'',
'after:title'
);
现在,后端按预期工作,在前端呈现值。我添加了如下模型:
myext/Classes/Domain/Model/Product/FeVariant.php
<?php
namespace Vendor\myext\Domain\Model\Product;
class FeVariant extends \Extcode\CartProducts\Domain\Model\Product\FeVariant
{
/**
* note
*
* @var string
*/
protected $note = '';
/**
* Returns note
*
* @return string
*/
public function getNote()
{
return $this->note;
}
/**
* Sets note
*
* @param string $note
*/
public function setNote($note)
{
$this->note = $note;
}
}
并添加了 class 映射,如下所示
myext/Configuration/Extbase/Persistence/Classes.php
<?php
declare(strict_types=1);
return [
\Vendor\myext\Domain\Model\Product\FeVariant::class => [
'tableName' => 'tx_cartproducts_domain_model_product_fevariant',
],
];
我也找到了参考 here,但它也不适用于 fe_variant。
我认为你必须在 ext_localconf.php
中添加一些行$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\Extcode\CartProducts\Domain\Model\Product\FeVariant::class] = [
'className' => \Vendor\myext\Domain\Model\Product\FeVariant::class
];
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class)
->registerImplementation(
\Extcode\CartProducts\Domain\Model\Product\FeVariant::class,
\Vendor\myext\Domain\Model\Product\FeVariant::class
);