I want to intercept sales_order_place_before
event, so I created a new module named app\code\Giulio\CheckoutExtention, created a
registration.php` file where I put this code below:
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Giulio_CheckoutExtension',
__DIR__
);
a module.xml
inside app\code\Giulio\CheckoutExtention\etc
where I have declared my module like following:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd" >
<module name="Giulio_CheckoutExtension" setup_version="0.0.1"/>
</config>
and then always inside \etc
folder, an events.xml
where i declared my Observer like this.
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_order_place_after">
<observer name="set_checkout_if_no_different_categories" instance="Giulio\CheckoutExtension\Observer\SetCheckout" />
</event>
</config>
Then inside \Giulio\CheckoutExtension\Observer
a SetCheckout.php
file where I extended Monolog\Logger
class for loggin some messages and implemented ObserverInterface
like this:
<?php
namespace Giulio\CheckoutExtension\Observer;
use Magento\Framework\Event\Observer;
use Monolog\Logger;
class SetCheckout extends Logger implements \Magento\Framework\Event\ObserverInterface {
public function execute(Observer $observer) {
$order = $observer->getEvent()->getOrder();
$order->setOrderId("CIAO");
$this->warning("Ho creato un Log con l'observer");
}
}
after executing
rm -rf var/di/* var/generation/* var/cache/* var/log/* var/page_cache/*
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento indexer:reindex
and tried to accessing Homepage for my store, the page wont load and it will be left blank.
Any suggestion?
Thanks you all anticipately!
__constructor()
the\Psr\Log\LoggerInterface $logger
.