Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Block/FaqProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Block/LatestFaq.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function getFaqCount(): int
{
$collection = $this->faqCollectionFactory->create();
$collection->addFieldToFilter('is_active', 1);
return $collection->count();
return $collection->getSize();
}
}
11 changes: 8 additions & 3 deletions Console/MakeThingsTerrible.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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');
Expand Down
7 changes: 4 additions & 3 deletions Controller/Adminhtml/Question/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
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
{
public function __construct(
Context $context,
private readonly FaqRepositoryInterface $faqRepository,
private readonly Faq $faq
private readonly FaqFactory $faqFactory
) {
parent::__construct($context);
}
Expand All @@ -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");
Expand Down
10 changes: 7 additions & 3 deletions Helper/FaqList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 8 additions & 5 deletions Plugin/CustomerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

/**
Expand All @@ -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 [];
}
}
11 changes: 11 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,15 @@
</argument>
</arguments>
</type>

<type name="Crealoz\TerribleModule\Console\MakeThingsTerrible" shared="false">
<arguments><argument name="faqModel" xsi:type="object">\Crealoz\TerribleModule\Model\Faq\Proxy</argument>
<argument name="state" xsi:type="object">\Magento\Framework\App\State\Proxy</argument>
</arguments>
</type>

<type name="Crealoz\TerribleModule\Controller\Index\CustomerFaq" shared="false">
<arguments><argument name="customerSession" xsi:type="object">\Magento\Customer\Model\Session\Proxy</argument>
</arguments>
</type>
</config>
4 changes: 2 additions & 2 deletions view/frontend/templates/latest.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $latestFaq = $block->getLatestFaq();

<div class="latest-faq">
<h3><?= $escaper->escapeHtml(__('Latest Questions')) ?></h3>
<?php if ($latestFaq->count() > 0): ?>
<?php if ($latestFaq->getSize() > 0): ?>
<ul>
<?php foreach ($latestFaq as $faq): ?>
<li>
Expand All @@ -18,7 +18,7 @@ $latestFaq = $block->getLatestFaq();
</li>
<?php endforeach; ?>
</ul>
<?php echo $this->getFaqCount() ?>
<?php echo $block->getFaqCount() ?>
<?php else: ?>
<p><?= $escaper->escapeHtml(__('No FAQ available yet.')) ?></p>
<?php endif; ?>
Expand Down