Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View peterjaap's full-sized avatar

Peter Jaap Blaakmeer peterjaap

  • elgentos ecommerce solutions / Blaakmeer Webdevelopment
  • Groningen, the Netherlands
View GitHub Profile
@peterjaap
peterjaap / ConditionalSpecialPrice.php
Last active February 19, 2023 10:48
Wyomind Data Feed Manager conditional special price - this custom attribute for Wyomind Data Feed Manager only shows the special price when the special price is set lower than the original price.
<?php
if($product->getSpecialPrice() && $product->getSpecialPrice() > 0 && $product->getSpecialPrice() < $product->getPrice()) {
$specialPriceInclTax = Mage::helper('tax')->getPrice($product, $product->getSpecialPrice(), true);
$conditionalSpecialPrice = '<g:sale_price>' . $specialPriceInclTax . '</g:sale_price>' . PHP_EOL;
$specialFromDate = $product->getSpecialFromDate();
$specialToDate = $product->getSpecialToDate();
if($specialFromDate && !$specialToDate) {
$specialToDate = '2100-01-01';
}
if($specialToDate && !$specialFromDate) {
@peterjaap
peterjaap / attachToWebsite.sql
Created September 24, 2014 12:27
Magento SQL query to attach products that are not added to a website to the default website (id 1)
INSERT INTO catalog_product_website
(product_id, website_id)
(SELECT catalog_product_entity.entity_id, '1'
FROM catalog_product_entity LEFT JOIN catalog_product_website ON catalog_product_entity.entity_id = catalog_product_website.product_id
GROUP BY catalog_product_entity.entity_id
HAVING COUNT(catalog_product_website.product_id) = 0
ORDER BY sku DESC)
@peterjaap
peterjaap / 1_product_queries.sql
Last active November 15, 2022 18:43 — forked from itris/1_product_queries.sql
Magento 2 - Remove duplicate store view-specific product and category data
/*
* IMPORTANT: The queries below are written for Magento Community. If you're going to run them on Magento Enterprise (Adobe Commerce), you need
* to replace all instances of ".entity_id" with ".row_id". See this for context: http://magento.stackexchange.com/questions/139740/magento-2-schema-changes-for-ee-catalog-staging
*
* When importing products in Magento 2, if you specify store view codes in the store_view_code column, product data will be set at
* both the global scope as well as the specific store view scope. This is not ideal because now you have duplicate
* data at two different scopes that shouldn't actually be duplicated. The scripts below clean up this data by finding
* data set at specific store view scopes and if it's an exact match to the data set at the global store view, then it
* deletes the data set at the specific store view scope.
*
@peterjaap
peterjaap / server.security-txt
Last active November 13, 2022 19:10
Nginx rules for security.txt on Hypernode
# ~/nginx/server.security-txt
# Make Magento 2.4.x's security.txt available to the world
rewrite ^/.well-known/security.txt$ /securitytxt/index/securitytxt last;
rewrite ^/security.txt$ /securitytxt/index/securitytxt last;
@peterjaap
peterjaap / fix-order-invoice-confirmation-email-item-grid.sql
Last active November 9, 2022 19:35
These queries fix the order item list in customized order/invoice email templates. Basically you need to change order to order_id and invoice to invoice_id and add area="frontend" if it's not set. Check whether you need to fix it with the SELECT queries, run the UPDATE queries to fix them.
SELECT COUNT(*) FROM email_template WHERE template_text LIKE '%order=%';
SELECT COUNT(*) FROM email_template WHERE template_text LIKE '%invoice=%';
SELECT COUNT(*) FROM email_template WHERE template_text LIKE '%sales_email_order_items%' AND template_text NOT LIKE '%area="frontend"%';
SELECT COUNT(*) FROM email_template WHERE template_text LIKE '%sales_email_order_invoice_items%' AND template_text NOT LIKE '%area="frontend"%';
UPDATE email_template SET template_text = REPLACE(template_text, "order=$order", "order_id=$order_id") WHERE template_text LIKE '%order=%';
UPDATE email_template SET template_text = REPLACE(template_text, "invoice=$invoice", "invoice_id=$invoice_id") WHERE template_text LIKE '%invoice=%';
UPDATE email_template SET template_text = REPLACE(template_text, 'handle="sales_email_order_items"', 'area="frontend" handle="sales_email_order_items"') WHERE template_text LIKE '%sales_email_order_items%' AND template_text NOT LIKE '%area="frontend"%';
UPDATE email_template SET template_text = REPLACE
@peterjaap
peterjaap / checkTables.php
Last active November 9, 2022 07:46
Quick & dirty script to check for existence of Magento (2) table names in codebase
<?php
$tables = shell_exec('magerun2 db:query "SHOW TABLES"');
$tables = array_filter(explode(PHP_EOL, $tables), function ($table) {
if (empty($table)) return false;
if (substr($table, -3) === '_cl') return false;
if (substr($table, -8) === '_replica') return false;
if (stripos($table, '_flat_') !== false) return false;
if (stripos($table, '_fulltext_') !== false) return false;
if (stripos($table, 'sequence_') !== false) return false;
return true;
@peterjaap
peterjaap / magento-testing-scenarios.md
Last active October 17, 2022 10:16
Magento testing scenarios

Magento testing scenarios

For use after an upgrade to verify the correct working of Magento

SHIP IT

Frontend

General

  • Activate all logs on the server (PHP, MySQL, Magento, mail, etc)
  • Check meta tags in HTML
@peterjaap
peterjaap / magento_postman_collection.json
Created November 18, 2016 11:28
Postman request collection for Magento 1 SOAP v2
{
"id": "6b940a31-113d-109f-f36a-75c1604ef7d4",
"name": "ExampleShop",
"description": "",
"order": [
"2658e264-981e-4786-7f05-88f3fce0f4e6",
"8c81cf7c-e188-b8bd-0970-a96aa3a8d6a3",
"a1e3c72f-6fde-d46b-7896-e1627f7e5f64",
"c050284d-14bd-bdd6-256e-30111f354ef6",
"3b0ac9f0-3544-4797-fd4f-56b436ecd029",
@peterjaap
peterjaap / fitchef-to-myfitnesspal.user.js
Created September 12, 2022 18:15
Fitchef to MyFitnessPal Greasemonkey script
// ==UserScript==
// @name Fitchef to MyFitnessPal
// @version 0.1
// @description Voeg link toe aaan Fitchef.nl om een recept aan MyFitnessPal toe te voegen
// @author Peter Jaap Blaakmeer
// @match https://fitchef.nl/weekschema/*/*
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// ==/UserScript==
@peterjaap
peterjaap / clean-core-config-data-duplicate-values.sql
Last active June 7, 2022 08:49
Delete core_config_data values where the fallback value in scope 0 is the same
DELETE FROM core_config_data WHERE config_id IN (SELECT config_id
FROM (SELECT DUPS.*
FROM core_config_data ORIG
LEFT JOIN core_config_data DUPS
ON ORIG.path = DUPS.path AND (ORIG.value = DUPS.value OR (ORIG.value IS NULL AND DUPS.value IS NULL))
AND DUPS.scope != "default" AND DUPS.scope_id != 0
WHERE ORIG.scope = "default"
AND ORIG.scope_id = 0
AND DUPS.path IS NOT NULL) as tmp)