Skip to content

Instantly share code, notes, and snippets.

View adamzero1's full-sized avatar

Adam adamzero1

View GitHub Profile
@adamzero1
adamzero1 / incorrect_store_id_for_admin_orders.patch
Created August 4, 2020 14:14
Wrong Store Id when creating order in admin, with single store.
--- Model/Session/Quote.php 2020-08-04 13:55:36.438626071 +0000
+++ Model/Session/Quote.php 2020-08-04 13:56:16.990487672 +0000
@@ -134,7 +134,7 @@
$cookieMetadataFactory,
$appState
);
- if ($this->_storeManager->hasSingleStore()) {
+ if ($this->_storeManager->isSingleStoreMode()) {
$this->setStoreId($this->_storeManager->getStore(true)->getId());
}
@adamzero1
adamzero1 / double_decrementing_stock_on_shipment.patch
Last active August 26, 2021 19:52
Magento doule decrementing stock when shipping orders
--- Model/GetItemsToDeductFromShipment.php 2020-11-26 10:23:56.827000000 +0000
+++ Model/GetItemsToDeductFromShipment.php 2020-11-26 10:22:50.741302876 +0000
@@ -17,6 +17,7 @@
use Magento\Sales\Model\Order\Item as OrderItem;
use Magento\Sales\Model\Order\Shipment;
use Magento\Sales\Model\Order\Shipment\Item;
+use Magento\CatalogInventory\Api\StockConfigurationInterface;
/**
* Get source items for deduction class.
@adamzero1
adamzero1 / Magento 2 Environment Variable.md
Created February 12, 2021 11:19
A description of the environment variables for Magento 2

MAGE_RUN_TYPE

  • Possible Values: store,website (string)
  • Version Constraints: 2.* CE, 2.* EE The scope the current request should be running as

MAGE_RUN_CODE

  • Possible Values: (string)
  • Version Constraints: 2.* CE, 2.* EE Website/Store (depending on MAGE_RUN_TYPE) code for the current request You can use admin for admin.
@adamzero1
adamzero1 / export_out_of_memory_issue.patch
Last active March 16, 2021 13:45
Export Out Of Memory
--- Model/Export/Product.php 2021-03-16 13:35:33.809000000 +0000
+++ Model/Export/Product.php 2021-03-16 13:36:09.819832268 +0000
@@ -949,8 +949,9 @@
$productIds = array_keys($rawData);
$stockItemRows = $this->prepareCatalogInventory($productIds);
+ $entityCollection = clone $this->_getEntityCollection();
$this->rowCustomizer->prepareData(
- $this->_prepareEntityCollection($this->_entityCollectionFactory->create()),
+ $entityCollection,
@adamzero1
adamzero1 / evaluate_redis_size.php
Last active September 15, 2021 15:23
Magento 2 Redis Key Sizes
<?php
require realpath(__DIR__) . '/app/bootstrap.php';
class RedisCustom extends Credis_Client {
private static function _prepare_command($args)
{
return sprintf('*%d%s%s%s', count($args), CRLF, implode(array_map(array('self', '_map'), $args), CRLF), CRLF);
}
@adamzero1
adamzero1 / show_store_label_for_attribute_option_by_option_code.sql
Last active January 10, 2022 08:46
Show store label for attribute option, by option_code
select ea.attribute_code,
ea.frontend_label,
oc.option_id,
oc.attribute_id,
oc.option_code,
eaov.value_id,
eaov.store_id,
eaov.value from option_code as oc
left join eav_attribute_option_value as eaov on oc.option_id = eaov.option_id
left join eav_attribute as ea on oc.attribute_id = ea.attribute_id
@adamzero1
adamzero1 / README.md
Last active February 23, 2022 10:26
Fix broken Magento2 install

Description

Sometimes when running composer install for Magento 2 depending on your current directory structure the Magento composer plugin does not extract/copy the files out of vendor. Which leaves you with a broken installation.

How to run

curl -s https://gist.githubusercontent.com/adamzero1/0eb6d3e14078676a3ba589d77ba67b3d/raw/6ed67290b6eca7211942d1363ab6115eefd590a6/fix | bash
@adamzero1
adamzero1 / README.md
Last active March 9, 2022 20:27
Magento MySQL Santized Backup

Run sanitized backup

curl https://gist.githubusercontent.com/adamzero1/90e577229cbfb5907822b50daa7baf37/raw/85aa792ea563418fb9da2dee1fba1fa7669e7bd1/backup.sh | bash
@adamzero1
adamzero1 / analyse_magento_var_directory.php
Created May 12, 2022 11:00
Analyse Magento var directory
<?php
use Magento\Setup\Module\I18n\Parser\Parser;
if(!is_file('bin/magento')){
echo 'Unable to find "bin/magento", this needs to be ran from the root of the project.'.PHP_EOL;
return 1;
}
define('REPORT_WIDTH', 200);
@adamzero1
adamzero1 / magento_cron_job_run_times.sql
Created August 9, 2022 12:25
Report on average,min and max run time (in seconds) of all completed jobs in Magento 2
select job_code,
avg(timestampdiff(second, executed_at, finished_at)) as average_run_time,
min(timestampdiff(second, executed_at, finished_at)) as min_run_time,
max(timestampdiff(second, executed_at, finished_at)) as max_run_time
from cron_schedule where executed_at is not null and finished_at is not null group by job_code order by max(timestampdiff(second, executed_at, finished_at)) desc;