I am creating a module in which I tried to JOIN two Collection.
1st is custom collection ('custom/custom') and second is ('customer/customer'), I want to filter the collection based on a custom customer attribute 'pushnotification'.
What so far I did :
$collection = Mage::getModel('custom/custom')->getCollection();
$collection->getSelect()->join(
array('cust' => 'customer_entity'),
'cust.entity_id = main_table.user_id');
Output
[id] => 1
[user_id] => 1
[registration_id] => 123456
[device_type] => 0
[entity_id] => 1
[entity_type_id] => 1
[attribute_set_id] => 0
[website_id] => 1
[email] => deepak#gmail.com
[group_id] => 1
[increment_id] =>
[store_id] => 1
[created_at] => 2015-10-03 13:26:37
[updated_at] => 2015-10-22 06:25:33
[is_active] => 1
[disable_auto_group_change] => 0
My query : How can I JOIN custom ('custom/custom') collection with customer ('customer/customer') collection filter based on attribute pushnotification?
Related
I have a collection like the below. I need to fetch those users, whom does not uploaded documents. Now from the relationship, How can I fetch this?
[0] => Array
(
[id] => 2
[user_id] => 8
[referred_by] =>
........
[user_documents] =>
)
[1] => Array
(
[id] => 3
[user_id] => 9
[referred_by] =>
[reference_id] => NM1100008
.......
[user_documents] => Array
(
[id] => 1
[customer_id] => 3
[doc_type] => 1
[document] => N8xFORsPpkTayTQ9Ihyz0ly7QM62TJHxvHhSFQSN.png
[admin_comment] =>
[approve_status] => approve
[other_gov_id] =>
[doc_no] => 1
[created_at] => 2020-04-04 12:39:12
[updated_at] => 2020-04-06 13:57:01
[deleted_at] =>
)
)
I want to get rows only when user_documents is empty.. To get those users who does not uploaded documents to the system.
[user_documents] =>
Thanks in advance.
You can use laravel querying-relationship-absence
$users= User::doesntHave('user_documents')->get();
Depending on how you have setup your relations, something like this should work:
User::doesntHave('documents')->get();
I have use in model .
$data = DB::select('select * from users');
return $data;
But in controller I have got like this.
Array
(
[0] => stdClass Object
(
[Id] => 10
[Name] => Sachin
[Gender] => M
)
[1] => stdClass Object
(
[Id] => 12
[Name] => Sourav
[Gender] => M
)
)
But I want Like this
Array
(
[0] => Array
(
[Id] => 10
[Name] => Sachin
[Gender] => M
)
[1] => Array
(
[Id] => 12
[Name] => Sourav
[Gender] => M
)
)
I already tried using get() and toArray() but its giving call to unknown member function.
Anyone have an idea how to resolved this issue.
You just use the laravel standard function
public function testData(){
$data = YOUR_MODEL_NAME::all()->toArray();
echo "<pre>";print_r($data);
}
UPDATED:
public function testData(){
$data = DB::select('select * from users');
$data = collect($data)->map(function($x){ return (array) $x; })->toArray();
echo "<pre>";print_r($data);
}
Output will be :
UPDATED:
Array
(
[0] => Array
(
[email] => bmc-admin#gmail.com
[member_code] => BMC0001ADMIN
)
[1] => Array
(
[email] => bmc-analyst#gmail.com
[member_code] => BMC0003ADMIN
)
[2] => Array
(
[email] => bmc-product-manager#gmail.com
[member_code] => BMC0002ADMIN
)
)
Array
(
[0] => Array
(
[id] => 1
[drewry_user_id] => 1
[email] => bmc-admin#gmail.com
[name] => BMC Administrator
[mobile] =>
[member_name] => BMC-Admin
[member_code] => BMC0001ADMIN
[shipper_size] => Large
[fk_role_id] => 1
[fk_country_id] =>
[timezone] => Asia/Kolkata
[status] => 1
[created_at] =>
[created_by] =>
[updated_at] => 2017-07-12 04:56:31
[updated_by] =>
[deleted_at] =>
)
[1] => Array
(
[id] => 6
[drewry_user_id] => 3
[email] => bmc-analyst#gmail.com
[name] => BMC Analyst
[mobile] =>
[member_name] => BMC-Analyst
[member_code] => BMC0003ADMIN
[shipper_size] => Large
[fk_role_id] => 3
[fk_country_id] =>
[timezone] => Asia/Kolkata
[status] => 1
[created_at] =>
[created_by] =>
[updated_at] => 2017-07-26 10:55:41
[updated_by] =>
[deleted_at] =>
)
[2] => Array
(
[id] => 9
[drewry_user_id] => 2
[email] => bmc-product-manager#gmail.com
[name] => BMC Product Manager
[mobile] =>
[member_name] => BMC-Product-Manager
[member_code] => BMC0002ADMIN
[shipper_size] => Large
[fk_role_id] => 2
[fk_country_id] =>
[timezone] => Asia/Kolkata
[status] => 1
[created_at] =>
[created_by] =>
[updated_at] => 2017-07-14 09:09:10
[updated_by] =>
[deleted_at] =>
)
[3] => Array
(
[id] => 19
[drewry_user_id] => 4
[email] => bmc-customer1#gmail.com
[name] => User 1
[mobile] =>
[member_name] => User-1
[member_code] => BMC0004CUSTOMER1
[shipper_size] => Large
[fk_role_id] => 4
[fk_country_id] =>
[timezone] => Asia/Kolkata
[status] => 1
[created_at] =>
[created_by] =>
[updated_at] => 2017-07-27 11:31:20
[updated_by] =>
[deleted_at] =>
)
[4] => Array
(
[id] => 20
[drewry_user_id] => 5
[email] => bmc-customer2#gmail.com
[name] => User 2
[mobile] =>
[member_name] => User-2
[member_code] => BMC0004CUSTOMER2
[shipper_size] => Large
[fk_role_id] => 4
[fk_country_id] =>
[timezone] => Asia/Kolkata
[status] => 1
[created_at] =>
[created_by] =>
[updated_at] => 2017-07-18 06:34:08
[updated_by] =>
[deleted_at] =>
)
[5] => Array
(
[id] => 21
[drewry_user_id] => 6
[email] => bmc-customer3#gmail.com
[name] => User 3
[mobile] =>
[member_name] => User-3
[member_code] => BMC0004CUSTOMER3
[shipper_size] => Large
[fk_role_id] => 4
[fk_country_id] =>
[timezone] => Asia/Kolkata
[status] => 1
[created_at] =>
[created_by] =>
[updated_at] => 2017-07-18 06:35:25
[updated_by] =>
[deleted_at] =>
)
[6] => Array
(
[id] => 22
[drewry_user_id] => 7
[email] => bmc-customer4#gmail.com
[name] => User 4
[mobile] =>
[member_name] => User-4
[member_code] => BMC0004CUSTOMER4
[shipper_size] => Large
[fk_role_id] => 4
[fk_country_id] =>
[timezone] => Asia/Kolkata
[status] => 1
[created_at] =>
[created_by] =>
[updated_at] => 2017-07-18 06:35:54
[updated_by] =>
[deleted_at] =>
)
[7] => Array
(
[id] => 23
[drewry_user_id] => 8
[email] => bmc-customer5#gmail.com
[name] => User 5
[mobile] =>
[member_name] => User-5
[member_code] => BMC0004CUSTOMER5
[shipper_size] => Large
[fk_role_id] => 4
[fk_country_id] =>
[timezone] => Asia/Kolkata
[status] => 1
[created_at] =>
[created_by] =>
[updated_at] => 2017-07-25 15:35:46
[updated_by] =>
[deleted_at] =>
)
)
I hope it will work to you.
If you just need to get raw nested arrays of data, without using Eloquent:
$data = DB::connection()->getPdo()
->query("SELECT * FROM users")
->fetchAll(\PDO::FETCH_ASSOC);
This should be much more efficient than the current accepted answer.
toArray is a model method of Eloquent, so you need to a Eloquent model, try this:
User::all()->toArray();
http://laravel.com/docs/eloquent#collections
I need the catalog_product_entity_media_gallery table value data only on listing page.
When i am going to listing page and use the print_r($_productCollection);
$_productCollection on listing page returns me a array like this.
[_resourceName:protected] => catalog/product
[_resource:protected] =>
[_resourceCollectionName:protected] => catalog/product_collection
[_dataSaveAllowed:protected] => 1
[_isObjectNew:protected] =>
[_data:protected] => Array
(
[entity_id] => 160
[entity_type_id] => 4
[attribute_set_id] => 4
[type_id] => simple
[sku] => 104580
[has_options] => 0
[required_options] => 0
[created_at] => 2014-12-01 10:40:25
[updated_at] => 2014-12-01 11:51:15
[cat_index_position] => 1
[price] => 4.4900
[tax_class_id] => 4
[final_price] => 4.4900
[minimal_price] => 4.4900
[min_price] => 4.4900
[max_price] => 4.4900
[tier_price] =>
[name] => E Shisha E Liquid eKaiser *Menthol Flavour* 10ml Platinum Bottle Refill for Rechargeable E cigarette and E Shisha
[msrp_enabled] => 1
[msrp_display_actual_price_type] => 1
[thumbnail] => amazon_images/104580.jpg
[small_image] => amazon_images/104580.jpg
[image_label] =>
[small_image_label] =>
[thumbnail_label] =>
[url_key] => e-shisha-e-liquid-ekaiser-menthol-flavour-10ml-platinum-bottle-refill-for-rechargeable-e-cigarette-and-e-shisha
[short_description] => The eKaiser Platinum e Liquid range is made specifically for Cigarette smokers.
I need the only [small_image] value, which returns me only the amazon_images/104580.jpg
If any One have any idea, how to do it
Please help me.
Thank you
And also you can do like this :
$product = Mage::getModel('catalog/product')->load($_product->getId());
foreach ($product->getMediaGallery('images') as $image) {
...
}
You can do like this on listing page.
$product = Mage::getModel('catalog/product')->load($_product->getId());
foreach ($product->getMediaGalleryImages() as $image) {
var_dump($image->getUrl());
}
A for loop in listing with getModel will slow down your listing page considerably.
With listing page you should only use flat tables for collection.
So you need to make sure that small image is populated in flat table.
When iterating an array in Smarty I am getting results conflicting with a print_r() of the same array.
When doing a print_r() on the array I can see that there are 2 objects in the array and each object is unique. However, when I run a print_r() on each item of the array (via foreach loop) I seem to get the same results for each item.
Can anyone identify what I'm doing wrong?
See the below code examples and results.
Code:
{$fields.rgggo_spreadsheetcellmap_documents.value->beans|#print_r}
Ouput:
Array
(
[a852b076-a5cb-dda9-3868-52010d6957ab] => RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => a852b076-a5cb-dda9-3868-52010d6957ab
[name] =>
[date_entered] => 08/06/2013 09:52am
[date_modified] => 08/06/2013 02:16pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] => Test 2
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => document_type_text_c
[row] => 3
[col] => 1
.... a bunch more stuff here
)
[f038918d-a13d-69f0-3541-51fff82f0497] => RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => f038918d-a13d-69f0-3541-51fff82f0497
[name] =>
[date_entered] => 08/05/2013 02:10pm
[date_modified] => 08/06/2013 02:17pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] =>
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => description
[row] => 2
[col] => 1
.... a bunch more stuff here
)
)
When I iterate the array...
{{foreach from=$fields.rgggo_spreadsheetcellmap_documents.value->beans key=k item=v}}
<pre>
{$v|#print_r}
</pre>
{{/foreach}}
I get these results:
RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => f038918d-a13d-69f0-3541-51fff82f0497
[name] =>
[date_entered] => 08/05/2013 02:10pm
[date_modified] => 08/06/2013 02:17pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] =>
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => description
[row] => 2
[col] => 1
.... a bunch more stuff here
)
RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => f038918d-a13d-69f0-3541-51fff82f0497
[name] =>
[date_entered] => 08/05/2013 02:10pm
[date_modified] => 08/06/2013 02:17pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] =>
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => description
[row] => 2
[col] => 1
.... a bunch more stuff here
)
I found the answer in another stackoverflow question. The issue is double vs single curly brackets and their use in SugarCRM.
Is there a difference between using a single vs. double brace (delimiters) in SugarCRM Smarty tpls command construct?
I'm using an extension that switch customer groups based on some rules.
I added an attribute to customer as an EAV using this code.
$setup->addAttribute('customer', 'autoswitchgroup', array(
'type' => 'varchar',
'input' => 'select',
'label' => 'Autoswitch Group',
'global' => 1,
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'default' => 'yes',
'visible_on_front' => 1,
'source' => 'bitstream_all/entity_autoswitchgroup',
));
Looking over the extension code I see it gets the customer attribute using this code:
$customerAttributeValue = $this->_getCustomer()->getDataUsingMethod($attribute);
where _getCustomer() is defined as an Object. (#return Varien_Object).
If I take a look on the customer object I see this info:
[_resourceCollectionName:protected] => customer/customer_collection
[_cacheTag:protected] =>
[_dataSaveAllowed:protected] => 1
[_isObjectNew:protected] =>
[_data:protected] => Array
(
[entity_id] => 1
[entity_type_id] => 1
[attribute_set_id] => 0
[website_id] => 1
[email] => ****
[group_id] => 11
[increment_id] => 000000001
[store_id] => 1
[created_at] => 2011-06-04 15:11:50
[updated_at] => 2012-03-05 14:04:54
[is_active] => 1
[created_in] => Lenjerii
[prefix] =>
[firstname] => Ovidiu
[middlename] =>
[lastname] => Ungureanu
[suffix] =>
[password_hash] => ****
[taxvat] =>
[facebook_uid] => ****
[gender] => 1
[dob] =>
[autoswitchgroup] => yes
[is_subscribed] => 1
[parent_id] => 0
[dob_is_formated] => 1
[confirmation] =>
)
[_hasDataChanges:protected] => 1
[_origData:protected] => Array
(
[entity_id] => 1
[entity_type_id] => 1
[attribute_set_id] => 0
[website_id] => 1
[email] => ****
[group_id] => 11
[increment_id] => 000000001
[store_id] => 1
[created_at] => 2011-06-04 15:11:50
[updated_at] => 2012-03-05 13:49:46
[is_active] => 1
[created_in] => Lenjerii
[prefix] =>
[firstname] => Ovidiu
[middlename] =>
[lastname] => Ungureanu
[suffix] =>
[password_hash] => ****
[taxvat] =>
[facebook_uid] => ****
[gender] => 1
)
[_idFieldName:protected] => entity_id
[_isDeleted:protected] =>
In frontend I want the same info, getting it using this:
$customer = Mage::getSingleton('customer/session')->getCustomer();
Here is the result:
[_resourceCollectionName:protected] => customer/customer_collection
[_cacheTag:protected] =>
[_dataSaveAllowed:protected] => 1
[_isObjectNew:protected] =>
[_data:protected] => Array
(
[website_id] => 1
[entity_id] => 1
[entity_type_id] => 1
[attribute_set_id] => 0
[email] => ***
[group_id] => 11
[increment_id] => 000000001
[store_id] => 1
[created_at] => 2011-06-04 15:11:50
[updated_at] => 2012-03-05 13:49:46
[is_active] => 1
[created_in] => Lenjerii
[prefix] =>
[firstname] => Ovidiu
[middlename] =>
[lastname] => Ungureanu
[suffix] =>
[password_hash] => ***
[taxvat] =>
[facebook_uid] => ***
[gender] => 1
[tax_class_id] => 3
)
[_hasDataChanges:protected] => 1
[_origData:protected] => Array
(
[website_id] => 1
[entity_id] => 1
[entity_type_id] => 1
[attribute_set_id] => 0
[email] => ***
[group_id] => 11
[increment_id] => 000000001
[store_id] => 1
[created_at] => 2011-06-04 15:11:50
[updated_at] => 2012-03-05 13:49:46
[is_active] => 1
[created_in] => Lenjerii
[prefix] =>
[firstname] => Ovidiu
[middlename] =>
[lastname] => Ungureanu
[suffix] =>
[password_hash] => ****
[taxvat] =>
[facebook_uid] => ****
[gender] => 1
)
What I'm interested to get it [autoswitchgroup] - the attribute created. This one is not saved in database explicity for all users, that's why I have a default value.
Now what I don't understand is how on module I get it in customer data but on frontend I don't see it.
Even more, on module appears in [_data:protected] but not in [_origData:protected].
In both places the object is _resourceCollectionName:protected] => customer/customer_collection ...
Hopefully this is not too long to read.
I know is not an real answer but here is what I did and works.
$attribute = 'autoswitchgroup';
$customer->getDataSetDefault($attribute, 'yes');
So, I get the attribute name and using getDataSetDefault for that attribute will set a default value if there is no value.