Filter products based on a foreign entity

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Milko
    Junior Member
    • Jul 2016
    • 6

    Filter products based on a foreign entity

    Hello, I wondered, what were the exact steps to get to prefilter the products when filling out a sales order based on the brand value.
  • Tigershroff
    Junior Member
    • Sep 2019
    • 1

    #2
    Can you ex-plane prefilter the products.

    Comment


    • Milko
      Milko commented
      Editing a comment
      Yes, for example:
      Into the sales order, I add a field called "vendor".
      Now, I need to filter the product by $vendor (brand), when I open the list to add the items into the Sales Order.
  • Maximus
    Senior Member
    • Nov 2018
    • 2731

    #3
    Hi,
    You can save own filter condition according to each brand value and use it upo selecting products in sales order. For example to create your own brand filter go to Products list view, configure a filter condition and press All -> Save filter (see attachments).
    Attached Files

    Comment


    • Milko
      Milko commented
      Editing a comment
      Thank you, but that solution only works with my user, if I want something wide to the organization?
  • Maximus
    Senior Member
    • Nov 2018
    • 2731

    #4
    Well, the easiest way is:
    1. In the Product entity create 'Varchar' field type and call it for example like 'hiddenBrandName'.
    2. Add Formula for the Product entity:
    Code:
    hiddenBrandName = brandName
    3. Recalculate formula for all Products.
    4. Create Product.php in espocrm/custom/Espo/Custom/SelectManagers
    Add this code into it:
    PHP Code:
    <?php

    namespace Espo\Custom\SelectManagers;

    class 
    Product extends \Espo\Modules\Sales\SelectManagers\Product
    {
        protected function 
    filterPhoenixolutions(&$result)
        {
            
    $result['whereClause'][] = array(
                
    'hiddenBrandName' => 'Phoenixolutions'
            
    );
        }
     }
    5. Create Product.json in espocrm/custom/Espo/Custom/Resources/metadata/clientDefs
    Configure the "filterList" parameter:
    Code:
    {
        "filterList": [
            "__APPEND__",
            {
                "name": "phoenixolutions"
            }
        ]
    }
    6. Cleare cache.


    You can also fetching brand by its id. In this way you do not need to create one more field and use Formula.
    Last edited by Maximus; 09-12-2019, 10:19 AM.

    Comment


    • Milko
      Milko commented
      Editing a comment
      Thank you!
  • yuri
    Member
    • Mar 2014
    • 8777

    #5
    You can also utilize Report Filter (if you have advanced pack). It allows adding filters to all users or users from specific team.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment


    • Milko
      Milko commented
      Editing a comment
      Yes, I have the advanced pack, there is a way to use a variable instead of a fixed value into the report filter?
Working...