Skip to content

Instantly share code, notes, and snippets.

@kmddevdani
kmddevdani / createProduct.php
Last active January 26, 2020 12:50
Trying out product creation for Magento2
<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
@kmddevdani
kmddevdani / code_runtime_measurement.php
Last active August 8, 2018 01:57
measure and log code runtime
<?php
class my_class {
private $_timerId = [];
private function startTimer($timerId) {
$this->_timerId[$timerId]['start'] = microtime(true);
}
private function stopTimer($timerId) {
@kmddevdani
kmddevdani / magento2_customers_with_addresses_without_city.sql
Created July 30, 2018 21:57
magento2 find customers with at least 3 addresses, at least one of which is without city
select
count(*) addresses,
ce.entity_id,
email
from customer_address_entity cae
join customer_entity ce ON cae.parent_id = ce.entity_id
where ce.is_active = 1
and cae.city = ''
group by ce.entity_id
having addresses > 2 -- delete this line, if you also want to show customers that have only one address
@kmddevdani
kmddevdani / magento2_update_store_specific_product_attributes.php
Created May 27, 2018 21:33
magento2 update product attributes, store-specific
<?php
/**
* Sets different values for an attribute, depending on the store.
*
* This example sets the hs code attribute of product 123 to 111111 for the UK and 222222 for AU.
*/
$storeIdUK = 1;
$storeIdAU = 2;
@kmddevdani
kmddevdani / magento2_add_simple_to_configurable_product.php
Last active May 21, 2018 03:33
Magento2: Add a simple product to a configurable product
<?php
class ProductManager implements ProductManagerInterface
{
/**
* @var \Magento\Catalog\Api\ProductRepositoryInterface
*/
private $prodRep;
public function __construct()
@kmddevdani
kmddevdani / createChroot.sh
Created October 5, 2017 00:17
Creates chrooted user with real scp and ssh access on a amazon linux ec2 instance
#!/bin/bash
#
# This script creates a chrooted user, scp enabled, on an Amazon Linux aws instance
#
# 2017-10-05
#
# change username and password here:
username="abc"