Archive for the ‘Magento 2.0’ Category

Magento 2 Select from Db in a template

<?php … $om = \Magento\Framework\App\ObjectManager::getInstance();   $connection = $om->create(’\Magento\Framework\App\ResourceConnection’)->getConnection(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION);   $tblSalesOrder = $connection->getTableName(’pinamondo_seotext’); $results = $connection->fetchAll(’SELECT name FROM `’.$tblSalesOrder.’`’);   var_dump($results); …

Select simple products of configurable product

<?php   $product = Mage::getModel(’catalog/product’)->load(127); $confProduct = Mage::getModel(’catalog/product_type_configurable’)->setProduct($product); $simpleProductsCollection = $confProduct->getUsedProductCollection() ->addAttributeToSelect(’*’) ->addFilterByRequiredOptions(); foreach($simpleProductsCollection as $simpleProduct) { var_dump($simpleProduct->getId()); }

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 […]

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…