Prestashop 1.7.7 在自定义字段上创建 ToggleColumn
Prestashop 1.7.7 create a ToggleColumn on a custom field
在我的数据库中,我有一个字段 isVerified
,它是一个 bool : 0 / 1
。
我想创建一个 ToggleColumn
,所以每当我点击管理面板时,它都会切换到 true / 1
,我会执行发送邮件等操作。
这是我到目前为止所做的:
在数据库中创建一个 isVerified
列并将其设置为 bool default 0
创建:
->add((new ToggleColumn('isVerified'))
->setName('Verify')
->setOptions([
'field' => 'isVerified',
'primary_field' => 'id_customer',
'route' => 'admin_customers_toggle_verify',
'route_param_name' => 'customerId'
])
)
在customers.yml
中参数一个路由:
`
admin_customers_toggle_verify:
path: /{customerId}/toggle-verify
methods: [POST]
defaults:
_controller: PrestaShopBundle:Admin/Sell/Customer/Customer:toggleVerify
_legacy_controller: AdminCustomers
_legacy_link: AdminCustomers:verifycustomer
_legacy_parameters:
id_customer: customerId
requirements:
customerId: \d+
- 在
CustomerController
中创建了一个 toggleVeryfyAction
方法:
$editableCustomer = $this->getQueryBus()->handle(new GetCustomerForEditing((int) $customerId)); $editCustomerCommand = new EditCustomerCommand((int) $customerId); $editCustomerCommand->setIsVerified(!$editableCustomer->isVerified()); $this->getCommandBus()->handle($editCustomerCommand);
我找到的解决方案是在这些文件中添加字段:
- CustomerFormDataProvider
- CustomerFormDataHandler
- AddCustomerCommand
- EditCustomerCommand
- GetCustomerForEditingHandler
- EditableCustomer
- CustomerType
在我的数据库中,我有一个字段 isVerified
,它是一个 bool : 0 / 1
。
我想创建一个 ToggleColumn
,所以每当我点击管理面板时,它都会切换到 true / 1
,我会执行发送邮件等操作。
这是我到目前为止所做的:
在数据库中创建一个
isVerified
列并将其设置为bool default 0
创建:
->add((new ToggleColumn('isVerified')) ->setName('Verify') ->setOptions([ 'field' => 'isVerified', 'primary_field' => 'id_customer', 'route' => 'admin_customers_toggle_verify', 'route_param_name' => 'customerId' ]) )
在
customers.yml
中参数一个路由:
`
admin_customers_toggle_verify:
path: /{customerId}/toggle-verify
methods: [POST]
defaults:
_controller: PrestaShopBundle:Admin/Sell/Customer/Customer:toggleVerify
_legacy_controller: AdminCustomers
_legacy_link: AdminCustomers:verifycustomer
_legacy_parameters:
id_customer: customerId
requirements:
customerId: \d+
- 在
CustomerController
中创建了一个toggleVeryfyAction
方法:$editableCustomer = $this->getQueryBus()->handle(new GetCustomerForEditing((int) $customerId)); $editCustomerCommand = new EditCustomerCommand((int) $customerId); $editCustomerCommand->setIsVerified(!$editableCustomer->isVerified()); $this->getCommandBus()->handle($editCustomerCommand);
我找到的解决方案是在这些文件中添加字段:
- CustomerFormDataProvider
- CustomerFormDataHandler
- AddCustomerCommand
- EditCustomerCommand
- GetCustomerForEditingHandler
- EditableCustomer
- CustomerType