Skip to main content

Posts

Showing posts from August, 2019

Magento 2 Update product image attributes value using custom script programetically

Magento 2 Update product image programetically <?php //increase the max execution time @ini_set('max_execution_time', -1); //memory_limit @ini_set('memory_limit', -1); error_reporting(E_ALL); ini_set('display_errors', '1'); use \Magento\Framework\App\Bootstrap; require __DIR__ . '/app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $instance = \Magento\Framework\App\ObjectManager::getInstance(); $state = $objectManager->get('\Magento\Framework\App\State'); $state->setAreaCode('frontend'); $product_collections = $instance->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory'); $collections = $product_collections->create(); foreach ($collections as $product) { if ($product->getId() == 2052) { $product = $objectManager->create('\Magento\Catalog\Model\Pr

Magento 2 add single product using custom script or programmatically

Magento 2 add single product programmatically <?php //increase the max execution time @ini_set('max_execution_time', -1); //memory_limit @ini_set('memory_limit', -1); error_reporting(E_ALL); ini_set('display_errors', '1'); use \Magento\Framework\App\Bootstrap; require __DIR__ . '/app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $bootstrapManager = $bootstrap->getObjectManager(); $state = $bootstrapManager->get('\Magento\Framework\App\State'); $state->setAreaCode('frontend'); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // instance of object manager $product = $objectManager->create('\Magento\Catalog\Model\Product'); $sku = 'sku'; $name = 'Sample Product'; $product->setSku($sku); // Set your sku here $product->setName($name); // Name of Product $product->setAttributeSetId(4); // Attribu

Magento 2 get category collection using specific controllers and category level using object manager

Magento 2 get category collection using object manager <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $category = $objectManager->get('Magento\Framework\Registry') ->registry('current_category'); //get current category $requestInterface = $objectManager->get('Magento\Framework\App\RequestInterface'); //echo $routeName = $requestInterface->getRouteName(); //echo $moduleName = $requestInterface->getModuleName(); $controllerName = $requestInterface->getControllerName(); //echo $actionName = $requestInterface->getActionName(); $parcatId = $category->getId(); // current Category ID $parcategory = $objectManager->create('Magento\Catalog\Model\Category') ->load($parcatId); $parent_category = $parcategory->getParentCategory(); $subcatId = $parent_category->getId(); $subcategory = $objectManager->create('Magento\Catalog\Model\Category

Magento 2 Get specific attribute (manufacturer) collection in phtml file with images using object manager

Magento 2 Get specific attribute (manufacturer) with images using object manager <?php $om = \Magento\Framework\App\ObjectManager::getInstance(); $categoryFactory = $om->get('\Magento\Catalog\Model\CategoryFactory'); $categoryHelper = $om->get('\Magento\Catalog\Helper\Category'); $categoryRepository = $om->get('\Magento\Catalog\Model\CategoryRepository'); $category = $categoryFactory->create()->load($catId); $categoryProducts = $category->getProductCollection() ->addAttributeToSelect('*'); foreach ($categoryProducts as $_product) { if($_product->getManufacturer()){ $brand_value = $_product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($_product); $brand_id = $_product->getManufacturer(); $curnt_cat_url = $category->getUrl(); $brandId = '?manufacturer='.$brand_id; $om = \Magento\Framework\App\ObjectManager::

Magento 2 Get Product collection using custom attributes of Best Seller

Get Product collection using custom attributes of Best Seller <?php use Magento\Framework\App\Action\Action; $_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $_helper = $this->helper('Magento\Catalog\Helper\Output'); $productCollection = $_objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory'); $collection = $productCollection->create()->addAttributeToSelect('*')->addAttributeToFilter('home_best_seller', '1')->setPageSize(10)->setOrder('sort_order', 'DESC')->load(); $imagewidth = 400; $imageheight = 400; $imageHelper = $_objectManager->get('\Magento\Catalog\Helper\Image'); $i = 0; foreach ($collection as $product) { echo $product->getName(); } ?>

Magento 2 Custom product option edit using JS

Custom product option edit using JS <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $cart = $objectManager->get('\Magento\Checkout\Model\Cart'); //This doesn't work $itemsCollection = $cart->getQuote()->getItemsCollection(); //This doesn't work too $itemsVisible = $cart->getQuote()->getAllVisibleItems(); $items = $cart->getQuote()->getAllItems(); $prosuctid = $_product->getId(); foreach ($items as $item) { $options = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct()); $optionsid = $item->getProductId(); if ($prosuctid == $optionsid) { $customOptions = $options['options']; // error here, line 44 if (!empty($customOptions)) { foreach ($customOptions as $option) { $optionId = $option['option_id']; $optionValue = $option['option_value']; waitFor

Magento 2 add/update simple products meta title, description programmetically using custom script

Magento 2 add/update meta values using custom script  <?php //increase the max execution time @ini_set('max_execution_time', -1); //memory_limit @ini_set('memory_limit', -1); error_reporting(E_ALL); ini_set('display_errors', '1'); use \Magento\Framework\App\Bootstrap; require __DIR__ . '/app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $instance = \Magento\Framework\App\ObjectManager::getInstance(); $state = $objectManager->get('\Magento\Framework\App\State'); $state->setAreaCode('frontend'); $product_collections = $instance->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory'); $collections = $product_collections->create(); foreach ($collections as $product) { $sku = $product->getSku(); echo 'Produc SKU : ' . $sku; echo "<br>&

Magento 2 add/update configure products meta title, Description programetically using custom script

Magento 2 add/update meta values of configure products using custom script <?php //increase the max execution time @ini_set('max_execution_time', -1); //memory_limit @ini_set('memory_limit', -1); error_reporting(E_ALL); ini_set('display_errors', '1'); use \Magento\Framework\App\Bootstrap; require __DIR__ . '/app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $instance = \Magento\Framework\App\ObjectManager::getInstance(); $state = $objectManager->get('\Magento\Framework\App\State'); $state->setAreaCode('frontend'); $product_collections = $instance->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory'); $collections = $product_collections->create()->addAttributeToFilter('type_id', 'configurable'); foreach ($collections as $product) { echo "

Magento 2 check product attribute values in database using mysql query

Magento 2 check product attribute in database using mysql query SELECT * FROM `catalog_product_entity_text` where store_id = 1; SELECT * FROM `catalog_product_entity_datetime` where store_id = 1; SELECT * FROM `catalog_product_entity_decimal` where store_id = 1; SELECT * FROM `catalog_product_entity_int` where store_id = 1; SELECT * FROM `catalog_product_entity_varchar` where store_id = 1; Note : In above SQL query store_id 1 is ID of store. kindly you need to check store Id for all store-views in admin and run the above code for each store-views separately.

Magento 2 check category attribute values in database using mysql query

Magento 2 check category attribute in database using mysql quer SELECT * FROM `catalog_category_entity_text` where store_id = 1; SELECT * FROM `catalog_category_entity_datetime` where store_id = 1; SELECT * FROM `catalog_category_entity_decimal` where store_id = 1; SELECT * FROM `catalog_category_entity_int` where store_id = 1; SELECT * FROM `catalog_category_entity_varchar` where store_id = 1; Note : In above SQL query store_id 1 is ID of store. kindly you need to check store Id for all store-views in admin and run the above code for each store-views separately.