Skip to content

Instantly share code, notes, and snippets.

View Luxato's full-sized avatar
🎯
Focusing

Lukas S. Luxato

🎯
Focusing
  • Denmark
View GitHub Profile
@Luxato
Luxato / guzzle_pool_example.php
Created February 23, 2022 12:28 — forked from wzed/guzzle_pool_example.php
GuzzleHttp\Pool example: identifying responses to concurrent async requests
<?php
/*
* Using a key => value pair with the yield keyword is
* the cleanest method I could find to add identifiers or tags
* to asynchronous concurrent requests in Guzzle,
* so you can identify which response is from which request!
*/
$client = new GuzzleHttp\Client(['base_uri' => 'http://httpbin.org']);
@Luxato
Luxato / concurrent-pool.php
Created February 22, 2022 13:08 — forked from fgilio/concurrent-pool.php
Laravel HTTP client concurrent requests pool
<?php
// 1. Register the routes
Route::get('test/{lorem}', function ($lorem) {
sleep(3);
return response()->json([
'message' => $lorem,
'token' => Str::random(),
]);
@Luxato
Luxato / index.php
Last active August 20, 2021 11:39
Magento 1 get profiler ordered by elapsed time
<?php
/*
* Don't forget that in order for profiler to work it has to be enabled, else you will get empty profiles.
*/
$profiler = Mage::getSingleton('core/resource')->getConnection('core_write')->getProfiler();
$queryProfiles = $profiler->getQueryProfiles();
$profiles = [];
@Luxato
Luxato / lukas.php
Created February 10, 2021 14:53
Magento 1 - How to add attribute to the attribute set
<?php
require_once 'app/Mage.php';
Mage::app();
$attributeSetName = 'Electric scooters'; // Name of the attribute set
//$groupName = 'Frontend';
$code = 'my_attribute_code';
try {
@Luxato
Luxato / index.php
Last active January 11, 2021 14:51
Magento 1 join collection with table created by subquery
<?php
$productCollection->getSelect()->join(
new Zend_Db_Expr("(SELECT product_id, SUM(impressions) as impressions, SUM(clicks) as clicks, SUM(cart) as cart, SUM(conversions) as conversions, round(SUM(profit), 2) as profit, round(SUM(profit)/SUM(impressions), 3) as rpi
FROM evermart_crosssells_statistics_daily" .
($dateFilter ? " WHERE $dateFilter" : "")
. " GROUP BY product_id)"),
't.product_id = e.entity_id',
array('t.impressions','t.clicks', 't.cart', 't.conversions', 't.profit', 't.rpi')
);
@Luxato
Luxato / sql.sql
Last active January 20, 2022 08:37
Add datetime that updates on update
ALTER TABLE `table_name`
ADD `updated_at` datetime NULL DEFAULT now() on update now();
@Luxato
Luxato / sort.js
Created November 18, 2020 11:57
Sort table by arbitrary column with javascript
function sortTable(table, col, reverse) {
var tb = table.tBodies[0],
tr = Array.prototype.slice.call(tb.rows, 0),
i;
reverse = -((+reverse) || -1);
tr = tr.sort(function (a, b) {
return reverse
* (a.cells[col].textContent.trim()
.localeCompare(b.cells[col].textContent.trim())
);
@Luxato
Luxato / index.php
Created November 5, 2020 12:50
Magento working with time
<?php
date_default_timezone_set(Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE));
$currentShopTime = date('Y-m-d H:i:s');
@Luxato
Luxato / getChildrenConfProducts.php
Last active August 17, 2020 08:17
Get Children Configurable Products
<?php
$product = Mage::getModel('catalog/product')
->load(11925);
$children = $product->getTypeInstance()->getUsedProducts($product);
$children_ids = [];
foreach ($children as $child){
$children_ids[] = $child->getID();
}
@Luxato
Luxato / getChildrenBundleProducts.php
Last active August 17, 2020 07:57
Magento 1 get Bundle product children qty
<?php
$product = Mage::getModel('catalog/product')
->load(9275);
$collection = $product->getTypeInstance(true)
->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product);
$children_ids = [];