1 Comment

Magento2 Order by clause in collection

How to add product in order programmatically using price per customer group?
Magento 2 - enable cash on delivery only for specific shipment method

I have a custom collection to which I add filters. For example, I have this:

$giftColletion = $this->_giftFactory->getCollection();
$giftColletion->addFieldToFilter('store_id', 1);

What filter should I add to $giftColletion so it can return all the records by field position in ASC order ?

Related Posts

  • Magento order omni search: search all records for ordernumber or name (0)
    Would it be possible to create an omni search field for the order grid? Sometimes one wants to search ALL records for instance when a customer calls. Would be great if we had some kind of omni search that searches all known records (for example when a customer calls and mentions […]
  • filter categories by custom attribute (1)
    i created a module that adds a custom attribute to categories i want the defualt behavior when i call the category collection with Mage:getModel('catalog/category') to only return categories that have a specific value set for that custom attribute, how would I do this?
  • Understanding setSelect()->join Need to join two custom collections (1)
    I am confused understanding the correct usage of $collection->getSelect()->join(... to bring two custom model resources together. I tried following other examples using the getSelect method. I also attempted to join the tables in the collection class _afterLoad() method. I'm […]
  • Magento2: Filter ProductCollection by Product Type (type_id) (1)
    I have the following in my custom module helper: public function __construct( MagentoFrameworkAppHelperContext $context, MagentoCatalogModelResourceModelProductCollection $productCollection, array $data = [] ) { $this->_productCollection = $productCollection; […]
  • “random” order clause added to my collection (1)
    For a module I load a custom product collection where I select products based on IDs in an array, I also try and sort the collection by the same order as the IDs have in the array(). To achieve the sorting I use Zend's getSelect->order() to add a custom "ORDER BY" to the SQL […]
  • How to customize admin sales order grid collection? (0)
    I have to add a custom where clause to the query that retrieve data to fill sales order in the relative admin grid. I know that it is defined here vendormagentomodule-salesetcdi.xml as virtualType <virtualType name="MagentoSalesModelResourceModelOrderGridCollection" […]
  • Add custom column to customer admin grid (2)
    In my module I have custom db table that connected with magento customers by customer_id field. What I need is to add field value from this table to customer admin grid. How can I add join with my table and add my column value to customer grid collection, so it looks like other […]
  • How to add filtering to custom table field column in Customers admin grid in Magento2? (0)
    Added custom columns from custom table to Customers grid using JOIN in the following method: MagentoFrameworkModelResourceModelDbCollectionAbstractCollection::_beforeLoad: protected function _beforeLoad() { ... […]
  • Filter Magento collection with nested “OR” “AND” filter (2)
    I am trying to determine how to filter a Magento collection from a flat table that would produce a WHERE clause with an AND that is followed by expression with a nested OR, which has nested ANDs, such as: SELECT * FROM `my_model_flat_table` WHERE (`customer_id` = 123456) AND ( […]
  • how to join fields like product skus in sales order grid collection in magento2? (0)
    I want to join product skus and order comments and order product custom option in sales order grid collection. I have aleady added columns in ui component but values is not rendered because of collection does not have this values. I have tried with column renderer is working but […]
How to add product in order programmatically using price per customer group?
Magento 2 - enable cash on delivery only for specific shipment method

1 Comment on this article

  • User November 12, 2016

    You can try this

    $giftColletion = $this->_giftFactory->getCollection();
    $giftColletion->addFieldToFilter('store_id', 1);

    setOrder is use for sorting


Add a comment

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax