Müşteri tablosundaki özel bir sütunu (2) magento2'ye eklemek istiyorum ve müşteri kaydı sırasında bu alana değer katmak istiyorum. Bunun için Magento2'de müşteri tablosuna özel sütun nasıl eklenir?
ilk ben $ müşteri çağırdığınızda Magento/Müşteri/Kontrolör/Hesap/CreatePost içinde> ('1234567890') setTelephone müşteri oluşturmak customer_entity table.While içinde DB sütun (Telefon) oluşturun. Yürütme işlevi php. Magento/Customer/Model/Data/Customer.php'da Undefine fonksiyon setiTelephone hatası veriyor. Ama bu işlevi bu modelde zaten oluşturdum.Magento/Müşteri/Kontrolör/Hesap/CreatePost.php
public function execute()
{
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
if ($this->session->isLoggedIn() || !$this->registration->isAllowed()) {
$resultRedirect->setPath('*/*/');
return $resultRedirect;
}
if (!$this->getRequest()->isPost()) {
$url = $this->urlModel->getUrl('*/*/create', ['_secure' => true]);
$resultRedirect->setUrl($this->_redirect->error($url));
return $resultRedirect;
}
$this->session->regenerateId();
try {
$address = $this->extractAddress();
$addresses = $address === null ? [] : [$address];
$customer = $this->customerExtractor->extract('customer_account_create', $this->_request);
$customer->setAddresses($addresses);
//Here is I set the telephone and it is giving an error
$customer->setTelephone('1234567890');
Magento/Müşteri/Model/Veri/Customer.php
public function setTelephone($telephone)
{
return $this->setData(self::TELEPHONE, $telephone);
}
public function getTelephone()
{
return $this->_get(self::TELEPHONE);
}
Magento/Müşteri/Api /Data/CustomerInterface.php
<?php
namespace Magento\Customer\Api\Data;
interface CustomerInterface extends \Magento\Framework\Api\CustomAttributesDataInterface
{
/* Add this code*/
const TELEPHONE = 'telephone';
public function getTelephone();
public function setTelephone($telephone);
}
Özel modülle denenmiştir. Ancak bir hata veriyor.
1 exception(s): Exception #0 (Magento\Framework\Exception\LocalizedException): Please upgrade your database: Run "bin/magento setup:upgrade" from the Magento root directory. The following modules are outdated: Onjection_Customer data: current version - none, required version - 1.0.0...
Modül Kod
app/kod/Onjection/Müşteri/registration.php
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Onjection_Customer', __DIR__ );
2.app/code/Onjection/Customer /etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Onjection_Customer" setup_version="1.0.0">
<sequence>
<module name="Magento_Customer"/>
</sequence>
</module>
</config>
3.app/code/Onjection/Customer/Setup/InstallData.php
Komutları kurulumu için kullanılan<?php
namespace Onjection\Customer\Setup;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
protected $customerSetupFactory;
/**
* @var AttributeSetFactory
*/
private $attributeSetFactory;
/**
* @param CustomerSetupFactory $customerSetupFactory
* @param AttributeSetFactory $attributeSetFactory
*/
public function __construct(
CustomerSetupFactory $customerSetupFactory,
AttributeSetFactory $attributeSetFactory
) {
$this->customerSetupFactory = $customerSetupFactory;
$this->attributeSetFactory = $attributeSetFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
/** @var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
$customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
/** @var $attributeSet AttributeSet */
$attributeSet = $this->attributeSetFactory->create();
$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
$customerSetup->addAttribute(Customer::ENTITY, 'mobile', [
'type' => 'varchar',
'label' => 'Mobile',
'input' => 'text',
'required' => false,
'visible' => true,
'user_defined' => true,
'sort_order' => 1000,
'position' => 1000,
'system' => 0,
]);
$attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'mobile')
->addData([
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => ['customer_address_edit'],
]);
$attribute->save();
$setup->endSetup();
}
}
:
php bin/magento kurulumu: yükseltmesi
php bin/magento ayarları: statik içerik: dağıtımı
Magento ile çalışmanın doğru yolu bu değil. Bkz. [Burada] (https://magento.stackexchange.com/questions/88245/magento2-create-a-customer-custom-attribute). Çekirdek dosyaları da değiştirmemelisiniz. – subroutines
@subroutines Bu özel özniteliğin müşteri kayıt sayfasına nasıl eklenir? Modül oluşturmadan bunu yapmak için herhangi bir yöntem var mı? – Tomas
'telefon' zaten mevcut bir müşteri adresi özniteliğidir, kayıt sayfasında göstermek için 'magento \ module-customer \ view \ frontend \ templates \ form \ register.phtml' özelleştirmeye bakabilirsiniz. – subroutines