Magento 2 Call phtml file in CMS Page

Here we will learn how to call custom phtml file on any cms page or add phtml in your custom cms page.

First, go to the admin section and open CMS page in which you want to add phtml file.
Go to the content section and add blow code.
Note: Replace package and module with your custom module.

{{block class="Magento\Framework\View\Element\Template" template="Package_Module::test.phtml"}}

Are you want to add external CSS in cms page?
You just need to put below code in cms page->design tab->layout section.



Afer save CMS page clear cache.

Magento 2 Useful Commands

Forusefully deploy

php bin/magento setup:static-content:deploy -f -s standard

Setup Upgrade Using Command Line

php bin/magento setup:upgrade

If you don’t want to remove pub/static files while installing/updating database then use following command.

php bin/magento setup:upgrade --keep-generated

Cache Clean Using Command Line

php bin/magento cache:clean

Cache Flush Using Command Line

php bin/magento cache:flush

View cache status Using Command Line

php bin/magento cache:status

Enable Cache Using Command Line

php bin/magento cache:enable [cache_type]

Disable Cache Using Command Line

php bin/magento cache:disable [cache_type]

Static Content Deploy Using Command Line (Use -f for force deploy on 2.2.x or later)

php bin/magento setup:static-content:deploy

Static Content Deploy For Particular Language Using Command Line

php bin/magento setup:static-content:deploy en_US

Static Content Deploy For Magento Backend Theme Using Command Line (Working on 2.1.1 or later)

php bin/magento setup:static-content:deploy --theme="Magento/backend"

Static Content Deploy For Specific Themes Using Command Line (Working on 2.1.1 or later)

php bin/magento setup:static-content:deploy --theme Magento/luma --theme Magento/second_theme

Exclude Themes on Static Content Deploy and does not minify HTML files Using Command Line (Working on 2.1.1 or later)

php bin/magento setup:static-content:deploy en_US --exclude-theme Magento/luma --no-html-minify

Reindexing Using Command Line

php bin/magento indexer:reindex

View the list of indexers Using Command Line

php bin/magento indexer:info

View indexer status Using Command Line

php bin/magento indexer:status

Show the mode of all indexers Using Command Line

php bin/magento indexer:show-mode

See all modules Status Using Command Line

php bin/magento module:status

Enable module Using Command Line

php bin/magento module:enable Namespace_Module

Disable module Using Command Line

php bin/magento module:disable Namespace_Module

Uninstall Module Using Command Line

php bin/magento module:uninstall Namespace_Module

Check Current Mode Using Command Line

php bin/magento deploy:mode:show

Change To Developer Mode Using Command Line

php bin/magento deploy:mode:set developer

Change To Production Mode Using Command Line

php bin/magento deploy:mode:set production

Run the single-tenant Compiler Using Command Line

php bin/magento setup:di:compile

Unlock Admin User Using Command Line

Unlock Admin User Using Command Line

Enable Maintenance Mode Using Command Line

php bin/magento maintenance:enable

How to Improve WordPress Security ?

We know as a matter of fact that having your site hacked is not fun. That is the reason, here at Universal WebTech, we consider security important.

In accordance with our genuine way to deal with security, our items are deliberately improved to be as secure as could be allowed. There are, on the other hand, still a modest bunch of potential security dangers, when running a site, that we have no power over. You, the site proprietor, need to pay consideration on these potential security dangers, with a specific end goal to keep your site safe.

Like most site proprietors, security was never top of my needs. It was just when one of my sites was hacked that I understood how regular it was for sites to be traded off by vindictive gatherings.

There are several points which should not be neglected:

Kindly go through below points to overcome from unwanted threats if you are already facing or keep this in mind for future benefits.

Do not use generic user-name and password:

This is most common thing but mostly leave undone by admins that causes unwanted threats to WordPress sites. Recetly millions of WordPress sites were hacked due to unpatched vulnerability in REST API (Which has been patched in WordPress version 4.7.2). Such ignorance can be destroying on any types of business or blogs. Do not use commonly used password for your WordPress site like 123456, password123, etc.

Login Hint should not be there:

If login-hint is enabled on your WordPress site and any time after placing a wrong password WordPress is suggesting hint, it should be removed by disabling script in function.php section using below code:

function no_wordpress_errors(){ return 'Remove or change this text'; } add_filter( 'login_errors', 'no_wordpress_errors' ); 

Enable 2FA for your WordPress:

Now, this is feature has saved lots of people around the world from potential hacking, so why don’t you enable it on WordPress site? WordPress by default not providing this feature but you can use any reliable plug-in to enable.

Plugin Security is must:

Do not ever install plugin that is from unkown resource. This simple tactic will effectively help you to stay away from intruders to pry in your own website. You can also use WordPress security plugin like WP White Security to improve security.

As per WP White Security, more than 70% of WordPress establishments are defenseless against programmer assaults and the aggregate number of hacked WordPress sites in 2012 was an incredible 170,000. This figure is developing consistently. Install All In One Wp Security and Firewall Plugin for WordPress security.

Get SSL Certificate for Safer communication:

Most of Developers are aware of SSL thing, but if not they must. Data transiting between browser and server can be pried if there isn’t a shelter of SSL. Price of SSL certs often harass site owners but gone are the days. Previously SSL could only be afforded by huge companies but now providers like SSL Shop are boon for newbies as well. So ideally every website should get the certificate and encrypt data transmission over HTTPs. Additionally Google is pushing search rankings for HTTPs websites, so this will like cherry on top moment for all website owners.

Make your systems up-to-date:

Whether it is plugin, WordPress or your physical system’s software or hardware, everything should be up-to-date to stay away from bad people. Above example of WordPress REST API vulnerability have ruined many peoples life. Updates often come after patching vulnerabilities so it must be done.

Conclusion:

Hope this piece of content is enough impressive and containing valuable information. Next time we will come with another good topic to improve your website performance.

Load product by SKU in Magento 1.x

How to load Magento product by SKU or by product id to get product name, Image, and other useful information.

Load product by SKU
$product = Mage::getModel('catalog/product')->loadByAttribute('sku','product_sku');

Load product by product id
$product = Mage::getModel('catalog/product')->load($product_id);

Warning: simplexml_load_string() in Magento

Warning: simplexml_load_string() in Magento

This error comes when there is any unwanted white space in any file or in the URL path.

To fix this error you need to connect to the database and open table core_config_data.

find web/unsecure/base_url and web/secure/base_url URL in this table.

check domain URL contains white space or not if yes then remove and save it.

now clear cache from var folder and run URL.

Direct SQL Queries In Magento

Let’s assume we need to fetch data from direct database and we don’t want to use model in magento. At that time we can also access data direct from database using magento database connection and simple SQL query.

Below is the code for how can we access data using simple SQL query.

$new_db_resource = Mage::getSingleton('core/resource');
$connection = $new_db_resource->getConnection('magento');
$data='SELECT design_id FROM sales_flat_quote_item WHERE item_id = '.$_item->getId();
$outout=$connection->fetchRow($data);
print_r($outout);

Get product image in Magento

Magento basically has 3 different types of product image which are as followed.
Base Image
Small Image
Thumbnail image

Now let’s see how we can get product images using product id.

$products = Mage::getModel('catalog/product')->load(900);
echo $products->getImage();
echo $products->getSmallImage();
echo $products->getThumbnail();
echo Mage::helper('catalog/image')->init($products, 'small_image')->resize(163,100);
echo Mage::helper('catalog/image')->init($products, 'image')->resize(400,400);

Get product collection filter by category id in magento

Below is the code by using we can get product collection filter by category id in Magento

$category = Mage::getModel('catalog/category')->load('category_id');
$productCollection = $category->getProductCollection();
$productCollection
->addStoreFilter()
->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addUrlRewrite();

SQL constraints

FOREIGN KEY – Ensure the referential integrity of the data in one table to match values in another table
CHECK – Ensures that the value in a column meets a specific condition
NOT NULL – It will not accept NULL value.
DEFAULT – Specifies a default value for a column
UNIQUE – Ensures that each row for a column must have a unique value
PRIMARY KEY – A combination of a NOT NULL and UNIQUE. Ensures that a column have a unique identity which helps to find a particular record in a table more easily and quickly