[英]How to extend TYPO3 cart product with new field in fe varient?
我正在嘗試使用 fe varient 擴展一個新領域。 我添加了以下代碼:
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'
);
現在,后端按預期工作,在前端呈現價值。 我添加了 model,如下所示:
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/配置/Extbase/Persistence/Classes.php
<?php
declare(strict_types=1);
return [
\Vendor\myext\Domain\Model\Product\FeVariant::class => [
'tableName' => 'tx_cartproducts_domain_model_product_fevariant',
],
];
我也在這里找到了參考,但它也不適用於 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
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.