I have a custom module which, among other things, when installed will create a page. I want to pass a cart ID (encrypted) to this page as a param and then get this cart ID and delete. This needs to be be done via an ID, not via session.
This is what I have so far (effectively only creates the page):
<?php
namespace Zitec\Concierge\Setup\Patch\Data;
use Magento\Cms\Model\PageFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
class AddCartClearingPage implements DataPatchInterface
{
/** @var ModuleDataSetupInterface */
private $moduleDataSetup;
/** @var PageFactory */
private $pageFactory;
private \Magento\Framework\App\Request\Http $request;
protected $_modelCart;
protected $_checkoutSession;
/**
* @param ModuleDataSetupInterface $moduleDataSetup
* @param PageFactory $pageFactory
*/
public function __construct(
\Magento\Framework\App\Request\Http $request,
ModuleDataSetupInterface $moduleDataSetup,
PageFactory $pageFactory
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->pageFactory = $pageFactory;
$this->request = $request;
}
/**
* {@inheritdoc}
*/
public function apply()
{
$pageContent = <<<HTML
<div class="content">
<div class="title">
<h2>Clearing Cart</h2>
</div>
</div>
HTML;
$pageData = [
'title' => 'Title',
'identifier' => 'title',
'page_layout' => 'identifier',
'content_heading' => 'Clearing Cart',
'content' => $pageContent,
'is_active' => 1,
'stores' => [\Magento\Store\Model\Store::DEFAULT_STORE_ID],
'sort_order' => 11
];
$this->moduleDataSetup->startSetup();
/** @var \Magento\Cms\Model\Page $page */
$page = $this->pageFactory->create();
$page->setData($pageData)->save();
$this->moduleDataSetup->endSetup();
/**
* Clearing the cart
*/
# Not sure this is working as expected
$cartID = $this->request->getParams();
$cart = $this->_modelCart;
# I dont think this is correct either
$quoteItems = $this->checkoutSession->getQuote()->getItemsCollection();
foreach($quoteItems as $item)
{
$cart->removeItem($item->getId())->save();
}
}
}
Any suggestions on how to accomplish the remaining?