MailChimp API 1.3 + Hominid 3 + Groupings - ruby

For some reason I just can't get the latest version of Hominid working with groupings in MailChimp.
Here's a snippet of what I'm doing:
info[:GROUPINGS] = { 'name' => 'Locations', 'groups' => 'SomeLocation' }
mailchimp = Hominid::API.new(MAILCHIMP_API_KEY)
list_id = mailchimp.find_list_id_by_name MAILCHIMP_LIST_NAME
mailchimp.list_update_member(list_id, email_value, info)
I've tried seemingly every combination of arrays and hashes to get the groupings working, but I keep getting variations of this error:
<270> "V" is not a valid Interest Grouping id for the list: Test List
Any help would be appreciated!

It seems that it needs an array of hashes:
info[:GROUPINGS] = [ { 'name' => 'Locations', 'groups' => 'SomeLocation' } ]
I hope this helps someone!

Related

Add non existing item to list

I am trying to fill a list with objects which haven't been added yet by random to a list. So I loop rInt times through a list and want to pick randomly objects and add them to the list if they does not already exist:
collectionList = new List<CollectionSccmCM>();
Random r = new Random();
int rInt = r.Next(0, 5);
for(int i=0; i<=rInt; i++){
collectionList.Add(_context.CollectionApplications.OrderBy(x => Guid.NewGuid()).Where(x => collectionList.Any(y => y.CollectionID !=(x.collection_id.ToString()))).Select(x => new CollectionSccmCM(){CollectionID= x.collection_id.ToString(), Name=x.collection_name}).FirstOrDefault());
}
I seems that I have a mistake in the orderby and where part, but I cannot figure out the error. When I put a toList between I dont receive any syntax error anymore, but also doesn't work.
Any tip what I am doing wrong?
Thanks
Edit:
I did a mistake and had to use contains, but still not working:
collectionList.Add(_context.CollectionApplications.OrderBy(x => Guid.NewGuid()).Where(x => collectionList.Any(y => !y.CollectionID.Contains(x.collection_id.ToString()))).Select(x => new CollectionSccmCM(){CollectionID= x.collection_id.ToString(), Name=x.collection_name}).FirstOrDefault());
Edit:
Got it working with a select, but not so happy with it and dont understand why the otherone wasnt working.
collectionList.Add(_context.CollectionApplications.OrderBy(x => Guid.NewGuid()).Where(x => !collectionList.Select(y => y.CollectionID).ToList().Contains(x.collection_id.ToString())).Select(x => new CollectionSccmCM(){CollectionID= x.collection_id.ToString(), Name=x.collection_name}).FirstOrDefault());
I would strongly suggest you consider adding some whitespace to your LINQ. I would break your first example down as follows:
collectionList.Add(
_context.CollectionApplications
.OrderBy(x => Guid.NewGuid())
.Where(x => collectionList.Any(y => y.CollectionID !=(x.collection_id.ToString())))
.Select(x => new CollectionSccmCM() {
CollectionID = x.collection_id.ToString(),
Name = x.collection_name
}).FirstOrDefault()
);
Looking at your Where call, you are including in the possible elements to add, those elements where any of the collection IDs doesn't match (collectionList.Any(y => ... )). That's all of them (unless you only have one element in collectionList).
You probably want to use All instead of Any -- where all of the collection IDs don't match:
.Where(x => collectionList.All(y => y.CollectionID != x.collection_id.ToString()))

undefined method `user_id' for #<ActiveRecord::Relation:0x007f8da82da248>

I am error in the 2nd line of the code here, I have a column user_id in the Estate table. What am I doing wrong here ?
myestate = Estate.where(:Mgmt => current_user.Company)
#managements = User.where(:id => myestate.user_id)
where is returning an ActiveRecord::Relation object. Because where(:mgmt => current_user.company) could return 0, 1, or Many records, you have to tell the query what you'd like from it.
Try:
myestate = Estate.where(:Mgmt => current_user.Company).first
#managements = User.where(:id => myestate.user_id)
Getting familiar with AREL and how it works is highly recommended. You can find great info on the github page or the Active Record Query Guide

how to update Cart Options in Codeigniter?

Through Documents provided by Codeigniter Its Cart Library doesnt Update its options We can add the Options like that
$data = array(
array(
'id' => 'sku_123ABC',
'qty' => 1,
'price' => 39.95,
'name' => 'T-Shirt',
'options' => array('Size' => 'L', 'Color' => 'Red')
)
);
$this->cart->insert($data);
Is there any other way or any tutorial to learn how we can update options of Cart just like
$qid = $this->input->post("qid");
$pairs = $this->input->post("pairs");
$males = $this->input->post("males");
$females = $this->input->post("females");
$data = array(
array(
'rowid' => $qid,
'qty' => 1,
'options' => array('pairs' => $pairs, 'males' => $males, 'females' => $females))
);
$this->cart->update($data);
I have searched it but seems no one has made any fix for it?
Though I have not found any solution therefore I am using simple solution and that is just rest the item in cart and adding new item with same id and updated option values. Its not great trick though but it is just working for me.
I am fallen yesterday like this kind of problem then i create Extending / Override update function. Here how to Extending Native library Link : Create CI Library
Here is my modified code in Github Link
I hope it will help someone and also can modify as their need.
No it did not work for me.. but there is no any errors, I check the array within the _update function as well,
Array
(
[id] => 177
[rowid] => 66bd8895e10f189f62bf3a65ada83630
[qty] => 1
[options] => Array
(
[vat] => 0
[discount] => 0
)
)
I know i'ts just too late but I want to share my solution:
I just got the the options in an array and updated it as I wanted and then update the entire options field in the cart with the array content.
Hope this help somebody.
Sorry for the english.
The way I tried was a bit difficult but it works. You can’t just update a single option value. To update you have to pass all the existing values to all the option values with the value you want to update as well.
If you want to update your Size option
$data = array(
‘rowid’ => $yourRowIdHere,
‘options’ => array ( ‘color’ => $yourExistingValue, ‘length’ => $yourExistingValue, ‘size’ => $newUpdatedValue)
));
$this->cart->update($data);
Give it a try :)

getting the value of array key in codeigniter

I have the following line in my controller:
$data['faq'] = $this->faqModel->get();
This data print the following using the print_r
Array
(
[faq] => Array
(
[0] => Array
(
[faqid] => 12
[catid] => 122
[question] => How this CMS works
[question_en] => How this CMS works
[answer] => How this CMS works?
[answer_en] => How this CMS works?
[sorder] => 2
[visible] => 1
)
[1] => Array
(
[faqid] => 8
[catid] => 121
[question] => How does the design cost?
[question_en] => How does the design cost?
[answer] => How does the design cost?
[answer_en] => How does the design cost?
[sorder] => 1
[visible] => 1
)
)
)
I want to use the value stored in the [catid] key, and I am trying to do something like:
$data['faq']['catid'] to get that value in the controller (I want to make another select with that value) But I am getting with this error message: Undefined index: catid
Anyone can help me to get the value of ['catid']???
Regards, Zoran
Its 3 dimensional array u look closely there is two elements in faq array. You must wrote something like this: $data['faq'][0]['catid'] or $data['faq'][1]['catid']
The way you are accessing the array is incorrect, you are missing the item index on the second level. The correct way to use it as you are doing would be to do
echo $data['faq'][0]['faqid']; //faqid of the first item
However, this will only show one faqid at a time, and it not so useful when you are iterating. So, a good way would be this way.
foreach($data['faq'] as $value) {
echo $value['faqid'];
}

CodeIgniter: Using array within array

I am following nettut+ tutorial for pagination and to store POST inputs as querystrings in db. So far, everything works fine until, suppose if I get an array as POST input, i am unable to loop through it and get all the array values and to store into query_array (i.e., store array within array).
The snippets below:
$query_array = array(
'gender' => $this->input->post('gender'),
'minage' => $this->input->post('minage'),
'maxage' => $this->input->post('maxage'),
'Citizenship' => $this->input->post('citizenship'), // checkboxes with name citizenship[]
);
This returns only last stored array value in Citizenship.
The output array:
Array ( [gender] => 1 [minage] => 18 [maxage] => 24 [Citizenship] => 2 )
makes the query string as:
&gender=1&minage=18&maxage=24&Citizenship=2
But, my requirement is to get all the values of 'Citizenship' array instead of last stored value.
The output required to make query string:
Array ( [gender] => 1 [minage] => 18 [maxage] => 24 [Citizenship] => 2 [Citizenship] => 4 [Citizenship] => 6 )
The query string :
&gender=1&minage=18&maxage=24&Citizenship[]=2&Citizenship[]=4&Citizenship[]=6
Any help appreciated..
Thanks.
Doesn't look like code ignighter supports un-named multidimensional arrays as input without a bit of hacking.
If you can access raw $_POST data try replacing
$this->input->post('citizenship')
with
array_map('intval',$_POST['citizenship'])
Alternativly add keys to your post data:
&gender=1&minage=18&maxage=24&Citizenship[0]=2&Citizenship[1]=4&Citizenship[2]=6
I fixed it myself. I just looped through the POST array and got the individual array key & pair values.
foreach($_POST['Citizenship'] as $k => $v) {
$Citizenship[$v] = $v;
}
Hope this helps someone who face similar problem.

Resources