Skip to content

Instantly share code, notes, and snippets.

View khnaim's full-sized avatar

Khadija NAIM khnaim

View GitHub Profile
@khnaim
khnaim / mysql-docker.sh
Created September 10, 2021 07:32 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@0-Sony
0-Sony / call-custom-js-everywhere.js
Last active September 6, 2024 06:42
Magento 2 : Work around JS : Call a js file using requireJs or call a js file before another one or override existing js method
/**
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Phuong LE <sony@menincode.com> <@>
* @copyright Copyright (c) 2018 Menincode (http://www.menincode.com)
*/
/** MyNamespace/MyModule/view/frontend/web/js/call-custom-js-everywhere.js */
/** check the requirejs-config.js file */
@peterjaap
peterjaap / swatch_attribute_options.php
Created November 28, 2017 13:03
Helper functions for product import in Magento 2 to create swatch attribute options
<?php
/**
* @param $attributeCode
* @param $newOptionValues
* @internal param $attributeData
*/
public function addSwatchValuesToSwatchAttribute($attributeCode, $newOptionValues)
{
$this->eavConfig->clear();
@luisfc
luisfc / install nodejs, npm and gulp
Last active October 3, 2020 16:37
Install nodejs, npm and gulp ubuntu 16.04
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
## Use n module from npm in order to upgrade node
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
@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)
*/
@Nav-Appaiya
Nav-Appaiya / gist:892d759c1749fb9241ce169afe213f68
Created September 6, 2016 08:55
Magento 2 get all attributes from the default products attribute set (id: 4)
<?php
/** @var $coll \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection */
$coll = $this->_objectManager->create(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection::class);
// add filter by entity type to get product attributes only
// '4' is the default type ID for 'catalog_product' entity - see 'eav_entity_type' table)
// or skip the next line to get all attributes for all types of entities
$coll->addFieldToFilter(\Magento\Eav\Model\Entity\Attribute\Set::KEY_ENTITY_TYPE_ID, 4);
$attrAll = $coll->load()->getItems();
@PGBI
PGBI / .profile
Last active November 25, 2020 20:43
`vagrant halt all` command to halt all running vagrant VMs
# To be pasted in ~/.profile
vagrant() {
if [[ $@ == "halt all" ]]; then
command vagrant global-status | grep running | colrm 8 | xargs -L 1 -t vagrant halt
else
command vagrant "$@"
fi
}

Magento Snippets

Add Attribute Group and Attributes to Attribute Sets

In an install script, you can follow the below example:

<?php
/**
 * Pan_JewelryDesigner Extension
@spalladino
spalladino / mysql-docker.sh
Created December 22, 2015 13:47
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@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;