Skip to main content

Posts

Magento2 create product using external script

<?php use Magento\Framework\App\Bootstrap; require __DIR__ . '/app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $appState = $objectManager->get('\Magento\Framework\App\State'); $appState->setAreaCode('frontend'); $websiteIds = [1]; $categoryIds = [2]; $is_in_stock = 1; $qty = 9999; //Initiate the product object $product = $objectManager->create('\Magento\Catalog\Model\Product'); $product->setSku('Test'); $product->setName('Test'); $product->setUrlKey('test'); $product->setWebsiteIds($websiteIds); $product->setCategoryIds($categoryIds); $product->setAttributeSetId(4); $product->setStatus(1); $product->setWeight(1); $product->setVisibility(4); $product->setTaxClassId(0); $product->setTypeId('simple'); $product->setPrice(10.25); $product->setDescription('This is a test simple item.'); $product->...

Magento2 custom Sql query

<?php /* Following are the methods which can be used to retrieve data $connection object fetchAll - fetch all records based on query fetchRow - fetch single row fetchAssoc - fetch result with column names fetchCol - fetch single column fetchOne - fetch first record */ // save this file on magento2 root and customize for your needs use Magento\Framework\App\Bootstrap; require __DIR__ . '/app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $resource = $objectManager->get('Magento\Framework\App\ResourceConnection'); $connection = $resource->getConnection(); $sql = "SELECT * FROM ".$resource->getTableName('core_config_data'); $result = $connection->fetchAll($sql); echo '<pre>'; print_r($result); //Insert query $sql = "INSERT INTO ".$resource->getTableName('TABLENAME')." SET columnname='value'" ;...

Magento Magmi Import tier price bug fix per website

Tier price import using Magmi import have Bug.Its not importing tier price per website. Here is the fix. Open the file tierpriceprocessor.php File location :- magmi/plugins/extra/itemprocessors/tierprice/tierpriceprocessor.php Step 1:- Find the function 'processItemAfterId'. Step 2 :- insert the following code right after Line 39 which is $pid=$params["product_id"]; $_websites = $item['websites']; $_websites = explode(',',$_websites); if(count($_websites) > 1){ for($i=0;$i<count($_websites);$i++){ $sql = "SELECT website_id FROM ".$this->tablename("core_website")." WHERE code ='".$_websites[$i]."'"; $webIds[$i] = $this->selectOne($sql,array(),"website_id"); } }else{ $sql = "SELECT website_id FROM ".$this->tablename("core_website")." WHERE code ='".$_websites[0]."'...