Skip to content

Instantly share code, notes, and snippets.

View 0-Sony's full-sized avatar

Phuong LÊ 0-Sony

View GitHub Profile
@ahmadazimi
ahmadazimi / replace-zero-width-space.php
Last active April 23, 2024 16:20
PHP replace Zero Width Space using preg_replace
<?php
/**
* http://stackoverflow.com/questions/11305797/remove-zero-width-space-characters-from-a-javascript-string
* U+200B zero width space
* U+200C zero width non-joiner Unicode code point
* U+200D zero width joiner Unicode code point
* U+FEFF zero width no-break space Unicode code point
*/
@0-Sony
0-Sony / addProductAttribute.php
Last active July 11, 2019 23:39
Add Custom Attribute for products in custom Attributes set
<!-- local/Namespace/Catalog/data/Namespace_catalog_setup/data-install-0.0.1.php -->
<?php
try {
/* @var $installer Mage_Catalog_Model_Resource_Setup */
$installer = $this;
/**
* Custom attribute creation
@Vinai
Vinai / or-example.php
Last active September 28, 2021 20:48
SearchCriteria OR Example for Magento 2
<?php
declare(strict_types = 1);
namespace Training5\VendorRepository\Controller\Test;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Api\Filter;
use Magento\Framework\Api\FilterBuilder;
@antoinekociuba
antoinekociuba / git-clone-non-empty-directory.sh
Created October 11, 2016 17:19
GIT - Clone into a non-empty directory
git init
git remote add origin PATH/TO/REPO
git fetch
git checkout -t origin/master
@antoinekociuba
antoinekociuba / rsync_media
Last active July 23, 2019 23:30
rsync Magento media folder from a remote server to a local media directory
rsync -avz --dry-run SOURCE DESTINATION
rsync -avz --dry-run SSH_USER@IP:/REMOTE_ASBOLUTE_PATH/media/ media/
--dry-run is to test if everything is fine, always do it first ;p
Remove it then to launch the real action
@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 <phuong.le@agence-soon.fr> <@>
* @category Namespace
* @package Namespace_Core
* @copyright Copyright (c) 2016 Agence Soon (http://www.agence-soon.fr)
*/
@0-Sony
0-Sony / mydate.php
Created April 28, 2017 09:59
Magento 2 : get timestamp of your store time zone and sub/add day
<?php
namespace Namespace\Module\Block;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Framework\View\Element\Template;
class mydate extends Template
@0-Sony
0-Sony / checkout_index_index.xml
Last active October 5, 2021 11:21
Magento 2 : Example Custom Validations JS
<!-- Here you can add your custom validation throught xml -->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="checkout" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
@dannygsmith
dannygsmith / valet-plus-destroy
Last active July 18, 2023 09:07
Remove valet-plus - reboot required
#!/usr/bin/env bash
#styles
VP_NONE='\033[00m'
VP_RED='\033[01;31m'
VP_GREEN='\033[01;32m'
VP_YELLOW='\033[01;33m'
VP_PURPLE='\033[01;35m'
VP_CYAN='\033[01;36m'
VP_WHITE='\033[01;37m'
@0-Sony
0-Sony / CmsBlockInstaller.php
Last active August 10, 2020 12:59
Magento 2 : Create Cms Block Programmatically
<?php
namespace Namespace\Cms\Setup;
use Magento\Cms\Api\BlockRepositoryInterface;
use Magento\Cms\Api\Data\BlockInterface;
use Magento\Cms\Api\Data\BlockInterfaceFactory;
use Magento\Framework\App\State;
use Magento\Framework\App\Area;
use Magento\Framework\Setup\InstallDataInterface;