Skip to content

Instantly share code, notes, and snippets.

View 0-Sony's full-sized avatar

Phuong LÊ 0-Sony

View GitHub Profile
@0-Sony
0-Sony / WebsiteAndStoreCreator.php
Last active June 19, 2024 17:20
Magento 2 : Create Programmatically Website/Store/StoreGroup
<?php
/**
* This file is part of Namespace for Magento.
*
* @license All rights reserved
* @author Phuong LE <[email protected]> <@>
* @category Namespace
* @package Namespace_Core
* @copyright Copyright (c) 2016 Agence Soon (http://www.agence-soon.fr)
*/
@0-Sony
0-Sony / registration.php
Created November 9, 2016 15:54
Magento 2 : Create Theme
<?php
/**
* Copyright © 2016 Soon. All rights reserved.
*/
/** Location : app/code/Namespace/MyModule **/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::THEME,
'frontend/Namespace/MyThemeName',
@0-Sony
0-Sony / use Magento2 Ajusted Tax Amount.php
Created December 2, 2016 16:31
Magento 2 : [Tips] Get Correct Tax Amount
Price Product excluding tax set in BO : 8,25 €
Tax rate : 10 %
For Magento the Tax Amount is 0,83 €
But 8,25 * 10/100 = 0,825 €
The final Price will be 9,08 €
Why Magento return 0,83 € ?
@0-Sony
0-Sony / CmsPageInstaller.php
Created January 2, 2017 15:34
Magento 2 : Create New Cms Page
<?php
/**
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Phuong LE <[email protected]> <@>
* @copyright Copyright (c) 2016 Agence Soon (http://www.agence-soon.fr)
*/
namespace Namespace\Cms\Setup;
use Magento\Cms\Model\Page;
@0-Sony
0-Sony / customerAttributeInstaller.php
Last active July 8, 2023 22:47
Magento 2 : Create Your Own Customer Attribute
<?php
/**
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Phuong LE <[email protected]> <@>
* @copyright Copyright (c) 2016 Agence Soon (http://www.agence-soon.fr)
*/
namespace NameSpace\Customer\Setup;
use Magento\Customer\Api\CustomerMetadataInterface;
@0-Sony
0-Sony / config.xml
Created February 17, 2017 11:25
Disable Native Module Observer
<config>
<frontend>
<events>
<!-- Disable native module observer -->
<your_event_name>
<observers>
<observer_name>
<type>disabled</type>
</observer_name>
</observers>
@0-Sony
0-Sony / DisplayFormatedPrice.php
Last active February 27, 2017 10:58
Magento 2 :Display product Price formatted
<?php
/** Assume you get your product in your block.*/
$product = $this->product;
$finalPrice = $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue();
/** Note for best practice , it's better to call your helper in your block **/
echo $this->helper('Magento\Framework\Pricing\Helper\Data')->currency(number_format($finalPrice,2), true , false);
?>
@0-Sony
0-Sony / LayoutLoadBeforeObserver.php
Last active May 14, 2021 14:21
Magento 2 : Add Body Class using an observer
<?php
/**
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Phuong LE <[email protected]> <@>
* @copyright Copyright (c) 2017 Agence Soon (http://www.agence-soon.fr)
*/
namespace MyVendor\MyModule\Observer;
@0-Sony
0-Sony / createFolderUsingInstaller.php
Last active October 9, 2017 09:05
Magento : create folder using intaller
<?php
try {
/* @var $installer Mage_Core_Model_Resource_Setup */
$installer = $this;
$customDir = Mage::getBaseDir('var') . DS . 'my' . DS . 'awesome' . DS . 'folder';
$ioFile = new Varien_Io_File();
$ioFile->checkAndCreateFolder($customDir);
@0-Sony
0-Sony / date.php
Last active August 22, 2017 16:11
Magento : Use Zend_date based on the Magento Timestamp | Use core Helper to Format Date.
<?php
$time = Mage::getModel('core/date')->timestamp(time());
$date = new Zend_Date($time, Zend_Date::TIMESTAMP);
$subday = 1;
$date->subDay($subday); // -1 day
$date->addDay(1); // +1 day