Magento2 DOB Customer attribute Save - magento2

While customer creation , i need to store dob attribute for customer.which is not saving. facing issue like,
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'customer_entity.value_id' in 'field list', query was: SELECT customer_entity.value_id FROM customer_entity WHERE (attribute_id='11' AND entity_id='199')
meanwhile,if i added custom date attribute in customer entity it get saved.
Any one have any idea about it.
Thanks in advance.
I am storing custom attributes as given below,
$data = []; //Array of attributes with key as attribute code
$customer = $this->customerModel->load($customerId);
$customerData = $customer->getDataModel();
$customerResource = $this->customerAttrFactory->create();
foreach ($data as $attrCode => $attrValue):
$customerData->setCustomAttribute($attrCode, $attrValue);
$customer->updateData($customerData);
$customerResource->saveAttribute($customer, $attrCode);
endforeach;

No need to save dob as an attribute.
Customer entity table has dob field so we can set it through customer model as given below.
$websiteId = $this->storeManager->getWebsite()->getWebsiteId();
$customer = $this->customerFactory->create();
$customer->setWebsiteId($websiteId);
$data['dob'] = $formData['dob'];
$customer->setData($data);
$customer->save();

Related

how to show list of CustomerId in dropdown list

i want to create Customer diary on the base of customerID that present in customer table.
In customerID field i want dropdown list having list of CustomerId's that are present in database
How can i do that ? can someone help me please
var _objAllCustomerIds = null;
using (AdventureWorksEntities context = new AdventureWorksEntities())
{
_objAllCustomerIds = context.MyCustomers.Select(customer => customer.Id).ToList();
}
//where AdventureWorksEntities is your DBcontent containing all your entities
//MyCustomers is the entities representation of your customer table
if this is in your .aspx file
then in your .aspx.cs file (assuming you're using code behind) you'd get the list of customer IDs and then bind that list to this dropdown.
Does this answer from another question help?
How to bind the selected value of a DropDownList

Use SugarCRM Beans to retrieve data

I needed to convert this SQL query to bean format.
"SELECT first_name, last_name FROM leads INNER JOIN contacts_leads_1_c ON
leads.id=contacts_leads_1_c.contacts_leads_1leads_idb where
contacts_leads_1_c.contacts_leads_1contacts_ida='".$bean->id."'";
I have this already in place
$lead = new Lead();
$where = "contacts_leads_1_c.contacts_leads_1contacts_ida = '$bean->id' ";
$lead_list = $lead->get_full_list("", $where,true);
$all_leads = array();
foreach($all_leads as $leads){
$bean->contacts_leads = $ref->first_name . ',' . $ref->last_name;
This is the problem
$lead_list = $lead->get_full_list("", $where,true);
Thanks in advance,
If $bean is already a contact you can grab a list of the related fields:
$leads = $bean->get_linked_beans('FIELDNAME','Leads');
FIELDNAME can be found in the vardefs and isn't the relationship name it's the name of the field that defines the link.
Note: In your example you're creating an empty array then looping over it.

how to insert multiple values using entity framework..?

I'm using Silverlight5 with MVVM framework and Entity framework. In my project i have one doubt..
I have an entity named 'Customer' the structure is as follows..
Customer ocustomer = new Customer();
ocustomer.CustomerName = customername;
ocustomer.CompanyName = company;
ocustomer.AddressLine1 = address1;
ocustomer.AddressLine2 = address2;
ocustomer.City = city;
ocustomer.State = state;
ocustomer.Country = country;
ocustomer.ZipCode = zipcode;
ocustomer.Notes = note;
_context.Customers.Add(ocustomer);
Now my need is to insert the Customer value into another table Named Customer_Entity
Customer_Entity ocustomerEntity=new Customer_Entity ();
ocustomerEntity.CustomerID=Customer_ID;
ocustomerEntity.EntityTypeID =1;
.
.
.
.
ocustomerEntity.CreatedTime =System.DateTime.Now;
ocustomerEntity.CreatedBy=Common.ActiveData.Instance.userid;
Here my need is to insert the customer value to Customer_Entity in every single row..
Customer_Entity Table Structure is as follows,
EntityID| CustomerID| EntityValue|
----------------------------------
1 | 22 |jasper |
2 | 22 |Company:Raj |
3 | 22 |Address |
ocustomer.CustomerName=customername
.
.
.
ocustomer.CreatedTime=system.DateTime.Now..
so i need to insert all the values in every single row using unique CustomerID..
Need help to solve this one..
On your CustomerEntity object you should have a navigation property pointing to the corresponding Customer record. Similarly, I would expect that your Customer class has a collection of CustomerEntity on it as well.
In which case, you should instantiate the Customer object, populating with the necessary information. Don't add it to the DbSet yet, though. Afterwards, create all of the CustomerEntity records that you need to, connecting it to the Customer object by using the navigation property itself (i.e. NOT the ID field), and adding that CustomerEntity record to the corresponding DbSet in you Context class.
As a final step add your Customer object to the corresponding DbSet, and run SaveChanges. You should be good to go. Entity Framework should automatically generate the ID for you and populate it to the CustomerEntity records.

required field for other model's field in yii

I need to store a record in First Model. It has around 10 fields. Now, I need to apply required rule for one field which i'm storing in SECOND model and I'm getting these values for this field from Third model.(it is a drop down field)
how can i make this field mandatory in yii??
can any one help please..
Many Thanks,
You can add additional attributes and rules to a model. You don't have to only use attributes that directly relate to fields in your database table. Let's look at a basic example. You have a user (User) table which has the following fields:
id
email
password
And you have another table which stores user profile (UserProfile) information which has the structure:
id
user_id
country
When the user creates their account, you would have a form that captures their information. Your User model would have rules like:
array('email, password', 'required'),
array('email', 'unique', 'message'=>'Email already in use'),
...
You can add an attribute for country to your User model like so:
class User extends CActiveRecord {
public $country;
...
And then in your rules you can add the new attribute:
array('email, password, country', 'required'),
array('email', 'unique', 'message'=>'Email already in use'),
...
The country attribute will now be a part of your User model. You can now add that to your form:
<?php echo $form->dropDownList($model,'country',CHtml::listData(Country::model()->findAll(),'id','country_name'),array('empty'=>'-- select a country --')); ?>
Now on your form submit, the $model->validate() method will validate the country field. You can save this manually to your second model (UserProfile), something like:
if(isset($_POST['User'])){
if ($model->validate()){
$user_profile = new UserProfile;
$user_profile->user_id = $model->id;
$user_profile->country = $model->country;
$user_profile->save();
...
Hopefully that answers your question.

TYPO3 - Adding values to a table using powermail

I made a form so that users can register their email address for a contest. Im using a powermail form and someone told me to use dbEntry to do this, but im not sure how to do it. This is my code so far:
plugin.tx_powermail_pi1{
dbEntry{
tt_address._enable = TEXT
tt_address._enable.value = 1
tt_address.email = TEXT
tt_address.email.value = ????
}
debug.output = all
}​
Ive been told to activate _enable to enable the data insertion. But now I dont know how to access the field value of the form. I probably should use the template id, which is ###UID71###, but I have no idea how.
According to the official documentation, you can do it this way:
plugin.tx_powermail.settings.setup {
dbEntry {
# enable or disable db entry for tt_address
tt_address._enable = TEXT
tt_address._enable.value = 1
# write only if field email is not yet filled with current value
# (update: update values of existing entry)
# (none: no entry if field is filled)
# (disable: always add values don't care about existing values)
tt_address._ifUnique.email = update
# fill table "tt_address" with field "pid" with the current pid (e.g. 12)
tt_address.pid = TEXT
tt_address.pid.data = TSFE:id
# fill table "tt_address" with field "tstamp" with the current time as timestamp (like 123456789)
tt_address.tstamp = TEXT
tt_address.tstamp.data = date:U
# fill table "tt_address" with field "name" with the value from powermail {firstname}
tt_address.name = TEXT
tt_address.name.field = firstname
...
}
}
I also found an (older) forum post (in German) with examples that use data from the user session:
# table "tt_address" with field "last_name" is the value from powermail (tt_content uid 88) field uid18 (###uid18###)
tt_address.last_name = TEXT
tt_address.last_name.data = TSFE:fe_user|sesData|powermail_88|uid18