Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Careful enabling order sof-deleting #109

Closed
cnoa23 opened this issue May 27, 2013 · 2 comments
Closed

Careful enabling order sof-deleting #109

cnoa23 opened this issue May 27, 2013 · 2 comments
Labels
Potential Bug Potential bugs or bugfixes, that needs to be reproduced.

Comments

@cnoa23
Copy link

cnoa23 commented May 27, 2013

Hi, following good practice from contributors i enabled sof-deleting for order entity. Now when i add a new order "Place Order" it fail because constrain in data base.
Order has field order_number and it is unique, it is generated by OrderNumberGenerator in SalesBundle/Generator.

While it generate the number it call getLastOrderNumber that use findBy and is enable sof-deleting so it generate existing order number.

To solve this in Order Repository on CoreBundle y create method to return last order but now softdeleting is disable, and change on classs OrderNumberGenerator method getLastOrderNumber to use my new method.

I hope this help you, and please suggest other solution more elegant.
Thanks
Carlos.

//Sylius\Bundle\SalesBundle\Generator
 protected function getLastOrderNumber()
    {
       // $lastOrder = current($this->repository->findBy(array(), array('createdAt' => 'desc'), 1));
       $lastOrder = current($this->repository->findLast(1));

        if (!$lastOrder) {
            return str_repeat('0', $this->numberLength);
        }

        return $lastOrder->getNumber();
    }
//namespace Sylius\Bundle\CoreBundle\Repository;
    public function findLast($limit = 1)
    {       
        $em = $this->getEntityManager();
        $filter = $em->getFilters()->disable('softdeleteable');
        $filter->disableForEntity('SyliusCoreBundle\Order');
        $lastOrder = $this->findBy(array(), array('createdAt' => 'desc'), $limit);
        $filter->enableForEntity('SyliusCoreBundle\Order');

        return $lastOrder;
}
@sargath
Copy link

sargath commented May 28, 2013

Yes i think this a still real problem, not only for a order but, for taxonomies and goods too.

@pjedrzejewski
Copy link
Member

Thanks for the heads up, this one is old, but useful! :)

pamil pushed a commit to pamil/Sylius that referenced this issue Mar 21, 2016
[ResourceBundle] : Twig extension documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Potential Bug Potential bugs or bugfixes, that needs to be reproduced.
Projects
None yet
Development

No branches or pull requests

3 participants