I have a custom class in Shopware that is not extending any other class in the CMS.
I want to have access to the database layer without using the container->get() or the DI service.
I don't know how to get the container to work in my class.
<?php declare(strict_types=1);
namespace Author\PriceDiscountPlugin\Handlers;
use Shopware\Core\Checkout\Cart\Cart;
use Shopware\Core\Checkout\Cart\CartBehavior;
use Shopware\Core\Checkout\Cart\CartProcessorInterface;
use Shopware\Core\Checkout\Cart\LineItem\CartDataCollection;
use Shopware\Core\Checkout\Cart\LineItem\LineItem;
use Shopware\Core\Checkout\Cart\LineItem\LineItemCollection;
use Shopware\Core\Checkout\Cart\Price\PercentagePriceCalculator;
use Shopware\Core\Checkout\Cart\Price\Struct\PercentagePriceDefinition;
use Shopware\Core\Checkout\Cart\Rule\LineItemRule;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
class DiscountCollector implements CartProcessorInterface
{
/**
* @var PercentagePriceCalculator
*/
private $calculator;
public function __construct(PercentagePriceCalculator $calculator)
{
$this->calculator = $calculator;
}
public function process(CartDataCollection $data, Cart $original, Cart $toCalculate, SalesChannelContext $context, CartBehavior $behavior): void
{
....
/* I WANT TO ACCESS THE DATABASE HERE */
....
}
}