Use Data Exchange Api to create a product - page_search entries missing
Hello,
I'm currently trying to import products via the Data Exchange Api. I'm using this list of requests to create the product abstract and the one concrete:
- POST /dynamic-entity/product-abstracts
- POST /dynamic-entity/products
- POST /dynamic-entity/product-abstract-localized-attributes
- POST /dynamic-entity/product-localized-attributes
- POST /dynamic-entity/product-abstract-stores
- POST /dynamic-entity/product-categories
- POST /dynamic-entity/availability-abstracts
- POST /dynamic-entity/availabilities
- POST /dynamic-entity/stock-products
- POST /dynamic-entity/product-searches
- POST /dynamic-entity/price-products
- POST /dynamic-entity/price-product-stores
- POST /dynamic-entity/price-product-defaults
When I have a look at the data in the backoffice everything seems to be ok. However the product is not displayed in the storefront because the entries in the tables spy_product_abstract_page_search and spy_product_concrete_page_search are missing.
If I trigger a 'console publish:trigger-events' or save the product in the backoffice again the entires are there.
Has anybody encountered something similiar? Are there any events that are missing when using the Data Exchange Api or does the order of the requests matter?
Answers
-
Good morning @LukasB!
Just as a sanity check, did you tryconsole sync:data?
Also, are queues empty in rabbit? (no exceptions in the search queues?)
Are the products marked as searchable?1 -
Good morning @victor.vanherpt!
Thanks for your answer. Yes I also tried
console sync:data
but that doesn't yield any result.I also got no entries in any queues/ error queues in RabbitMQ.
And yes, the concrete product is marked as searchable.
0 -
ah, it was worth checking the low hanging fruit :)
Good luck, I would be interested to see some comment if you find a solution1 -
In 5+ horrible years of product import I can say for sure: No trigger no P&S 😂
You can implement a check on spy_product to see which product was updated and then get concrete/abstract id in order to run trigger-events with -r product-concrete/product-abstract and —ids/i.
Best one is
vendor/bin/console publish:trigger-events -r product_configuration,product_abstract_category,url,product_concrete,product_abstract,availability
REALLY, don´t try to work around, it will always have a sideeffect which will get you nuts 🤣
1 -
Thanks @Fred Jung! I was hoping not to run any
publish:trigger-events
commands because the events are fired already when the table is filled within the data exchange api request1 -
Hi @LukasB & @victor.vanherpt 😀
As discussed we ran into a similar situation when and we found inside the documentation a possible workaround worth sharing here
In the Data Exchange setup documentation with category management two methods are presented \Pyz\Zed\DynamicEntity\DynamicEntityDependencyProvider::getDynamicEntityPostUpdatePlugins and \Pyz\Zed\DynamicEntity\DynamicEntityDependencyProvider::getDynamicEntityPostCreatePlugins
Plugins implementing the DynamicEntityPostCreatePluginInterface that are returned by those arrays are executed after the data is stored in the database.
This has allowed us to make a working prototype to publish the specific product(s) with the code below:
<?php namespace Pyz\Zed\DynamicEntityExtension\Dependency\Plugin; use Generated\Shared\Transfer\DynamicEntityPostEditRequestTransfer; use Generated\Shared\Transfer\DynamicEntityPostEditResponseTransfer; use Spryker\Zed\DynamicEntityExtension\Dependency\Plugin\DynamicEntityPostUpdatePluginInterface; use Spryker\Zed\Kernel\Communication\AbstractPlugin; /** * @method \Pyz\Zed\DynamicEntityExtension\Communication\DynamicEntityExtensionCommunicationFactory getFactory() */ class ProductPostUpdatePlugin extends AbstractPlugin implements DynamicEntityPostUpdatePluginInterface { protected const FIELD_ID_PRODUCT = 'id_product'; public function postUpdate(DynamicEntityPostEditRequestTransfer $dynamicEntityPostEditRequestTransfer): DynamicEntityPostEditResponseTransfer { $productPageSearchFacade = $this->getFactory()->getProductPageSearchFacade(); $products = $dynamicEntityPostEditRequestTransfer->getRawDynamicEntities(); $productConcreteIds = []; foreach ($products as $product) { $productConcreteIds[] = $product->getFields()[static::FIELD_ID_PRODUCT]; } $productPageSearchFacade->publishProductConcretes($productConcreteIds); return new DynamicEntityPostEditResponseTransfer(); } }
<?php namespace Pyz\Zed\DynamicEntity; use Pyz\Zed\DynamicEntityExtension\Dependency\Plugin\ProductPostUpdatePlugin; use Spryker\Zed\DynamicEntity\DynamicEntityDependencyProvider as SprykerDynamicEntityDependencyProvider; class DynamicEntityDependencyProvider extends SprykerDynamicEntityDependencyProvider { /** * @return list<\Spryker\Zed\DynamicEntityExtension\Dependency\Plugin\DynamicEntityPostUpdatePluginInterface> */ protected function getDynamicEntityPostUpdatePlugins(): array { return [ new ProductPostUpdatePlugin(), ]; } }
I personally haven't been able to find any Spryker OOTB implementation for such a trigger in the product abstract/concrete entities. Only for category management (and if my memory doesn't fail also for stock but cannot seem to find it now) as can be found in the code where the "inspiration" for the code above came from:
3 -
Great @jose.isasa thanks a lot for sharing this 😊
1
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 75 Spryker News
- 919 Developer Corner
- 779 Spryker Development
- 89 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 34 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 25 Job Opportunities
- 3.2K 📜 Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 69 Spryker Safari Questions
- 50 Random