Skip to content

Instantly share code, notes, and snippets.

View garyconstable's full-sized avatar
🏠
Working from home

Gary Constable garyconstable

🏠
Working from home
View GitHub Profile
@garyconstable
garyconstable / readme.md
Created December 30, 2018 22:06
Find Raspberry PI address on local network

All raspberry devices MAC addresses started with B8:27:EB

arp -na | grep -i b8:27:eb

Read more on: stackoverflow

@garyconstable
garyconstable / README.MD
Created December 20, 2018 10:01
Magento 2 - Get store Phone Number

How to get the store phone number

https://magento.stackexchange.com/questions/125354/how-to-get-store-phone-number-in-magento-2
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeInformation = $objectManager->create('Magento/Store/Model/Information');
$storeInfo = $storeInformation->getStoreInformationObject($store);
@garyconstable
garyconstable / README.MD
Created December 20, 2018 09:50
Magento 2 - Product Stock

Get Product stock

<?php 
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');
    echo $StockState->getStockQty($product->getId(), $product->getStore()->getWebsiteId());
?>
@garyconstable
garyconstable / README.MD
Created December 6, 2018 12:33
Magento - before, during, after
<?php

namespace Kodal\BindingShape\Plugin;

if(!function_exists("d")){
  function d($data = array(), $die = true){
    echo '<pre>'.print_r($data, true).'</pre>';
    if($die){
      die();
@garyconstable
garyconstable / README.MD
Created December 6, 2018 11:00
Magento 2 - Get Attribute Options

Magento 2 - Get Attribute Options

<?php
$attribute_value = $_product->getData( $attributeCode );
$optionText = $attr->getSource()->getOptionText( $attribute_value );

//the id of the row that has our image
$option_img_id = $attribute_value;

//get all of the options - if we need to find all images
@garyconstable
garyconstable / README.MD
Last active December 6, 2018 10:59
Magento 2 - Raw DB Query

Magento 2 - Raw DB Query

<?php
//use a raw query to fid the row or rows
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();

$sql = " select * from `eav_attribute_option_swatch` where option_id in(".$option_img_id.") " ;
@garyconstable
garyconstable / README.MD
Last active December 6, 2018 10:58
Magento 2 - Get Image Paths

Magento 2 - Get Image Paths

<?php
/* Using Direct Object Manager */
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
//$baseUrl = $storeManager->getStore()->getBaseUrl();
$mediaUrl = $storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
//$statiContenteUrl = $storeManager-&gt;getStore()-&gt;getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_STATIC);
@garyconstable
garyconstable / readme.md
Last active December 12, 2018 09:50
Install PHP

PHP...

which php

If you see this it's the stock version

/usr/bin/php
@garyconstable
garyconstable / readme.MD
Created November 30, 2018 13:27
Magento - Get the Current product & its categories

Magento - Get the Current product & its categories

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');//get current product
$cats = $product->getCategoryIds();
@garyconstable
garyconstable / host.MD
Created November 29, 2018 22:42
Magento - Vagrant - Vhost
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/public/pub;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name _;