Skip to content

Instantly share code, notes, and snippets.

@Alexander-Pop
Alexander-Pop / AttributeManagement.php
Created June 27, 2022 02:00
Magento 2 - change attribute type to Visual Swatch / Visual Text and add swatch options Ids #magento2 #attribute #interface
<?php
declare(strict_types=1);
namespace MyNamespace\Catalog\Model;
use Dnd\Catalog\Api\AttributeManagementInterface;
use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Eav\Api\AttributeRepositoryInterface;
use Magento\Eav\Api\Data\AttributeInterface;
@Alexander-Pop
Alexander-Pop / di.xml
Last active June 27, 2022 02:42
Magento 2 : expose Custom Store Configuration to graphQL #magento2 #graphql
<!-- etc/graphql/di.xml -->
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider">
<arguments>
<argument name="extendedConfigData" xsi:type="array">
<item name="custom_foo_config" xsi:type="string">mynamespace_mymodule/general/custom_foo_config</item>
</argument>
@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>