Configure and run Magento cronjob

Step 1: Add the following to your plugin’s app/code/local/Vendorname/Modulename/etc/config.xml file

<?xml version="1.0"?>
<config>
...
 
...
    <crontab>
        <jobs>
            <hexacode_kleidoo>
                <schedule>
                    <cron_expr>*/5 * * * *</cron_expr>
                </schedule>
                <run>
                    <model>vendorname_modulename/observer::mymethod</model>
                </run>
            </hexacode_kleidoo>
        </jobs>
    </crontab>
</config>

Step 2: Create app/code/local/Vendorname/Modulename/Model/Observer.php file. We put it to Observer.php in this example but we could create a new class file for this purpose.

<?php
 
class Vendorname_Modulename_Model_Observer {
 
    public function notifyorder($observer) {
            // put here your business logic
    }
}

Step 3: Add a new entry to your crontab

*/5 * * * * wget -O /dev/null -q http://www.YOURDOMAIN.com/PATH_TO_MAGENTO/cron.php &gt; /dev/null

Embed custom widget into a product list

Files involved:

app/code/Mika/CustomListing/etc/module.xml // a file setup module
app/code/Mika/CustomListing/Block/Rewrite/Product/ListingProduct.php  // a block file used for rewriting ListingProduct.php

A template block with configuration

Step 1
Create Block File: $MAGENTO_DIR/app/code/Imran/Test/Block/Titles.php

<?php
namespace Imran\Test\Block;
 
class Titles extends \Magento\Framework\View\Element\Template
{
    public function getTitle()
    {
        return "Mr";
    }
}

Step 2
Create Layout File: $MAGENTO_DIR/app/code/Imran/Test/view/layout/test_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <title/>
    </head>
    <body>
        <referenceContainer name="content">
            <block class="Imran\Test\Block\Tiles" template="Imran_Test::landingpage.phtml"/>
        </referenceContainer>
        <referenceBlock name="test-block" remove="true"/>
    </body>
</page>

Step 3
Create Template phtml File: $MAGENTO_DIR/app/code/Imran/Test/view/templates/landingpage.phtml

<?php
echo $this->getTitle();
?>

A custom widget with admin and db backend

A simple custom widget with db backend

In this tutorial, you’ll learn how-to create a database driven custom Magento 2.0 widget. It takes you through step by step creation of all necessary php, xml and template files… Read the rest of this entry »