Extending query from spryker/vendor to pyz
Hi Team,
I am trying to add an extra column in the spyOmsOrderItemStateHistory
table while changing the state from the backoffice. I discovered that entries for this history table are internally generated from the spySalesOrderItem
. The issue seems to stem from a call generated by ORM, specifically invoking the method located at:vendor/spryker/sales/src/Spryker/Zed/Sales/Persistence/Propel/AbstractSpySalesOrderItem.php::postSave
.
For testing, I successfully set and retrieved the new value. However, when I try to extend this functionality into the Pyz
namespace, it continues to reference the vendor path instead. Is there a solution for ensuring my extended code is executed rather than the vendor path?
Answers
-
Did you update the DTO to mirror this new column?
what part did you override from the core?
Take a look at the replacement rules if that can help:
https://docs.spryker.com/docs/dg/dev/backend-development/extend-spryker/spryker-os-module-customisation/extend-the-spryker-core-functionality.html#folder-organization0 -
Hi Hidran,
Thanks for your response. I'm familiar with the DTO update process, but my case is slightly different. Here's an example of how the functionality is used:
public function postSave(?ConnectionInterface $con = null): void
{
if ($this->statusChanged){
/** @var \Orm\Zed\Sales\Persistence\SpySalesOrderItem $salesOrderItemEntity */
$salesOrderItemEntity = $this;// Creating history entry
$omsOrderItemStateHistoryEntity = $this->createOmsOrderItemStateHistoryEntity();
$omsOrderItemStateHistoryEntity->setOrderItem($salesOrderItemEntity);
$omsOrderItemStateHistoryEntity->setState($this->getState());
// Custom additions for user tracking (currently commented)
// $omsOrderItemStateHistoryEntity->setFkUserId($salesOrderItemEntity->getFkUserId());
// $omsOrderItemStateHistoryEntity->setUsername($this->getSpyUser()->getUsername());
$omsOrderItemStateHistoryEntity->save();
}
$this->statusChanged = false;
}
In my scenario, the challenge is extending this core functionality where postSave() is automatically invoked. Even after extending the class into Pyz, it's still referencing the vendor file. Would appreciate any advice on how to properly redirect this behavior to my custom logic.0 -
That class is generated by Propel and you can extend the abstract class.
To use use your class, you would have to extend the SalesPersistenceFactory class and project level and override the method which provides the SpySalesOrderItemQuery with your extended class.For SpySalesOrderItem, you already have the class which extends from the Abstract core class
Those classes are already found in src/Orm/Zed/Sales:
/** * Skeleton subclass for representing a row from the 'spy_sales_order_item' table. * * * * You should add additional methods to this class to meet the * application requirements. This class will only be generated as * long as it does not already exist in the output directory. */class SpySalesOrderItem extends BaseSpySalesOrderItem{}
So, if you override the postSave method in this class, it would be used in place of the core Abstract postSave
0 -
Hi Hidran,
Thanks for the insights! I’m trying to understand how to implement this in my scenario. Specifically, how do I override the
createSalesOrderItemQuery
function in my project to make it return my extended class?Currently, the function looks like this:
/**
* @return \Orm\Zed\Sales\Persistence\SpySalesOrderItemQuery
*/
public function createSalesOrderItemQuery()
{
return SpySalesOrderItemQuery::create();
}The challenge is that this method is in
Spryker\Zed\Sales\Persistence\Propel\AbstractSpySalesOrderItem
and it extends\Orm\Zed\Sales\Persistence\Base\SpySalesOrderItem
. I need guidance on how to override this method to return my custom class. Could you elaborate on this or give an example of how to structure the return so that it references my project-level class?Thanks!
0 -
Hi,
What I posted for SpySalesOrderItem, is valid also for SpySalesOrderItemQuery
Spryker uses the one that gets publish into ORM/Zed when propel:install in executed
0
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