Questions tagged [collection]

Questions related to Magento collections

Filter by
Sorted by
Tagged with
1
vote
1answer
4k views

getting the subTotal of the cart

I am trying to get the subtotal that is in the cart. To do this I am calling Mage::getBlockSingleton('checkout/cart_totals') this appears to be returning a collection. I need to get a single value ...
2
votes
1answer
732 views

Magento get payment date in a custom report grid [closed]

I want to add "the date that customer paid the bill" to a report grid for "sales_flat_order_item" table. For getting result,I have to join two tables "sales_flat_order_status_history" and "...
7
votes
1answer
44k views

Custom Sort Order For Collection

I need to sort a collection based on "sort_order" field instead of "id" as shown in the image. $collection=Mage::getResourceModel('banners/manage_collection'); $collection->getSelect()->order('...
2
votes
1answer
855 views

How do I get my Collection to use a different DB connection?

So I have extended a Magento collection to obtain my own collection only I want to use a different DB connection. What I have attempted to do is define the connection in config.xml like so: <...
1
vote
1answer
18k views

What is causing SQLSTATE[42000]: Syntax error or access violation: 1064 when trying to Group Tables?

I have been trying to figure out what is causing the exception when attempting to create a join for my Collections and group them with the main_table. Here is the code from my Collection.php <?...
16
votes
3answers
27k views

Filtering results using LIKE

Consider these three "haystack" strings: a) foo bar b) welcome to foo bar industries c) foo barer And now my "needle": foo bar (Heh) I would like my filter to match my needle with haystack ...
5
votes
4answers
6k views

Fetch value from collection without foreach loop

I have a custom collection $someCollection = Mage::getModel('mymodule/mymodel')->getCollection() ->addFieldToSelect('some_field') ->...
0
votes
1answer
2k views

How far is transaction save effective?

I have a requirement where I need to save multiple rows to a custom table at once. so used CASE 1: foreach($dataCollection as $data){ $customModel->setData($data) ->...
0
votes
1answer
160 views

Collection rewrite unexpected behavior

As far as I know (/knew), the following 2 snippets were pretty much equivalent: $collection = Mage::getResourceModel("reports/product_collection") and $collection = Mage::getModel("reports/...
1
vote
1answer
150 views

Use of a 'where' clause on a calculated field value

I have a query for calculating the minimal price. The select statement part is: IF(at_price_index.tier_price IS NOT NULL, LEAST(at_price_index.min_price, at_price_index.tier_price), at_price_index....
5
votes
1answer
1k views

Using observer, how to get the current pager with loaded product collection

Using an observer how can i get the current pager block with its loaded product collection on a category page? I want to check the total number of pages on a category page before it is loaded.
6
votes
2answers
1k views

Filter Product Collection By Another Attribute In Product Collection eg 'attribX', array('gt' => 'attrib-Y')

When using product collections like so: $_productCollection= Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('*') ->...
27
votes
2answers
69k views

Left join a table on a collection query

I am doing the following to get some orders out of the system for export: $orders = Mage::getModel('sales/order')->getCollection() ->addFieldToFilter('status', $statusToExport) ->...
2
votes
0answers
245 views

Search multiple attribute by label not by value and use like condition [closed]

I have a problem, i have 2 attributes both are multiselect. When i apply search one of them is text box, now how search query would frame because it would on the basis of label not value. Please help
11
votes
4answers
22k views

Best practice to join product attributes

I have a custom table with a product reference product_id. Now I would like to show product information (sku, name) in my backend grid, but I am unsure what is the best practice to do this? My best ...
0
votes
1answer
2k views

Query to get all simple products which are not part of a complex product

Exactly as the title suggests, how can i find all simple products in the system that are not part of complex products such as configurable? I dont mind if this is done directly in the db or through ...
0
votes
1answer
5k views

Modify tax rate programmatically based on products without save in database

I need to apply different rates based on a custom attribute of product. I created an observer to change the rate before the cart (sales_quote_collect_totals_before). Everything works fine but when I ...
7
votes
1answer
1k views

Product loop giving incorrect images

I am looping through products and getting an error with product images. The code I am working with is below: <?php $collection = Mage::getModel('catalog/product')->getCollection(); ...
12
votes
1answer
18k views

How to specify custom sort order for product collection?

I am trying to create a product collection based on array of products ids, and also sort the collection based on the ids array. $productIds = array(318,310,311); $collection = Mage::getModel('catalog/...
3
votes
3answers
10k views

Product image url as part of collection load

Is it possible to have the product image url loaded as part of the product collection? for examples: Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*'); This doesnt ...
0
votes
1answer
2k views

Limit Collection Size to N-number

After several research attempts, I still couldn't manage to limit category page to N-number of products to be shown. I need to limit a specific category page to let's say 180 products only, with ...
2
votes
1answer
578 views

how to get all products from a category which have this attribute?

I have spent two days in this problem: I can´t find the right solution for getting all products which are related to a specified category and which have the searched attribute. In my special case: We ...
-1
votes
1answer
719 views

$this->getProductCollection() returns only 15 items

I am using the following code for getting products in the beforeToHtml() function of a block, but when I get the products in the template file using $this->getProductCollection() it returns only 15 ...
-1
votes
3answers
4k views

Change default category sort order by “in stock” [duplicate]

I'm trying to change the way my default "Best Value" view works for a category (both list/grid views) so that items which are "in stock" appear first and then out of stock items last. I have ...
4
votes
1answer
2k views

Manual eav join best way?

If i have a product collection in a multi store environment and i wish to also retrieve a specific attributes value from another store with my collection result, how is the best way to do this? For ...
2
votes
1answer
387 views

Search result display

I am trying to display the search result sorted by attribute_set_id. I want to display them with the title as the name of the first attribute_set and then all the products that belong to ...
2
votes
2answers
14k views

How can I write this sql query following the Magento Way?

How can I write this unsecure, ugly, query following the Magento way without using collection? select (select sum(points) FROM ".$this->getTable('mymodule/registry')." where points < 0 and ...
37
votes
3answers
28k views

Most efficient way to get all ID's from a collection

In the past to get all ID's of a product collection, I have always used getAllIds on the collection, believing this was a method that prevented the full collection load with data etc. But, I actually ...
9
votes
1answer
24k views

How to list all users

As part of an exercise I am trying to list all users email from my database on one page. So far the closest i've got is $user = mage::getModel('customer/customer')->getCollection()->getData(); ...
4
votes
1answer
2k views

How to set filter_index for a column which is not in the database table?

My code is as follows. Everything works fine except the filteration of new column which shows abandoned cart item names comma separately. I have overridden the block ...
2
votes
2answers
2k views

Toolbar not displaying with overridden Mage_Catalog_Block_Product_List

I am banging my head against the wall on the following problem: To get a product list that is sorted by the subcategory string, an product attribute and finally by the product name I have overridden ...
44
votes
5answers
111k views

How to get all items in cart currently?

I want to get a collection of all the items in cart currently. How can I do this ? Any suggestions will be appreciated.
0
votes
2answers
7k views

How to get product collection of given main category id?

In my website I have several stores available. One particular store contains both the simple and configurable products. This is a huge collection of products. What is the fastest way to get all ...
3
votes
4answers
16k views

fatal error: Call to a member function getCollection() on a non-object in magento

I am trying to get a collection of objects of a table of our database. Unfortunately the following code was leading to an error. my code is <?php class Ics_EasyLife_Block_Template extends ...
0
votes
1answer
314 views

How to add an object to a collection?

I can get customer address collection for each customer in front-end checkout process. What I need is I want to add a default address for all the customers in the collection. So in the onepage ...
0
votes
1answer
353 views

Collection loads wrong data?

I'm using Magento CE 1.7. I want to add the customer telephone number to the Abandoned Cart grid (Reports->Shopping Carts->Abandoned Carts). I have overridden the block ...
9
votes
5answers
15k views

How to log SQL query of the collection?

I want to log the SQL query for a custom collection. I tried the following code. But did not work. Any suggestions will be appreciated. Mage::log($collection->getSelect(),null,'test.log',true);
18
votes
2answers
72k views

How to get attribute “option label/attribute text” having “attribute value” (option_id)?

Suppose I have an attribute that is a collection of option (dropdown/multiselect). I can retrieve the attribute value for a given product: $store_id = [something]; $productId = [something]; // this ...
3
votes
3answers
2k views

Observer for Admin Order Grid

I would like to restrict order based on an Admin user. So for example the admin user would have an attribute that is assigned to a certain region (Group of Zipcodes). When the user logs in they could ...
2
votes
3answers
1k views

Ordering a catalog/product collection by sales data

I have a 'catalog/product' collection which is being filtered by product attributes, but I need to order this collection so that the most popular (sales OR views) come first. Is there a way to do ...
4
votes
3answers
3k views

Apply an extra filter in view

I am trying to add additional filters to a collection after the collection seems to of been generated. In catalogue product list.phtml there is the following line of code: $_productCollection = $this-...
0
votes
2answers
1k views

Data added to Collection with a Join is not showing up?

require_once('../app/Mage.php'); Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); $collection = Mage::getModel('sales/order')->getCollection() ->...
3
votes
1answer
4k views

Conditional join in magento collection

I am working in magento and now i face problem in getting my info.I created collection to fetch data , but now i want to check some value if exist i want to add new inner join to that collection.I try ...
3
votes
3answers
28k views

Filter product collection by custom attribute

I'm filtering a product collection by the custom attribute ean with the following code $collection = Mage::getModel('catalog/product')->getCollection(); $collection->addAttributeToSelect('name')...
2
votes
3answers
5k views

How do you deal with 61 tables join limit when building magento collection?

Mysql has known limitation of 61 tables to join, how do you overcome that when you have more than 61 attributes to join in magento collection?
2
votes
4answers
3k views

Add invoice status to order grid

We try to add the invoice status column to the sales order grid. We added the code beneath to the prepareCollection function: $collection->getSelect()->join('sales_flat_invoice', 'main_table....
1
vote
2answers
6k views

Trying to filter by 'In Stock' or 'Out of Stock' on product admin grid

I have successfully been able to get whether a product is 'In Stock' or 'Out of Stock' in the Magento admin product grid using an observer in the way set out below. However when I try to filter by 'In ...