What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

how to get data about product from database in controller ?

USLUHK9SQ
USLUHK9SQ Posts: 92 πŸ§‘πŸ»β€πŸš€ - Cadet

how to get data about product from database in controller ?

Β«1

Comments

  • Alberto Reyer
    Alberto Reyer Lead Spryker Solution Architect / Technical Director Posts: 690 πŸͺ - Explorer

    Depends, if you want a list of products in Zed, have a look at Tables and Query Containers.
    If you wont to show some fields in Zed, have a look at the ProductFacade::getProductConcrete or ProductFacade::getProductAbstract.

    If you try to show a product field in the Frontend (Yves/Glue), https://documentation.spryker.com/docs/tutorial-architecture-walkthrough-scos will be a good place to start

  • USLUHK9SQ
    USLUHK9SQ Posts: 92 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited January 2020

    i want to get all data about product by id or sku in Zed

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    Product concrete or Product abstract?

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    You can have at ProductFacadeInterface.

  • USLUHK9SQ
    USLUHK9SQ Posts: 92 πŸ§‘πŸ»β€πŸš€ - Cadet

    Product abstract

  • USLUHK9SQ
    USLUHK9SQ Posts: 92 πŸ§‘πŸ»β€πŸš€ - Cadet

    @UKHD8KTMF so how i can use ProductFacadeInterface in controller ?

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    I need some context to be able to help you. Are you doing a page in Zed? Trying to show some data on frontend? Please explain your use case.

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    Did you do developer bootcamp already https://training.spryker.com/courses/developer-bootcamp. It is free.

  • USLUHK9SQ
    USLUHK9SQ Posts: 92 πŸ§‘πŸ»β€πŸš€ - Cadet

    so when i create or update product i must send all data about it to other api i create custom module to catch this (Listener) but i not have data about product

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    Did you do something like described here https://documentation.spryker.com/docs/event-listen

  • USLUHK9SQ
    USLUHK9SQ Posts: 92 πŸ§‘πŸ»β€πŸš€ - Cadet

    yes

  • USLUHK9SQ
    USLUHK9SQ Posts: 92 πŸ§‘πŸ»β€πŸš€ - Cadet

    public function handle(TransferInterface $eventTransfers, $eventName)
    {
    $data = array(
    'eventName' => $eventName,
    'data' => $_POST,
    );
    $this->sender->sendDataToApi($data);
    }

  • USLUHK9SQ
    USLUHK9SQ Posts: 92 πŸ§‘πŸ»β€πŸš€ - Cadet

    $_POST - are data from form

  • USLUHK9SQ
    USLUHK9SQ Posts: 92 πŸ§‘πŸ»β€πŸš€ - Cadet

    and $eventTransfers is empty

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    This looks wrong to me, because the event transfer should contain the data. How did POST data came to event listener? What are you listening for?

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    If I understand correctly, what you want is to call some external API when user creates a product in ZED.

  • USLUHK9SQ
    USLUHK9SQ Posts: 92 πŸ§‘πŸ»β€πŸš€ - Cadet

    yes exactly

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    You can use some of existing events - check ProductEvents

  • USLUHK9SQ
    USLUHK9SQ Posts: 92 πŸ§‘πŸ»β€πŸš€ - Cadet

    in my subscriber function

    private function createProductListener(EventCollectionInterface $eventCollection) {
            $eventCollection->addListener(ProductEvents::PRODUCT_ABSTRACT_AFTER_CREATE, new KacperListener());
            return $eventCollection;
        }
    
  • USLUHK9SQ
    USLUHK9SQ Posts: 92 πŸ§‘πŸ»β€πŸš€ - Cadet

    and its go to my Listener and eventTransfer is empty

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    hmm, should not be $this->triggerEvent(ProductEvents::PRODUCT_ABSTRACT_AFTER_CREATE, $productAbstractTransfer);

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    you should have product abstract transfer - are you creating abstract product? maybe you are creating concrete product, but if event is triggered then I guess it is a correct one

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    You can put a breakpoint in ProductAbstractManager and debug if data is set

  • USLUHK9SQ
    USLUHK9SQ Posts: 92 πŸ§‘πŸ»β€πŸš€ - Cadet

    its my subscriber

  • USLUHK9SQ
    USLUHK9SQ Posts: 92 πŸ§‘πŸ»β€πŸš€ - Cadet

    could you change method and show me how to correctly ? I spent many hours on this

  • USLUHK9SQ
    USLUHK9SQ Posts: 92 πŸ§‘πŸ»β€πŸš€ - Cadet

    and docs is not clear for me

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    can you share also KacperListener ?

  • USLUHK9SQ
    USLUHK9SQ Posts: 92 πŸ§‘πŸ»β€πŸš€ - Cadet

    okey

  • USLUHK9SQ
    USLUHK9SQ Posts: 92 πŸ§‘πŸ»β€πŸš€ - Cadet

    kacperListener

  • Ehsan Zanjani
    Ehsan Zanjani Head of Solution Architecture @ Spryker Posts: 113 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited January 2020

    Hi @USLUHK9SQ
    For having the product data in fronted stores, (Yves and Glue), we are using Publish and Synchronize (P&S) feature, this acts as CQRS method.
    long story short, we trigger events which contain the listener and some meta data information for publishing into database, then we aggregate and denormilize data and provide it via queue to Redis and ES.
    here you can find a simple HowTo tutorial
    https://documentation.spryker.com/docs/handling-data-publish-and-synchronization