diff --git a/src/BasketBundle/Controller/BasketController.php b/src/BasketBundle/Controller/BasketController.php index 6c6895045..b446bd44d 100644 --- a/src/BasketBundle/Controller/BasketController.php +++ b/src/BasketBundle/Controller/BasketController.php @@ -17,6 +17,7 @@ use Sonata\BasketBundle\Form\BasketType; use Sonata\BasketBundle\Form\PaymentType; use Sonata\BasketBundle\Form\ShippingType; +use Sonata\Component\Basket\BasketFactoryInterface; use Sonata\Component\Customer\AddressInterface; use Sonata\Component\Delivery\UndeliverableCountryException; use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -35,6 +36,16 @@ */ class BasketController extends Controller { + /** + * @var BasketFactoryInterface + */ + private $basketFactory; + + public function __construct(BasketFactoryInterface $basketFactory) + { + $this->basketFactory = $basketFactory; + } + /** * Shows the basket. * @@ -84,7 +95,7 @@ public function updateAction(Request $request) $basket->clean(); // clean the basket // update the basket - $this->get('sonata.basket.factory')->save($basket); + $this->basketFactory->save($basket); return new RedirectResponse($this->generateUrl('sonata_basket_index')); } @@ -146,7 +157,7 @@ public function addProductAction(Request $request) $basketElement = $provider->basketAddProduct($basket, $product, $basketElement); } - $this->get('sonata.basket.factory')->save($basket); + $this->basketFactory->save($basket); if ($request->isXmlHttpRequest() && $provider->getOption('product_add_modal')) { return $this->render('@SonataBasket/Basket/add_product_popin.html.twig', [ @@ -177,7 +188,7 @@ public function addProductAction(Request $request) */ public function resetAction() { - $this->get('sonata.basket.factory')->reset($this->get('sonata.basket')); + $this->basketFactory->reset($this->get('sonata.basket')); return new RedirectResponse($this->generateUrl('sonata_basket_index')); } @@ -207,7 +218,7 @@ public function authenticationStepAction() $basket = $this->get('sonata.basket'); $basket->setCustomer($customer); - $this->get('sonata.basket.factory')->save($basket); + $this->basketFactory->save($basket); return new RedirectResponse($this->generateUrl('sonata_basket_delivery_address')); } @@ -248,7 +259,7 @@ public function paymentStepAction(Request $request) if ($form->isSubmitted() && $form->isValid()) { // save the basket - $this->get('sonata.basket.factory')->save($basket); + $this->basketFactory->save($basket); return new RedirectResponse($this->generateUrl('sonata_basket_final')); } @@ -301,7 +312,7 @@ public function deliveryStepAction(Request $request) if ($form->isSubmitted() && $form->isValid()) { // save the basket - $this->get('sonata.basket.factory')->save($form->getData()); + $this->basketFactory->save($form->getData()); return new RedirectResponse($this->generateUrl('sonata_basket_payment_address')); } @@ -371,7 +382,7 @@ public function deliveryAddressStepAction(Request $request) $basket->setCustomer($customer); $basket->setDeliveryAddress($address); // save the basket - $this->get('sonata.basket.factory')->save($basket); + $this->basketFactory->save($basket); return new RedirectResponse($this->generateUrl('sonata_basket_delivery')); } @@ -434,7 +445,7 @@ public function paymentAddressStepAction(Request $request) $basket->setCustomer($customer); $basket->setBillingAddress($address); // save the basket - $this->get('sonata.basket.factory')->save($basket); + $this->basketFactory->save($basket); return new RedirectResponse($this->generateUrl('sonata_basket_payment')); } diff --git a/src/BasketBundle/Resources/config/basket.xml b/src/BasketBundle/Resources/config/basket.xml index e66d8a953..e7e559c08 100644 --- a/src/BasketBundle/Resources/config/basket.xml +++ b/src/BasketBundle/Resources/config/basket.xml @@ -29,5 +29,9 @@ sonata.basket.block.nb_items + + + + diff --git a/src/Component/Basket/BasketElement.php b/src/Component/Basket/BasketElement.php index d1cfcaede..383e2340c 100644 --- a/src/Component/Basket/BasketElement.php +++ b/src/Component/Basket/BasketElement.php @@ -124,7 +124,7 @@ public function getProductId() return $this->productId; } - public function setProductId($productId): void + public function setProductId(int $productId): void { if ($productId === $this->productId) { return; diff --git a/src/Component/Basket/BasketElementInterface.php b/src/Component/Basket/BasketElementInterface.php index 5c67d3ad4..1c5930bbf 100644 --- a/src/Component/Basket/BasketElementInterface.php +++ b/src/Component/Basket/BasketElementInterface.php @@ -64,10 +64,8 @@ public function getProductId(); /** * Never call this method, use the setProduct instead. This method is only used * by the form framework. - * - * @param int $productId */ - public function setProductId($productId); + public function setProductId(int $productId); /** * Returns the VAT amount. diff --git a/src/Component/Delivery/FreeDelivery.php b/src/Component/Delivery/FreeDelivery.php index 62ed389c2..eac932ccf 100644 --- a/src/Component/Delivery/FreeDelivery.php +++ b/src/Component/Delivery/FreeDelivery.php @@ -48,6 +48,6 @@ public function isAddressRequired() public function getName() { - return 'Free delivery'; + return 'free_address_required'; } } diff --git a/src/Component/Product/AddBasket.php b/src/Component/Product/AddBasket.php index 6662ceb7d..b9aaaa1f8 100644 --- a/src/Component/Product/AddBasket.php +++ b/src/Component/Product/AddBasket.php @@ -53,7 +53,7 @@ public function getProductId() * * @param int $productId the product id */ - public function setProductId($productId): void + public function setProductId(int $productId): void { // never erase this value if (null !== $this->productId) { diff --git a/src/CustomerBundle/Resources/config/orm.xml b/src/CustomerBundle/Resources/config/orm.xml index 4ade3adbf..a0455d866 100644 --- a/src/CustomerBundle/Resources/config/orm.xml +++ b/src/CustomerBundle/Resources/config/orm.xml @@ -9,7 +9,7 @@ %sonata.customer.address.class% - + %sonata.customer.customer.class% diff --git a/src/PaymentBundle/Resources/config/payment.xml b/src/PaymentBundle/Resources/config/payment.xml index 0af6b7408..fd6107f02 100644 --- a/src/PaymentBundle/Resources/config/payment.xml +++ b/src/PaymentBundle/Resources/config/payment.xml @@ -60,5 +60,9 @@ + + + + diff --git a/tests/Component/Delivery/FreeDeliveryTest.php b/tests/Component/Delivery/FreeDeliveryTest.php index 5766fef22..1dd80e16c 100644 --- a/tests/Component/Delivery/FreeDeliveryTest.php +++ b/tests/Component/Delivery/FreeDeliveryTest.php @@ -40,6 +40,6 @@ public function testPriceIsNull(): void public function testGetName(): void { $freeDelivery = new FreeDelivery(false); - $this->assertSame('Free delivery', $freeDelivery->getName()); + $this->assertSame('free_address_required', $freeDelivery->getName()); } }