Uninstall Module Manually for Magento 2

  • Delete the Module folder from {folder path}\app\code
  • Remove module entry from setup_module
  • php bin/magento setup:upgrade => Setup Upgrade
  • php bin/magento cache:flush
Advertisements
Posted in כללי | Tagged | Leave a comment

how to put product into category, data come from csv magento 2

lets say i have this csv file

Continue reading

Posted in כללי | Tagged | Leave a comment

how to remove last category from product in magento 2

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productRepository = $objectManager->get(‘\Magento\Catalog\Model\ProductRepository’);

$sku = 100101;
$product = $productRepository->get(100101);
$categories_from_db_by_product = $product->getCategoryIds();
array_pop($categories_from_db_by_product);
$product->setCategoryIds($categories_from_db_by_product);
$product->save();

Posted in כללי | Tagged | Leave a comment

how to get category id by name magento 2

$collection = $objectManager->create(‘\Magento\Catalog\Model\Category’)->getCollection()->addAttributeToFilter(‘name’,$my_name)->setPageSize(1);

$cat_det = $collection->getData();
$category_id = $cat_det[0][‘entity_id’];

Posted in כללי | Tagged | Leave a comment

how to load categories from product magento 2


$categories_from_db_by_product = $product->getCategoryIds();

foreach($categories_from_db_by_product as $category){
$cat = $objectManager->create(‘Magento\Catalog\Model\Category’)->load($category);
if($cat->getName() != $categories_from_csv[$i]){
$isIn = true;
}
}

Posted in כללי | Tagged | Leave a comment

String to int in php return 0

there are cases when

int(’11’) or intval(’22’)

will return a 0 and not  the number himself and that is because there is spaces in the number

the solution is to use regular expression

$int = (int) preg_replace(‘/\D/’, ”, $strNonNumeric);
OR

$int = (int) preg_replace(‘/[^0-9]/’, ”, $strNonNumeric);

 

Posted in כללי | Leave a comment

how to get product by sku or id in magento 2

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        

 

                $appState = $objectManager->get(‘\Magento\Framework\App\State’);

                $appState->setAreaCode(‘frontend’);

 

                $productRepository = $objectManager->get(‘\Magento\Catalog\Model\ProductRepository’);

 

                $id = 1; // YOUR PRODUCT ID;

                $sku = ’24-MB01′; // YOUR PRODUCT SKU

 

                // get product by product id

                $product = $productRepository->getById($id);

 

                // get product by product sku

                $product = $productRepository->get($sku);

Posted in כללי | Tagged | Leave a comment