Magento add hidden Product attribute Magento add hidden Product attribute
$setup->addAttribute('catalog_product', 'seller_name', array(
'group' => 'Meta Information',
'input' => 'hidden',
'type' => 'text',
'label' => 'Seller Name',
'backend' => '',
'visible' => 0,
'required' => 0,
'user_defined' => 1,
'searchable' => 1,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 1,
'visible_in_advanced_search' => 0,
'is_html_allowed_on_front' => 0,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
Ngage Studios - Magento Certified Developers May 18, 2016
Magento add hidden Product attribute Magento add hidden Product attribute
$setup->addAttribute('catalog_product', 'seller_name', array(
'group' => 'Meta Information',
'input' => 'hidden',
'type' => 'text',
'label' => 'Seller Name',
'backend' => '',
'visible' => 0,
'required' => 0,
'user_defined' => 1,
'searchable' => 1,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 1,
'visible_in_advanced_search' => 0,
'is_html_allowed_on_front' => 0,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
Magento2 How to load product collection by id I got product collection in my custom template using following code
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
foreach ($productCollection as $product) {
$product_id=$product['entity_id'];
echo $_product->getName();
}?> Ngage Studios - Magento Certified Developers
Magento2 How to load product collection by id I got product collection in my custom template using following code
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
foreach ($productCollection as $product) {
$product_id=$product['entity_id'];
echo $_product->getName();
}?>
Magento get just one column value or get multiple column values by name Magento get just one column value or get multiple column values by name
Only want a particular field?
print_r($collection->getColumnValues('name'));
The team at Magento have even given us some rudimentary filtering capabilities.
print_r($collection->getItemsByColumnValue('name','fieldname'));
Ngage Studios - Magento Certified Developers May 17, 2016
Magento get just one column value or get multiple column values by name Magento get just one column value or get multiple column values by name
Only want a particular field?
print_r($collection->getColumnValues('name'));
The team at Magento have even given us some rudimentary filtering capabilities.
print_r($collection->getItemsByColumnValue('name','fieldname'));
Magento 2: indexing using Command prompt f we need to do whole index management in the site we will run the following command in project In root magento directory
php bin/magento indexer:reindex in root/bin directory
php magento indexer:reindex Execute the command from command line and be happy. Indexing will work perfectly.
Ngage Studios - Magento Certified Developers May 16, 2016
Magento 2: indexing using Command prompt f we need to do whole index management in the site we will run the following command in project In root magento directory
php bin/magento indexer:reindex in root/bin directory
php magento indexer:reindex Execute the command from command line and be happy. Indexing will work perfectly.
Magento 2 : How to get formatted price with currency Magento 2 : How to get formatted price with currency
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of Object Manager
$priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data'); // Instance of Pricing Helper
$price = 1000; //Your Price
$formattedPrice = $priceHelper->currency($price, true, false);
?>
Ngage Studios - Magento Certified Developers May 14, 2016
Magento 2 : How to get formatted price with currency Magento 2 : How to get formatted price with currency
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of Object Manager
$priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data'); // Instance of Pricing Helper
$price = 1000; //Your Price
$formattedPrice = $priceHelper->currency($price, true, false);
?>
Magento 2 : How to get current category from registry Magento 2 : How to get current category from registry
<?php
$registry = $objectManager->get('Magento\Framework\Registry');
$category = $objectManager->create('Magento\Catalog\Model\Category')->load($registry->registry('current_category')->getId());
?> OR
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category
echo $category->getId();
echo $category->getName();
?>
Ngage Studios - Magento Certified Developers May 10, 2016
Magento 2 : How to get current category from registry Magento 2 : How to get current category from registry
<?php
$registry = $objectManager->get('Magento\Framework\Registry');
$category = $objectManager->create('Magento\Catalog\Model\Category')->load($registry->registry('current_category')->getId());
?> OR
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category
echo $category->getId();
echo $category->getName();
?>
Magento 2 : translation steps step 1: get the translation texts
php bin/magento i18n:collect-phrases --output=zh_Hans_CN.csv --magento .
Step 2: on root folder there must be translation file of this name
Step 3: Create folders
mkdir app/i18n
mkdir app/i18n/ngage/
mkdir app/i18n/ngage/zh_Hans_CN/ Step 4 :Create the file composer.json with the following contents:
{
"name": "test/nl_nl",
"description": "Chinese Language",
"version": "100.0.1",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"require": {
"magento/framework": "100.0.*"
},
"type": "magento2-language",
"autoload": {
"files": [
"registration.php"
]
}
,"extra": {"map": "*", "ngage/zh_Hans_CN"}
} Stpe 5 : Create the file language.xml with the following contents:
<?xml version="1.0"?>
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
zh_Hans_CN
<vendor>ngage</vendor>
<package>zh_hans_cn</package>
</language> Step 6: Create the file registration.php with the following content:
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::LANGUAGE,
'ngage_zh_hans_cn',
__DIR__
); Step 7: deploy setup
php bin/magento setup:static-content:deploy
php bin/magento setup:static-content:deploy nl_NL
php bin/magento indexer:reindex
php bin/magento cache:clean
php bin/magento cache:flush
Ngage Studios - Magento Certified Developers May 8, 2016
Magento 2 : translation steps step 1: get the translation texts
php bin/magento i18n:collect-phrases --output=zh_Hans_CN.csv --magento .
Step 2: on root folder there must be translation file of this name
Step 3: Create folders
mkdir app/i18n
mkdir app/i18n/ngage/
mkdir app/i18n/ngage/zh_Hans_CN/ Step 4 :Create the file composer.json with the following contents:
{
"name": "test/nl_nl",
"description": "Chinese Language",
"version": "100.0.1",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"require": {
"magento/framework": "100.0.*"
},
"type": "magento2-language",
"autoload": {
"files": [
"registration.php"
]
}
,"extra": {"map": "*", "ngage/zh_Hans_CN"}
} Stpe 5 : Create the file language.xml with the following contents:
<?xml version="1.0"?>
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
zh_Hans_CN
<vendor>ngage</vendor>
<package>zh_hans_cn</package>
</language> Step 6: Create the file registration.php with the following content:
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::LANGUAGE,
'ngage_zh_hans_cn',
__DIR__
); Step 7: deploy setup
php bin/magento setup:static-content:deploy
php bin/magento setup:static-content:deploy nl_NL
php bin/magento indexer:reindex
php bin/magento cache:clean
php bin/magento cache:flush
Magento 2 file permission File system permissions and ownership Use the following steps:
If you haven’t already done so, log in to your Magento server as, or switch to, the Magento file system owner . Change to the Magento installation directory:cd <web server docroot>/<magento2 base dir> The base directory is typically a subdirectory named magento2
under your web server’s docroot. Need help locating the docroot? Click here .
Examples:
Ubuntu: /var/www/magento2
CentOS: /var/www/html/magento2
Set ownership:chown -R :<your web server group name> . Typical examples:
CentOS: chown -R :apache .
Ubuntu: chown -R :www-data .
Set permissions:find . -type d -exec chmod 770 {} \; && find . -type f -exec chmod 660 {} \; && chmod u+x bin/magento If you must enter the commands as sudo
, use:
sudo find . -type d -exec chmod 770 {} \; && sudo find . -type f -exec chmod 660 {} \; && sudo chmod u+x bin/magento
Ngage Studios - Magento Certified Developers May 7, 2016
Magento 2 file permission File system permissions and ownership Use the following steps:
If you haven’t already done so, log in to your Magento server as, or switch to, the Magento file system owner . Change to the Magento installation directory:cd <web server docroot>/<magento2 base dir> The base directory is typically a subdirectory named magento2
under your web server’s docroot. Need help locating the docroot? Click here .
Examples:
Ubuntu: /var/www/magento2
CentOS: /var/www/html/magento2
Set ownership:chown -R :<your web server group name> . Typical examples:
CentOS: chown -R :apache .
Ubuntu: chown -R :www-data .
Set permissions:find . -type d -exec chmod 770 {} \; && find . -type f -exec chmod 660 {} \; && chmod u+x bin/magento If you must enter the commands as sudo
, use:
sudo find . -type d -exec chmod 770 {} \; && sudo find . -type f -exec chmod 660 {} \; && sudo chmod u+x bin/magento
Clear Theme/CSS Cache in Magento 2 Step 1: Clear pub folder and cache
rm -rf pub/static/frontend/* var/view_preprocessed/ var/*cache/* Step 2: Deploy files to pub folder
php bin/magento setup:static-content:deploy
Ngage Studios - Magento Certified Developers
Clear Theme/CSS Cache in Magento 2 Step 1: Clear pub folder and cache
rm -rf pub/static/frontend/* var/view_preprocessed/ var/*cache/* Step 2: Deploy files to pub folder
php bin/magento setup:static-content:deploy
Magento 2 add static block in layout Magento 2 add static block to layout XML
<referenceContainer name="footer-container">
<block class="Magento\Cms\Block\Block" name="footerstaticblock" after="-" >
<arguments>
<argument name="block_id" xsi:type="string">footerstaticblock</argument>
</arguments>
</block>
</referenceContainer> Magento 2 add static block to TEMPLATE
<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();?> Magento 2 add static block to CMS
{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}
Ngage Studios - Magento Certified Developers May 6, 2016
Magento 2 add static block in layout Magento 2 add static block to layout XML
<referenceContainer name="footer-container">
<block class="Magento\Cms\Block\Block" name="footerstaticblock" after="-" >
<arguments>
<argument name="block_id" xsi:type="string">footerstaticblock</argument>
</arguments>
</block>
</referenceContainer> Magento 2 add static block to TEMPLATE
<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();?> Magento 2 add static block to CMS
{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}
Posts navigation