diff --git a/Block/FaqProduct.php b/Block/FaqProduct.php index cd75194..79ad8db 100644 --- a/Block/FaqProduct.php +++ b/Block/FaqProduct.php @@ -3,29 +3,29 @@ namespace Crealoz\TerribleModule\Block; use Magento\Catalog\Api\ProductRepositoryInterface; -use Magento\Framework\App\ObjectManager; use Magento\Framework\View\Element\Template; -use Crealoz\TerribleModule\Model\ResourceModel\Faq\Collection; +use Crealoz\TerribleModule\Model\ResourceModel\Faq\CollectionFactory; class FaqProduct extends Template { protected $productRepository; - private ObjectManager $objectManager; + + private CollectionFactory $collectionFactory; public function __construct( Template\Context $context, - ObjectManager $objectManager, ProductRepositoryInterface $productRepository, + CollectionFactory $collectionFactory, array $data = [] ) { + $this->collectionFactory = $collectionFactory; $this->productRepository = $productRepository; parent::__construct($context, $data); - $this->objectManager = $objectManager; } public function getFaqCollection() { - $collection = $this->objectManager->create(Collection::class); + $collection = $this->collectionFactory->create(); $collection->addFieldToFilter('question', ['like' => '%produit%']); $collection->addFieldToFilter('is_active', 1); return $collection; diff --git a/Block/LatestFaq.php b/Block/LatestFaq.php index 3465131..f96d1fc 100644 --- a/Block/LatestFaq.php +++ b/Block/LatestFaq.php @@ -30,6 +30,6 @@ public function getFaqCount(): int { $collection = $this->faqCollectionFactory->create(); $collection->addFieldToFilter('is_active', 1); - return $collection->count(); + return $collection->getSize(); } } diff --git a/Console/MakeThingsTerrible.php b/Console/MakeThingsTerrible.php index 306fbfe..d06b193 100644 --- a/Console/MakeThingsTerrible.php +++ b/Console/MakeThingsTerrible.php @@ -8,13 +8,18 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\Question; +use Magento\User\Model\UserFactory; class MakeThingsTerrible extends Command { + private UserFactory $userFactory; + public function __construct( protected \Crealoz\TerribleModule\Model\Faq $faqModel, - protected readonly State $state + protected readonly State $state, + UserFactory $userFactory ) { + $this->userFactory = $userFactory; parent::__construct(); } @@ -27,8 +32,8 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { if ($this->state->getAreaCode() === Area::AREA_ADMINHTML) { - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); - $user = $objectManager->create('Magento\User\Model\User'); + + $user = $this->userFactory->create(); $user->setId(1); } $questionHelper = $this->getHelper('question'); diff --git a/Controller/Adminhtml/Question/Edit.php b/Controller/Adminhtml/Question/Edit.php index 1679dc3..053d6eb 100644 --- a/Controller/Adminhtml/Question/Edit.php +++ b/Controller/Adminhtml/Question/Edit.php @@ -3,7 +3,7 @@ namespace Crealoz\TerribleModule\Controller\Adminhtml\Question; use Crealoz\TerribleModule\Api\FaqRepositoryInterface; -use Crealoz\TerribleModule\Model\Faq; +use Crealoz\TerribleModule\Model\FaqFactory; use Magento\Backend\App\Action\Context; class Edit extends \Magento\Backend\App\Action @@ -11,7 +11,7 @@ class Edit extends \Magento\Backend\App\Action public function __construct( Context $context, private readonly FaqRepositoryInterface $faqRepository, - private readonly Faq $faq + private readonly FaqFactory $faqFactory ) { parent::__construct($context); } @@ -29,7 +29,8 @@ public function execute() } $resultPage->getConfig()->getTitle()->prepend(__('Edit Question')); } else { - $this->faq->setData([]); + $faq = $this->faqFactory->create(); + $faq->setData([]); $resultPage->getConfig()->getTitle()->prepend(__('New Question')); } $resultPage->setActiveMenu("Crealoz_TerribleModule::faq"); diff --git a/Helper/FaqList.php b/Helper/FaqList.php index 7006819..112623e 100644 --- a/Helper/FaqList.php +++ b/Helper/FaqList.php @@ -3,21 +3,25 @@ namespace Crealoz\TerribleModule\Helper; use Crealoz\TerribleModule\Model\ResourceModel\Faq\CollectionFactory; +use Magento\User\Api\Data\UserInterface; class FaqList extends \Magento\Framework\App\Helper\AbstractHelper { protected $faqCollectionFactory; + private UserInterface $user; + public function __construct( - CollectionFactory $faqCollectionFactory + CollectionFactory $faqCollectionFactory, + UserInterface $user ) { - $this->objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $this->user = $user; $this->faqCollectionFactory = $faqCollectionFactory; } public function getFaqCollection() { - $user = $this->objectManager->get('Magento\User\Model\User'); + $user = $this->user; $collection = $this->faqCollectionFactory->create(); $collection->addFieldToFilter('is_active', 1); return $collection; diff --git a/Plugin/CustomerPlugin.php b/Plugin/CustomerPlugin.php index 7626000..d005ff8 100644 --- a/Plugin/CustomerPlugin.php +++ b/Plugin/CustomerPlugin.php @@ -9,12 +9,14 @@ class CustomerPlugin * * @param $subject * @param $proceed + * @param mixed $result Result of the intercepted method * @return string */ - public function aroundGetCustomerName($subject, $proceed) + public function afterGetCustomerName($subject, $result) + { - $customerName = $proceed(); - return 'Mr. ' . $customerName; + return 'Mr. ' . $result; + } /** @@ -24,9 +26,10 @@ public function aroundGetCustomerName($subject, $proceed) * @param $proceed * @return mixed */ - public function aroundGetCustomerEmail($subject, $proceed) + public function beforeGetCustomerEmail($subject) + { $subject->setEmail('anonymus@toto.fr'); - return $proceed(); + return []; } } diff --git a/etc/di.xml b/etc/di.xml index 3ae0782..d1b57f1 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -66,4 +66,15 @@ + + + \Crealoz\TerribleModule\Model\Faq\Proxy + \Magento\Framework\App\State\Proxy + + + + + \Magento\Customer\Model\Session\Proxy + + diff --git a/view/frontend/templates/latest.phtml b/view/frontend/templates/latest.phtml index 0108ee9..4759262 100644 --- a/view/frontend/templates/latest.phtml +++ b/view/frontend/templates/latest.phtml @@ -9,7 +9,7 @@ $latestFaq = $block->getLatestFaq();

escapeHtml(__('Latest Questions')) ?>

- count() > 0): ?> + getSize() > 0): ?> - getFaqCount() ?> + getFaqCount() ?>

escapeHtml(__('No FAQ available yet.')) ?>