Skip to content

Instantly share code, notes, and snippets.

View antoinekociuba's full-sized avatar

Antoine Kociuba antoinekociuba

View GitHub Profile
@antoinekociuba
antoinekociuba / start_es_docker_container.sh
Last active October 7, 2020 15:22
Start an ElasticSearch container, with specific version and storage location
docker run -d --restart=unless-stopped --name=container_name_elasticsearch -p 123456:9200 -e "discovery.type=single-node" -v /home/www/project/.es_data:/usr/share/elasticsearch/data elasticsearch:7.6.2
@antoinekociuba
antoinekociuba / search_string_in_files.sh
Created October 7, 2020 15:18
Search a specific string in files ('toto.log' in below example)
grep -rnw '/var/www/project/vendor/' -e 'toto.log'
@antoinekociuba
antoinekociuba / m2_clean_product_eav_values.sql
Created November 10, 2019 02:12
Magento 2 - Clean product EAV values (zombie product values, even if attribute(s) is/are not on concerned attribute set(s) anymore). Inspiration from https://github.com/magento/data-migration-tool/issues/598
CREATE TABLE catalog_product_entity_int_old LIKE catalog_product_entity_int;
INSERT INTO catalog_product_entity_int_old SELECT * FROM catalog_product_entity_int;
DELETE FROM catalog_product_entity_int
WHERE value_id IN
(SELECT cpei.value_id
FROM catalog_product_entity_int_old cpei
WHERE cpei.attribute_id NOT IN
(SELECT eea.attribute_id
FROM eav_entity_attribute eea
@antoinekociuba
antoinekociuba / delete_merged_git_branches_remotely
Last active May 14, 2024 05:38
Delete all merged branches from the remote Git repository (assuming master is the main branch)
# Sources: https://community.atlassian.com/t5/Bitbucket-questions/Is-there-a-way-to-delete-branches-in-bulk/qaq-p/547331
# Make sure remotes are up to date (with stale remotes purged):
git fetch -p
# Initial no-op run --- do the branches to delete look correct?
# Be careful to omit 'master' from the output.
git branch --remote --merged origin/master | grep -v 'master' | cut -b 10- | xargs
# Do the bulk delete!!! (can take a long time...)
@antoinekociuba
antoinekociuba / git_assume_unchanged
Last active July 23, 2019 23:29
Make modification/deletion on a file not visible by Git, even if this file is under version control
git update-index --assume-unchanged media/downloadable/.htaccess
@antoinekociuba
antoinekociuba / m2_get_products_data.sql
Last active November 9, 2022 21:52
Magento 2 - Retrieve some products data (name, price, stock qty, images, categories...) from SQL query. On Magento Commerce versions, you will have to replace `entity_id` by `row_id`.
SELECT e.entity_id AS 'id',
v1.value AS 'name',
e.sku,
d1.value AS 'price',
si.qty AS 'qty',
t1.value AS 'short_description',
t2.value AS 'description',
v2.value AS 'image',
v3.value AS 'thumbnail',
mg.value AS 'media_gallery',
@antoinekociuba
antoinekociuba / category_trees_per_product.php
Last active February 24, 2022 09:53
Magento 1 - Get array of all category trees for a given product
<?php
// Get all product category IDs
$categoryIds = $product->getCategoryIds();
// Get category trees, filtered by product category IDs
$helper = Mage::helper('catalog/category');
$categoryTreeCollection = $helper->getStoreCategories('path', true, false);
$categoryTreeCollection->addAttributeToFilter('entity_id', ['in' => $categoryIds]);
@antoinekociuba
antoinekociuba / add-checkout-form-key.sh
Last active June 19, 2017 20:17 — forked from grafikchaos/add-checkout-form-key.sh
Magento SUPEE-9767 Checkout Form Key Theme Patch
find -L app/design/frontend -name 'shipping.phtml' -or -name 'billing.phtml' -or -name 'shipping_method.phtml' -or -name 'payment.phtml' -or -name 'addresses.phtml' \
| xargs grep -L formkey \
| xargs perl -i -pe 's/<\/form>/<?php echo \$this->getBlockHtml("formkey") ?>\n<\/form>/g'
find -L skin/frontend -name 'opcheckout.js' \
| xargs grep -L form_key \
| xargs perl -i -pe 's/if \(elements\[i\]\.name=='\''payment\[method\]'\''\) \{/if (elements[i].name=='\''payment[method]'\'' || elements[i].name == '\''form_key'\'') {/g'
find -L js -name 'payment.js' \
@antoinekociuba
antoinekociuba / .gitignore_magento
Created April 25, 2017 14:25 — forked from herveguetin/.gitignore_magento
Magento .gitignore example
######################
# Magento .gitignore #
######################
# Magento Core unnecessary files #
##################################
/errors/local.xml
/index.php
/install.php
/mage
@antoinekociuba
antoinekociuba / define_root_folder_after_ssh.sh
Last active April 11, 2017 12:10
Vagrant quickies - Go to project root folder or specific folder after SSH connexion
#!/bin/bash
echo "cd /var/www/magento" >> /home/vagrant/.bashrc