OroCommerce Forums

Covering OroCommerce topics, including community updates and company announcements.

Forums OroCommerce Restrict selectable shopping lists (sl) in frontend's product sl-widget

This topic contains 2 replies, has 2 voices, and was last updated by  Frank 2 months ago.

  • Creator
    Topic
  • #40279

    Frank
    Participant

    # frontend
    # product-search-grid
    # in-shoppinglist-dropdown-widget

    Hi there,

    my shoppinglists have an additional property ‘owner’ (=businessUnit). I want to allow logged-in customer users to add products only to shoppinglists with the same owner
    (shoppingList.owner == product.businessOwner).

    The In-Shoppinglist-Dropdown-Widget allows to select all (!) shoppinglists, which customer user has created before:
    https://snipboard.io/BenGfy.jpg

    I want to restrict the list of selectable shoppinglists to those with the same (business)-ownership as of the product.

    I have tried to filter shoppingListsCollection in the relevant twig-template:

    Of course, this cannot work!

    TWIG does not know, what is ‘product.owner’ and what is ‘list.owner’?

    list.owner I tried to generate adding a 5th property to ‘owner’
    ProductShoppingListsDataProvider::saveShoppingListData()

    Although this shoppingList-property ‘owner’ is passed to the twig-template successfully (I can dump it), , it is not available as shoppingListsCollection-instance property in the javascript-section of the template.

    How I should pass both properties list.owner and product.owner to the template correctly?

    Thanks a lot for help
    Frank

    I know OroShoppingListBundle/Resources/public/js/app/widget/product-shopping-list-widget.js ‘feeds’ the twig template. However I do not want to modify this js, and I think it’s not neccessary at all.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #40363
    Hryhorii Hrebiniuk
    Hryhorii Hrebiniuk
    Participant

    Hello.

    It looks like shoppingListsCollection, that you have in the template, is instance of BaseCollection, which is created here
    https://github.com/oroinc/orocommerce/blob/80df308/src/Oro/Bundle/ShoppingListBundle/Resources/public/js/app/components/shoppinglist-collection-component.js#L30

    It receives data from provider
    https://github.com/oroinc/orocommerce/blob/80df308/src/Oro/Bundle/ShoppingListBundle/Resources/views/layouts/blank/page/shopping_list_collection.yml#L10

    It looks like that provider needs to be extended to pass information about shopping list’s owner into the template.

    #40378

    Frank
    Participant

    Hi there,

    thanks Hryhorii for responce, however solution was a little bit different:

    1) ShoppingList-buOwner-property:

    Investigating template
    ShoppingListBundle/Resources/views/layouts/default/imports/product_shopping_lists/..
    .. product_shopping_lists.html.twig
    I found out, that I had have to exand attributes of the JS-ShoppingListCollection (id, label, is_current) to (id, label, is_current, buOwner).
    These attributes are generated by:
    OroShoppingListBundle/Entity/ShoppingList::jsonSerialize()
    I had have to override this method.

    2) Product-buOwner-property:

    Again, investigating template
    ShoppingListBundle/Resources/views/layouts/default/imports/product_shopping_lists/..
    .. product_shopping_lists.html.twig
    I found out, that productShoppingLists which are used by this template are provided by:
    OroShoppingListBundle/DataProvider/ProductShoppingListsDataProvider::
    saveShoppingListData().
    I had have to override this Provider, and add to twig-template a simple if-clause to filter select-options-shoppingLists in the way described above.

    And, it works.

    Thanks for recommandations
    Frank

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

You will be redirected to [title]. Would you like to continue?

Yes No