Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Master - make order steps working on front office for symfony 4.1 - PR 2 #603

Merged
merged 1 commit into from
Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/BasketBundle/Controller/BasketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,6 +36,16 @@
*/
class BasketController extends Controller
{
/**
* @var BasketFactoryInterface
*/
private $basketFactory;

public function __construct(BasketFactoryInterface $basketFactory)
{
$this->basketFactory = $basketFactory;
}

/**
* Shows the basket.
*
Expand Down Expand Up @@ -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'));
}
Expand Down Expand Up @@ -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', [
Expand Down Expand Up @@ -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'));
}
Expand Down Expand Up @@ -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'));
}
Expand Down Expand Up @@ -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'));
}
Expand Down Expand Up @@ -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'));
}
Expand Down Expand Up @@ -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'));
}
Expand Down Expand Up @@ -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'));
}
Expand Down
4 changes: 4 additions & 0 deletions src/BasketBundle/Resources/config/basket.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@
<argument>sonata.basket.block.nb_items</argument>
<argument type="service" id="templating"/>
</service>
<service id="Sonata\BasketBundle\Controller\BasketController">
<tag name="controller.service_arguments"/>
<argument type="service" id="sonata.basket.factory"/>
</service>
</services>
</container>
2 changes: 1 addition & 1 deletion src/Component/Basket/BasketElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/Component/Basket/BasketElementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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): void;

/**
* Returns the VAT amount.
Expand Down
2 changes: 1 addition & 1 deletion src/Component/Delivery/FreeDelivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public function isAddressRequired()

public function getName()
{
return 'Free delivery';
return 'free_address_required';
OskarStark marked this conversation as resolved.
Show resolved Hide resolved
}
}
2 changes: 1 addition & 1 deletion src/Component/Product/AddBasket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/CustomerBundle/Resources/config/orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<argument>%sonata.customer.address.class%</argument>
<argument type="service" id="doctrine"/>
</service>
<service id="sonata.customer.manager" class="%sonata.customer.manager.class%">
<service id="sonata.customer.manager" class="%sonata.customer.manager.class%" public="true">
<argument>%sonata.customer.customer.class%</argument>
<argument type="service" id="doctrine"/>
</service>
Expand Down
4 changes: 4 additions & 0 deletions src/PaymentBundle/Resources/config/payment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,9 @@
<argument type="service" id="sonata.notification.backend"/>
<argument type="service" id="event_dispatcher"/>
</service>
<service id="Sonata\PaymentBundle\Controller\PaymentController">
<tag name="controller.service_arguments"/>
<argument type="service" id="sonata.basket.factory"/>
</service>
</services>
</container>
2 changes: 1 addition & 1 deletion tests/Component/Delivery/FreeDeliveryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}