Skip to content

Instantly share code, notes, and snippets.

@6ui11em
6ui11em / print_collection_sql.php
Created July 4, 2018 09:56
Magento 2 print collection SQL #magento2 #sql #debug
$collection->load();
// the following statements are equivalent
$collection->getSelect()->assemble();
$collection->getSelect()->__toString();
echo $collection->getSelect();
@6ui11em
6ui11em / customer_logged_in.php
Created July 17, 2018 14:04
Magento 2: Check if customer is logged in #magento2 #cache #customer
// To avoid problems with full page cache
// https://github.com/magento/magento2/blob/4d2609343a950e9ee6b50cc4444469d50d82b139/app/code/Magento/Customer/Block/Account/Customer.php#L52
public function customerLoggedIn()
{
return (bool)$this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
}
@6ui11em
6ui11em / console_dir.js
Created July 31, 2018 21:30
Javascript console log element DOM #javascript #log #console
console.dir(document.body);
@6ui11em
6ui11em / remove-top_links.xml
Created August 28, 2018 10:48
Magento 2: Remove top links #magento2 #layout #toplinks #remove
@6ui11em
6ui11em / copyright.phtml
Last active December 29, 2022 22:16
Magento 2: Dynamic copyright year in footer #magento2 #copyright #year
@6ui11em
6ui11em / sibilings.js
Created September 4, 2018 20:17
Javascript get siblings og an element #javascript #vanilla #sibilings
var item = document.querySelector('#find-me');
var prev = item.previousElementSibling;
var next = item.nextElementSibling;
@6ui11em
6ui11em / delete-tag.sh
Last active June 9, 2021 13:48
Git delete / update remote tag #git #tag #tagname #delete #modify #update
#Delete remote tag
git push --delete origin <tag>
#Move tag
git tag --force v1.0 <ID-of-commit-127>
git push --force --tags
@6ui11em
6ui11em / change_git_commit_message.sh
Created October 26, 2018 21:10
Git change last commit message #git #command #message
git commit --amend
@6ui11em
6ui11em / magento2_get_config_value.php
Created October 31, 2018 14:53
Magento 2 get config value #magento2 #config #core_config
/* Constructor */
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
$this->scopeConfig = $scopeConfig
/* Use */
$this->scopeConfig->getValue('dev/debug/template_hints', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
@6ui11em
6ui11em / remove_array_duplicates.js
Created January 11, 2019 09:04
Javascript remove array duplicates #javascript #js #array #duplicates
var sandwiches = ['turkey', 'ham', 'turkey', 'tuna', 'pb&j', 'ham', 'turkey', 'tuna'];
var deduped = sandwiches.filter(function (sandwich, index) {
return sandwiches.indexOf(sandwich) === index;
});
// Logs ["turkey", "ham", "tuna", "pb&j"]
console.log(deduped);