Hello in a project with Version CE 2.3.7 i need to add a fixed value for every new customer that will be always the same "AU" Phpmyadmin Image
In short in table marketplace_userdata > column country_pic once a user is registered, must be always "AU" as default rule
I made some check and marketplace_userdata is generated from a premium extension so i checked in controller some possibile useful info and i found this.
I tried to add following code but seems not correct. Any possible suggestion about how can i achieve the result?
$seller->setData('country_pic', 'AU');
/**
* Save Seller Data
*/
private function saveSellerData()
{
try {
$shopUrl = $this->getRequest()->getParam("profileurl");
$sellerId = $this->_getSession()->getCustomerId();
$status = $this->getStatus();
$status = 1; // set each customer as seller
$autoId = 0;
$collection = $this->_sellerCollectionFactory->create();
$collection->addFieldToFilter('seller_id', $sellerId);
foreach ($collection as $value) {
$autoId = $value->getId();
break;
}
$seller = $this->_sellerFactory->create()->load($autoId);
$seller->setData('is_seller', $status);
$seller->setData('shop_url', $shopUrl);
$seller->setData('seller_id', $sellerId);
$seller->setCreatedAt($this->_date->gmtDate());
$seller->setUpdatedAt($this->_date->gmtDate());
$seller->setAdminNotification(1);
$seller->save();
} catch (\Exception $e) {
$this->_helper->logDataInLogger(
"controller_account_becomesellerPost saveSellerData : ".$e->getMessage()
);
$this->messageManager->addError($e->getMessage());
}
try {
if ($status) {
/* clear cache */
$this->_helper->clearCache();
$this->messageManager->addSuccess(
__('Congratulations! Your seller account is created.')
);
} else {
$customer = $this->_helper->getCustomer();
$adminStoremail = $this->_helper->getAdminEmailId();
$adminEmail = $adminStoremail ? $adminStoremail : $this->_helper->getDefaultTransEmailId();
$adminUsername = $this->_helper->getAdminName();
$senderInfo = [
'name' => $customer->getFirstName().' '.$customer->getLastName(),
'email' => $customer->getEmail(),
];
$receiverInfo = [
'name' => $adminUsername,
'email' => $adminEmail,
];
$emailTemplateVariables['myvar1'] = $customer->getFirstname().' '.
$customer->getMiddlename().' '.$customer->getLastname();
$emailTemplateVariables['myvar2'] = $this->backendUrl->getUrl(
'customer/index/edit',
['id' => $customer->getId()]
);
$emailTemplateVariables['myvar3'] = $this->_helper->getAdminName();
$this->mpEmailHelper->sendNewSellerRequest(
$emailTemplateVariables,
$senderInfo,
$receiverInfo
);
$this->messageManager->addSuccess(
__('Your request to become seller is successfully raised.')
);
}
} catch (\Exception $e) {
$this->_helper->logDataInLogger(
"controller_account_becomesellerPost saveSellerData : ".$e->getMessage()
);
$this->messageManager->addError($e->getMessage());
}
}
Thanks
You can add default value for this column in InstallSchema.php
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
try {
$table = $installer->getConnection()->newTable(
$installer->getTable('marketplace_userdata')
)
->addColumn(
'country_pic',
Table::TYPE_TEXT,
null,
['nullable' => false, 'unsigned' => true, 'default' => 'AU']
)
;
$installer->getConnection()->createTable($table);
} catch (\Zend_Db_Exception $e) {
}
$installer->endSetup();
}
Ok thanks. What is the path of installschema.php?