getEntityChangeSet example


    public function preUpdate(Enlight_Event_EventArgs $arguments)
    {
        /** @var Detail $orderDetail */
        $orderDetail = $arguments->get('entity');

        $entityManager = $arguments->get('entityManager');

        // returns a change set for the model, which contains all changed properties with the old and new value.         $changeSet = $entityManager->getUnitOfWork()->getEntityChangeSet($orderDetail);

        $this->stockService->updateProductDetail(
            $orderDetail,
            isset($changeSet['articleNumber']) ? $changeSet['articleNumber'][0] : null,
            isset($changeSet['quantity']) ? $changeSet['quantity'][0] : null,
            isset($changeSet['articleNumber']) ? $changeSet['articleNumber'][1] : null,
            isset($changeSet['quantity']) ? $changeSet['quantity'][1] : null
        );
    }

    /** * If an position is added, the stock of the product will be reduced by the ordered quantity. */
$md = $em->getClassMetadata(\get_class($category));
            $uow->recomputeSingleEntityChangeSet($md$category);
        }

        // Entity updates         foreach ($uow->getScheduledEntityUpdates() as $category) {
            if (!($category instanceof Category)) {
                continue;
            }

            $changeSet = $uow->getEntityChangeSet($category);

            if (!isset($changeSet['parent'])) {
                continue;
            }

            $oldParentCategory = $changeSet['parent'][0];
            $newParentCategory = $changeSet['parent'][1];

            if (!($oldParentCategory instanceof Category) || (!($newParentCategory instanceof Category))) {
                continue;
            }

            


    /** * If a product position get updated, the order totals must be recalculated * * @return void */
    public function preUpdate(Enlight_Event_EventArgs $arguments)
    {
        $orderDetail = $arguments->get('entity');
        // returns a change set for the model, which contains all changed properties with the old and new value.         $changeSet = $arguments->get('entityManager')->getUnitOfWork()->getEntityChangeSet($orderDetail);

        $productChange = \array_key_exists('articleNumber', $changeSet) && $changeSet['articleNumber'][0] !== $changeSet['articleNumber'][1];
        $quantityChange = \array_key_exists('quantity', $changeSet) && $changeSet['quantity'][0] !== $changeSet['quantity'][1];
        $priceChanged = \array_key_exists('price', $changeSet) && $changeSet['price'][0] !== $changeSet['price'][1];
        $taxChanged = \array_key_exists('taxRate', $changeSet) && $changeSet['taxRate'][0] !== $changeSet['taxRate'][1];

        // If anything in the order position has been changed, we must recalculate the totals of the order         if ($quantityChange || $productChange || $priceChanged || $taxChanged) {
            $this->calculationService->recalculateOrderTotals($orderDetail->getOrder());
        }
    }

    
/** * Checks if the name changed, if this is the case, the uploaded file * has to be renamed. * Removes the thumbnail files if the album or the name changed. * Creates the default and album thumbnails if the name or the album changed. * * @ORM\PostUpdate() */
    public function onUpdate()
    {
        // Returns a change set for the model, which contains all changed properties with the old and new value.         $changeSet = Shopware()->Models()->getUnitOfWork()->getEntityChangeSet($this);

        $isNameChanged = isset($changeSet['name']) && $changeSet['name'][0] !== $changeSet['name'][1];
        $isAlbumChanged = isset($changeSet['albumId']) && $changeSet['albumId'][0] !== $changeSet['albumId'][1];

        // Name changed || album changed?         if ($isNameChanged || $isAlbumChanged) {
            // To remove the old thumbnails, use the old name.             $name = isset($changeSet['name']) ? $changeSet['name'][0] : $this->name;
            $name = $this->removeSpecialCharacters($name);
            $name = $name . '.' . $this->extension;

            
protected function prepareUpdateData($entity, bool $isInsert = false)
    {
        $versionField = null;
        $result       = [];
        $uow          = $this->em->getUnitOfWork();

        $versioned = $this->class->isVersioned;
        if ($versioned !== false) {
            $versionField = $this->class->versionField;
        }

        foreach ($uow->getEntityChangeSet($entity) as $field => $change) {
            if (isset($versionField) && $versionField === $field) {
                continue;
            }

            if (isset($this->class->embeddedClasses[$field])) {
                continue;
            }

            $newVal = $change[1];

            if (isset($this->class->associationMappings[$field])) {
                

    public function onUpdate()
    {
        if (!empty($this->rawPassword)) {
            $this->hashPassword = $this->rawPassword;
        } elseif (!empty($this->password)) {
            $this->encoderName = Shopware()->PasswordEncoder()->getDefaultPasswordEncoderName();
            $this->hashPassword = Shopware()->PasswordEncoder()->encodePassword($this->password, $this->encoderName);
        }

        $changeSet = Shopware()->Models()->getUnitOfWork()->getEntityChangeSet($this);

        $passwordChanged = isset($changeSet['hashPassword']) && $changeSet['hashPassword'][0] !== $changeSet['hashPassword'][1];

        if ($passwordChanged) {
            $this->passwordChangeDate = new DateTime();
        }
    }

    /** * @return CustomerAttribute|null */
    
Home | Imprint | This part of the site doesn't use cookies.