Skip to content

Instantly share code, notes, and snippets.

@DominicWatts
DominicWatts / Find-Running-PHP
Created February 22, 2020 00:36
Cli : Find Running PHP #CLI
ps -aux | grep '/usr/bin/php'
ps -aux | grep 'php'
ps -aux | grep 'php bin/magento'
@DominicWatts
DominicWatts / Null-coalescing-operator
Created February 22, 2020 00:37
PHP : Null coalescing operator (??) #php
$action = $_POST['action'] ?? 'default';
// The above is identical to this if/else statement
if (isset($_POST['action'])) {
$action = $_POST['action'];
} else {
$action = 'default';
}
@DominicWatts
DominicWatts / Installed-php-modules
Created February 22, 2020 00:37
Cli : Installed php modules #CLI
php -m
@DominicWatts
DominicWatts / magento-2-prices.md
Last active September 12, 2024 15:57
Magento 2 : Prices #magento2

Tier price in phtml

<?php
$priceInfo = $_product->getPriceInfo();
$tierPrices = $priceInfo->getPrice('tier_price')->getTierPriceList();
$productPriceAmount = $priceInfo->getPrice('final_price')->getAmount();
?>
<?php if (count($tierPrices)) : ?>
    <ul class="prices-tier items">
@DominicWatts
DominicWatts / magento 2 file operations
Created February 22, 2020 00:46
Magento 2 : File Operations #magento2
\Magento\Framework\Filesystem\Io\File
public function __construct(
\Magento\Framework\Filesystem\Io\File $file
) {
$this->file = $file;
}
public function streamRead($length = 1024)
public function streamReadCsv($delimiter = ',', $enclosure = '"')
@DominicWatts
DominicWatts / magento-2-fetching-config
Created February 22, 2020 00:53
Magento 2 : Fetching config #magento2
const XML_PATH_EMAIL_COPY_TO = 'sales_email/order/copy_to';
$data = $this->getConfigValue(
self::XML_PATH_EMAIL_COPY_TO, $this->getStore()->getStoreId()
);
protected $_scopeConfig;
/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
*/
@DominicWatts
DominicWatts / Magento __("") string
Last active September 12, 2024 13:53
Magento 2 : __('') string #magento2
use Symfony\Component\Console\Output\OutputInterface
OutputInterface $output
$this->output = $output;
$this->output->writeln((string) __(
'[%1] Order Invoiced order <info>%2 : %3<info>',
date('Y-m-d H:i:s'),
$order->getId(),
$order->getIncrementId())
@DominicWatts
DominicWatts / magento 2 permissions developer and default mode
Last active September 12, 2024 15:52
Magento 2 : permissions develop and default mode #magento2
echo 002 > magento_umask
775 for directories
664 for files
echo 022 > magento_umask
755 for directories
644 for files
@DominicWatts
DominicWatts / magento-2-cron
Created February 22, 2020 01:06
Magento 2 : Cron #magento2
*/5 * * * * /opt/cpanel/ea-php71/root/usr/bin/php ~/public_html/bin/magento cron:run >/dev/null 2>&1
*/5 * * * * /opt/cpanel/ea-php71/root/usr/bin/php ~/public_html/update/cron.php >/dev/null 2>&1
*/5 * * * * /opt/cpanel/ea-php71/root/usr/bin/php ~/public_html/bin/magento setup:cron:run >/dev/null 2>&1
*/5 * * * * /opt/cpanel/ea-php71/root/usr/bin/php ~/public_html/bin/magento cron:run >> ~/public_html/var/log/cron.log
*/5 * * * * /opt/cpanel/ea-php71/root/usr/bin/php ~/public_html/update/cron.php >> ~/public_html/var/log/update.cron.log
*/5 * * * * /opt/cpanel/ea-php71/root/usr/bin/php ~/public_html/bin/magento setup:cron:run >> ~/public_html/var/log/setup.cron.log
@DominicWatts
DominicWatts / magento-2-get-store-information
Created February 22, 2020 01:11
Magento 2 : Get store information #magento2
class HelloWorld extends \Magento\Framework\View\Element\Template
{    
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,        
        array $data = []
    ) {            
        parent::__construct($context, $data);
    }
/**