41 lines
1.5 KiB
PHP
41 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\UserAddressesBundle\Controller;
|
|
|
|
use KupShop\GraphQLBundle\EventListener\JsShopRefreshListener;
|
|
use KupShop\KupShopBundle\Routing\TranslatedRoute;
|
|
use KupShop\UserAddressesBundle\Util\UserAddressesUtil;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
|
|
|
class UserAddressesController extends AbstractController
|
|
{
|
|
#[TranslatedRoute(path: '/#cart#/_update_address/{step}')]
|
|
public function cartChange(Request $request, string $step, \Cart $cart, UserAddressesUtil $addressesUtil, SessionInterface $session): Response
|
|
{
|
|
$addressId = $request->get('addressId');
|
|
$cart->setData('user_address_id', $addressId);
|
|
|
|
if ($addressId !== null) {
|
|
$address = $addressesUtil->getDeliveryAddress(intval($addressId));
|
|
if ($address !== null) {
|
|
$cart->fetchAddresses();
|
|
$cart->updateAddresses($cart->invoice, $address->getAddressArray());
|
|
$cart->save();
|
|
|
|
$cart->invalidatePurchaseState();
|
|
$session->set(JsShopRefreshListener::SESSION_NAME, true);
|
|
}
|
|
}
|
|
|
|
return $this->forward('KupShop\ContentBundle\Controller\CartController::cartAction', [
|
|
'request' => $request,
|
|
'step' => $step,
|
|
]);
|
|
}
|
|
}
|