Skip to main content

Posts

Showing posts from May, 2018

Magento 2: get child product of current configurable product

<?php      $objectManager = \Magento\Framework\App\ObjectManager::getInstance();     $product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');//get current product     $productTypeInstance = $product->getTypeInstance();     $usedProducts = $productTypeInstance->getUsedProducts($product);     echo $product->getId(); //Main configurable product ID     echo $product->getName(); //Main Configurable Name     foreach ($usedProducts  as $child) {         echo $child->getId()."</br>"; //Child Product Id          echo $child->getName()."</br>"; //Child Product Name     }?>

Magento 2: get product category on product detail page

<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->get('Magento\Framework\Registry')->registry('current_product'); $categories = $product->getCategoryIds(); /*will return category ids array*/ foreach($categories as $category){     $cat = $objectManager->create('Magento\Catalog\Model\Category')->load($category);     $cats[] = $cat->getName();     }         // echo '<pre>';     // print_r($cats);     // echo '</pre>';         ?>

Magento 2: Putty Commands

cd - change directory cd ..    - come out of one directory pwd        -    Path of my current directory wget - get downloadable data unzip filename.zip -d /pictures  - for unzip data and -d for directory unzip -l filename.zip  -  list all files from a .zip file unzip filename.zip filename.txt  -- extract / unzip certain file from a .zip file zip -r filename *  -   zip up an entire directory including all sub-directories zip -r example2.zip *  -  zip all files in current directory rm -rf *    -    delete all files in directory rm -rf foldername/  -  To delete a whole folder and its content mysql -u user_name -p database_name< advomate_pompusalive.sql  ------ for import DB mysqldump -u username -p  database_to_be_exported > db_file_name.sql  ------   for export DB yum install zip unzip -y...

Magento 2: CRUD

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of object manager $resource = $objectManager->get('Magento\Framework\App\ResourceConnection'); $connection = $resource->getConnection(); $tableName = $resource->getTableName('employee'); //gives table name with prefix //Select Data from table $sql = "Select * FROM " . $tableName; $result = $connection->fetchAll($sql); // gives associated array, table fields as key in array. //Delete Data from table $sql = "Delete FROM " . $tableName." Where emp_id = 10"; $connection->query($sql); //Insert Data into table $sql = "Insert Into " . $tableName . " (emp_id, emp_name, emp_code, emp_salary) Values ('','XYZ','ABD20','50000')"; $connection->query($sql); //Update Data into table $sql = "Update " . $tableName . "Set emp_salary = 20000 where emp_id = 12"; $connecti...