Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
586ea72
commit 56311e8
Showing
3 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
src/Sylius/Bundle/CoreBundle/Collector/DebugCartCollector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\CoreBundle\Collector; | ||
|
||
use Sylius\Bundle\CoreBundle\Application\Kernel; | ||
use Sylius\Component\Channel\Context\ChannelNotFoundException; | ||
use Sylius\Component\Order\Context\CartContextInterface; | ||
use Sylius\Component\Core\Model\ChannelInterface; | ||
use Sylius\Component\Currency\Context\CurrencyNotFoundException; | ||
use Sylius\Component\Locale\Context\LocaleNotFoundException; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\DataCollector\DataCollector; | ||
|
||
final class DebugCartCollector extends DataCollector | ||
{ | ||
/** @var CartContextInterface */ | ||
private $cartContext; | ||
|
||
public function __construct( | ||
CartContextInterface $cartContext | ||
) { | ||
$this->cartContext = $cartContext; | ||
$cart = $cartContext->getCart(); | ||
|
||
$items = []; | ||
foreach ($cart->getItems() as $item) { | ||
$variant = $item->getVariant(); | ||
$product = $variant->getProduct(); | ||
|
||
$items[] = [ | ||
'id' => $item->getId(), | ||
'variantName' => $variant->getName(), | ||
'variantId' => $variant->getId(), | ||
'variantCode' => $variant->getCode(), | ||
'quantity' => $item->getQuantity(), | ||
'productName' => $product->getName(), | ||
'productId' => $product->getId(), | ||
]; | ||
} | ||
|
||
$this->data = [ | ||
'cart_id' => $cart->getId(), | ||
'total' => $cart->getTotal(), | ||
'subtotal' => $cart->getItemsTotal(), | ||
'currency' => $cart->getCurrencyCode(), | ||
'locale' => $cart->getLocaleCode(), | ||
'quantity' => count($cart->getItems()), | ||
'items' => $items, | ||
'states' => [ | ||
'main' => $cart->getState(), | ||
'checkout' => $cart->getCheckoutState(), | ||
'shipping' => $cart->getShippingState(), | ||
'payment' => $cart->getPaymentState(), | ||
] | ||
]; | ||
} | ||
|
||
public function getCartId(): ?int | ||
{ | ||
return $this->data['cart_id']; | ||
} | ||
|
||
public function getTotal(): ?int | ||
{ | ||
return $this->data['total']; | ||
} | ||
|
||
public function getSubtotal(): ?int | ||
{ | ||
return $this->data['subtotal']; | ||
} | ||
|
||
public function getCurrency(): ?string | ||
{ | ||
return $this->data['currency']; | ||
} | ||
|
||
public function getLocale(): ?string | ||
{ | ||
return $this->data['locale']; | ||
} | ||
|
||
public function getQuantity(): ?int | ||
{ | ||
return $this->data['quantity']; | ||
} | ||
|
||
public function getItems(): ?array | ||
{ | ||
return $this->data['items']; | ||
} | ||
|
||
public function getStates(): ?array | ||
{ | ||
return $this->data['states']; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function collect(Request $request, Response $response, \Exception $exception = null): void | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function reset(): void | ||
{ | ||
$this->data['cart_id'] = null; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName(): string | ||
{ | ||
return 'sylius_core_debug_cart'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/Sylius/Bundle/CoreBundle/Resources/views/Collector/debug_cart.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
{% extends '@WebProfiler/Profiler/layout.html.twig' %} | ||
|
||
{% block toolbar %} | ||
{% import "@SyliusShop/Common/Macro/money.html.twig" as money %} | ||
|
||
{% set icon %} | ||
<span class="sf-toolbar-value">Cart ({{ collector.quantity|default(0) }})</span> | ||
{% endset %} | ||
{% set text %} | ||
<div class="sf-toolbar-info-group"> | ||
<div class="sf-toolbar-info-piece"> | ||
<b>ID</b> | ||
<span>{{ collector.cartId }}</span> | ||
</div> | ||
<div class="sf-toolbar-info-piece"> | ||
<b>Subtotal</b> | ||
<span>{{ money.convertAndFormat(collector.subtotal, collector.currency) }}</span> | ||
</div> | ||
<div class="sf-toolbar-info-piece"> | ||
<b>Total</b> | ||
<span>{{ money.convertAndFormat(collector.total, collector.currency) }}</span> | ||
</div> | ||
</div> | ||
<div class="sf-toolbar-info-group"> | ||
<div class="sf-toolbar-info-piece"> | ||
<span><a href="{{ profiler_url ~ '?panel=sylius_core_debug_cart' }}" rel="help">View details</a></span> | ||
</div> | ||
</div> | ||
{% endset %} | ||
|
||
{% include '@WebProfiler/Profiler/toolbar_item.html.twig' with {'link': profiler_url} %} | ||
{% endblock %} | ||
|
||
{% block menu %} | ||
<span class="label"> | ||
<span class="icon">{{ include('@WebProfiler/Icon/form.svg') }}</span> | ||
<strong>Cart</strong> | ||
</span> | ||
{% endblock %} | ||
|
||
{% block panel %} | ||
|
||
{% import "@SyliusShop/Common/Macro/money.html.twig" as money %} | ||
|
||
<h2>Cart</h2> | ||
<table> | ||
<tr> | ||
<th>ID</th> | ||
<th>Currency</th> | ||
<th>Locale</th> | ||
<th>Subtotal</th> | ||
<th>Total</th> | ||
</tr> | ||
<tr> | ||
<td>{{ collector.cartId }}</td> | ||
<td>{{ collector.currency }}</td> | ||
<td>{{ collector.locale }}</td> | ||
<td>{{ money.convertAndFormat(collector.subtotal, collector.currency) }}</td> | ||
<td>{{ money.convertAndFormat(collector.total, collector.currency) }}</td> | ||
</tr> | ||
</table> | ||
|
||
<h2>States</h2> | ||
<table> | ||
<tr> | ||
<th>Main</th> | ||
<th>Checkout</th> | ||
<th>Shipping</th> | ||
<th>Payment</th> | ||
</tr> | ||
<tr> | ||
<td>{{ collector.states.main }}</td> | ||
<td>{{ collector.states.checkout }}</td> | ||
<td>{{ collector.states.shipping }}</td> | ||
<td>{{ collector.states.payment }}</td> | ||
</tr> | ||
</table> | ||
|
||
{% if collector.items|length > 0 %} | ||
<h2>Items</h2> | ||
<table> | ||
<tr> | ||
<th>ID</th> | ||
<th>Product (ID)</th> | ||
<th>Variant (ID / Code)</th> | ||
<th>Quantity</th> | ||
</tr> | ||
{% for item in collector.items %} | ||
<tr> | ||
<td>{{ item.id }}</td> | ||
<td>{{ item.productName }} ({{item.productId}})</td> | ||
<td>{{ item.variantName }} ({{ item.variantId }} / {{ item.variantCode }})</td> | ||
<td>{{ item.quantity }}</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
{% endif %} | ||
{% endblock %} |