Skip to content

Instantly share code, notes, and snippets.

@Alexander-Pop
Alexander-Pop / cms_page_view_selectable_about-us_AboutUs.xml
Created June 27, 2022 01:52
Magento2 - Add Custom Layout Update for a specific Cms Page #layout #magento2
<?xml version="1.0" encoding="UTF-8" ?>
<!--
pattern xml file name : cms_page_view_selectable_<CMS Page Identifier>_<Layout Update Name>.xml
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="\Vendor\AboutUS\Block\Custom" name="vendor.about-us.custom" template="Vendor_AboutUs::custom-template.phtml" before="-"/>
</referenceContainer>
@Alexander-Pop
Alexander-Pop / magentoUpdateFromSelectSql.php
Created June 27, 2022 01:50
Magento2 - updateFromSelect SQL #sql #magento2 #db #database
<?php
/** Quick Example how to use updateFromSelect in Magento 2 */
$this->connection = $this->resourceConnection->getConnection();
$this->someTable = 'some_table';
$this->tmpTableName = 'tmp_table';
$condition = 'ft.' . MyInterface::CRM_ID . ' = tmp.' . MyInterface::CRM_ID;
$condition .= ' AND ft.' . MyInterface::CODE . ' = tmp.' . MyInterface::CODE;
@Alexander-Pop
Alexander-Pop / PaymentInformationManagementPlugin.php
Created June 26, 2022 18:21
Magento2 - Alter the payment methods list in checkout #checkout #magento2 #plugin
<?php
namespace MyNamespace\MyModule\Plugin\Model;
class PaymentInformationManagementPlugin
{
/**
* Here is an example how you can alter the payment methods list in the checkout.
* Remove free and checkmo payment methods in the checkout
@Alexander-Pop
Alexander-Pop / checkout_index_index.xml
Last active June 26, 2022 18:23
Magento 2 - Form Custom Validations - Frontend #magento2 #validation #checkout
<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">
<item name="shipping-step" xsi:type="array">
@Alexander-Pop
Alexander-Pop / greatLogger.php
Last active June 22, 2022 16:13
PHP - custom Logging
<?php
// $this->logger = new Logger();
// $this->logger->setLogFile('admin.log');
// $this->logger->setTextBefore('user: '.$this->getUser()->getIdentity()->username);
// $this->logger->log($log);
class Logger {
private $logFile = 'logfile.log';
@Alexander-Pop
Alexander-Pop / DrupalSetAndGetFieldValueInTwigTemplate.txt
Last active December 21, 2021 14:15
Drupal Set and Get the raw field value in a twig template #drupal8 #d8 #twig
{{ entity.field_name.value }} to get the true raw value, includes tags and encoding.
Example: {{ node.body.value }}
result: <p>Batman &amp; Robin</p>
{{ content.field_name.0 }} to get the raw value minus tags and encoding.
Example: {{ content.body.0 }}
result: Batman & Robin
{% set parp_state = participating_state_1|render|striptags|trim|lower %}
@Alexander-Pop
Alexander-Pop / parallax-playground.js
Created November 19, 2021 04:39
Play with Parallax #parallax #js $jq #animation
const main = {};
const updateScroll = () => {
main.winScroll = $(window).scrollTop();
};
const parallaxLoad = () => {
const $someEl = $('.someEl');
$someEl.each((i,el) => {
let $el = $(el);
main.someEl[i] = $el;
});
@Alexander-Pop
Alexander-Pop / jQuery-Validate-Min-and-Max-Length-of-Input-Field-no-plugin.html
Last active October 26, 2021 09:10
jQuery - Validate Min and Max Length of Input Field #jquery #form #validate
<input type="text" id="name"/>
<p id="warning></p>
@Alexander-Pop
Alexander-Pop / Find-element-in-an-array-with-JavaScript.js
Last active October 26, 2021 09:04
Find element in an array with JavaScript #javascript #array
let charts = {
curationstate: "Curation State",
modellingapproach: "Modelling Approach",
organism: "Organism",
journal: "Journal"
};
// Note: the three equal signs so that null won't be equal to undefined
if (charts["curationstate"] === undefined) {
// do something
@Alexander-Pop
Alexander-Pop / onclick-add-parameter.js
Last active June 28, 2021 16:03
Jquery - onclick add parameter to url of other element #jquery #click
$("#classdemo-about img").click(function(){
//console.log('yes');
$('.btn-primary').attr('href', function() {
var vpar = '?vid=1';
if (this.href.indexOf(vpar) == -1) {
return this.href + vpar;
}
});
})