New answers tagged

1

removeItemByKey does not delete a product from the database. It just removes it from the product collection object. If you want to remove products you can use $this->_productRepositoryInterface->delete($product);


0

Added in admin custom Form <field name="customer_group"> <argument name="data" xsi:type="array"> <item name="options" xsi:type="object">Magento\Customer\Model\Customer\Source\Group</item> <item name="config" xsi:type="array"> <item name="dataType" xsi:type="string">int&...


0

try below code Using ObjectManger <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); //get current product $currentProduct = $objectManager->get('Magento\framework\Registry')->registry('current_product'); $currentProductData = $objectManager->get('Magento\Catalog\Model\Product')->load($currentProduct->getId()); ...


1

$hasRequired = false; $options = $_product->getOptions(); if (is_array($options)) { foreach ($_product->getOptions() as $option) { if ($option->getIsRequire()) { $hasRequired = true; break; } } } now check the value of $hasRequired; ($_product - is the product instance for which you are checking)


0

$productcollection = $this->collectionFactory->create()->addAttributeToSelect('manufacturer','LG')->load(); foreach ($productcollection as $product) { try { $productcollection->removeItemByKey($product->getId()); } catch (StateException $e) { } } return $productcollection; } Thankful of my friend Sandro who helped ...


1

Do some corrections in the code. Hopefully, it will work for you. $productcollection = $this->collectionFactory->create()->addAttributeToSelect('manufacturer','LG')->load(); foreach ($productcollection as $product) { try { $product->delete(); } catch (StateException $e) { } } This code will gives ...


1

If you try to delete product from frontend then you need to assign area for that. Add following code to your class. public function __construct( ........ \Magento\Catalog\Model\ProductRepository $productRepository, \Magento\Framework\Registry $registry ) { ...... $this->productRepository = $productRepository; $this->registry = ...


0

{theme_dir}/Magento_Catalog/templates/product/compare/link.phtml. do this by calling the Magento\Catalog\Helper\Product\Compare helper's method hasItems() <?php $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare'); if ($compareHelper->hasItems()) { ?> //default Magento code <li class="item link compare" data-bind="...


0

I've finally found a solution by a fellow developer that this one is working with PHP 7.1 and Magento 2.2.0 : https://github.com/olegkoval/magento2-regenerate_url_rewrites


0

protected $_productRepository; protected $_productImageHelper; public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Catalog\Model\ProductRepository $productRepository, \Magento\Catalog\Helper\Image $productImageHelper, array $data = [] ) { $this->_productRepository = $productRepository; $...


3

it will not help in a performance boost in the latest version with Magento plus Magento no longer recommend use flat catalog option for more info https://docs.magento.com/m2/ce/user_guide/catalog/catalog-flat.html


1

Go to Admin->Store->Configuration->Sales->Checkout->Shopping Cart And set the Parent Product Thumbnail as Grouped Product Image Check the below screenshot Clear the cache and check.


-1

Magento2 doen't support it by default, you have to do customization for this , You can create 1 custom column in quote_item table where you can save group product id for the item so when you add product from group product detail page so you have to insert its group id as well. then on item list page you can check if it has group product id then you can ...


0

I just override File: module-catalog/Block/Category/View.php And add the below code. I am just providing you a logic. I have directly used a custom query. I have created a table to add URL, title, description, and keyword then I have matched current URL in the table and then set title, description, and keyword dramatically. $urlInterface = \Magento\...


0

app\code\VendoreName\ModuleName\Block ProductName.php <?php namespace VendoreName\ModuleName\Block; use Magento\Framework\App\Request\DataPersistorInterface; class ProductName extends \Magento\Framework\View\Element\Template { protected $registry; public function __construct( \Magento\Framework\View\Element\Template\Context $context, ...


0

You need to load product to get product name With Object Manager $productId = "10"; //Product Id $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->create('Magento\Catalog\Model\Product')->load($productId); echo $product->getName(); //Get Product Name Note: Don't use objectManager directly With ...


2

Please you get by-product Id. $productId = "10"; //Product Id $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->create('Magento\Catalog\Model\Product')->load($productId); echo $product->getName(); //Get Product Name Or try for the current page. $objectManager = \Magento\Framework\App\ObjectManager::...


2

Use this <a class="action back" href="javascript:history.back()"><?= __('Back') ?></a>


0

I fix this by disabling the module loll!


0

This depends on the admin panel setting in: Stores > Configuration > Catalog > Catalog > Inventory > Stock Options > Display Out of Stock Products If this is set to NO, only products that are in stock will be returned.


0

please override Download.php file from the vendor. 1. Magento\ImportExport\Controller\Adminhtml\Export\File\Download.php add changes to in. public function execute() { if (empty($fileName = $this->getRequest()->getParam('filename'))) { throw new LocalizedException(__('Please provide export file name')); } ...


0

Try this may be help you By just adding lines in below file in mymodule_index_index.xml files page node I Add layout=1column and the problem is solved.


0

You can do that real time, but you have to hook into a lot of places (like collection retrieval, repository getList method, product view page, related products, upsells, and maybe a lot of others). Not to mention that you may have third party extensions that use product collections. My advice is to build an observer on the product save that sets the product ...


0

If it is configurable product, make sure all of it's simple products have the same attribute set as parent.


1

You are using wrong table join in your query. The name details for products are stored in catalog_product_entity_varchar table. First, make sure you have the correct attribute_id (75) value for name attribute. Use below query to achieve your requirements. UPDATE `catalog_product_entity_varchar` as pt LEFT JOIN `catalog_product_entity` as p ON p.`entity_id` ...


0

if you need it for one time, you can use the Store Manager trial, it allows to perform search by SKUs and apply filter with the selected products. Then you can export products in a few clicks


1

Try to fix this way.. Open below file vendor/magento/module-import-export/Controller/Adminhtml/Export/Export.php and replace below function public function execute() { if ($this->getRequest()->getPost(ExportModel::FILTER_ELEMENT_GROUP)) { try { $params = $this->getRequest()->getParams(); $model = $this-&...


0

Instead of using the object manager directly, inject the ProductFactory: public function __construct(\Magento\Catalog\Model\ProductFactory $productFactory) { $this->productFactory = $productFactory; } Then use it like this: $product = $this->productFactory->create(); $product->loadByAttribute('sku', $sku); or to do a full load (the above ...


0

It is working. Use below link https://www.cadence-labs.com/2019/07/magento-2-remove-price-from-select-dropdown-on/ Magento 2.2.3 - Remove price from select field on product page


0

In Magento 1, To change the image size we have to change on every listing page. So we have to remember all the file lists and search on the whole site. In Magento 2, We have good news to resize the image. We do not need to remember all the files. All the size is managing from 1 file view.xml. View.xml file located in app/design/vendor/theme/etc <image ...


5

In order to set the default Image size, you need to edit the image settings(width and height) on etc/view.xml file. If you are using custom theme, then go to the below file path vendor / magento / theme-frontend-blank (or Luma Theme) / etc / view.xml Copy the file and add in your custom theme on below path app / design / frontend / [vendor] / [theme] / ...


0

$attrCode = 'color_base'; $sourceModel = Mage::getModel('catalog/product')->getResource() ->getAttribute($attrCode)->getSource(); $valuesText = explode(',', 'red,green,blue'); $valuesIds = array_map(array($sourceModel, 'getOptionId'), $valuesText); $OptionIds = implode(',', $valuesIds); $product->setColorBase($attrCode, $OptionIds); $product-&...


1

In Magento 2? If you mean oversized, better to do it in css/html if you want to enlarge your image. Or if you want to display a bigger image because you use a small thumbnail size, have a look at your theme file view.xml https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/themes/theme-images.html and https://devdocs.magento.com/guides/v2.3/...


1

create your custom table Model files for get your custom collection. VendoreName\ModuleName\Model CustomData.php <?php namespace VendoreName\ModuleName\Model; use Magento\Framework\Model\AbstractModel; use VendoreName\ModuleName\Model\ResourceModel\CustomData as CustomDataResourceModel; class CustomData extends AbstractModel { protected function ...


0

create custom block file : app\code\Vendor\Extension\Block\Myblock.php <?php namespace Vendor\Extension\Block; use Magento\Framework\View\Element\Template; class Myblock extends Template { protected $productloader; public function __construct(\Magento\Catalog\Model\ProductFactory $productloader) { $this->productloader = $...


0

add Below in your custom catalog_product_view.xml layout file. app/design/frontend/ThemeVendor/ThemeName/Magento_Catalog/layout/catalog_product_view.xml <referenceContainer name="content"> <block class="Vendor\Module\Your\Block\Class" name="custom.block" after="product.info.details" template="Vendor_Module::product/test.phtml" /> ...


0

Hi I have used the move tag for moving my custom block after content bottom <move element="custom" destination="main" after="content.bottom"/>


1

You can do this way .. There are 2 ways to get category Data: => Using Object Manager: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $appState = $objectManager->get('\Magento\Framework\App\State'); $appState->setAreaCode('frontend'); $registry = $objectManager->get('\Magento\Framework\Registry'); $currentCategory = $...


1

It will be because you are adding a new filter each iteraction rather than replacing the current filter. Instead you can either reset the where query if you only have the 1 filter parameter or you can create a copy of the query each iteraction. To reset the where query foreach ($optionData as $optionValues) { $_productCollection->getSelect()->...


0

Please check this. It may help you. Magento2 : How to disable product image slider on detail page?


0

Can you please try below code which can be help to resolved it. $optionData = array('435','436','437','438','441','439'); $productIds = array(); foreach ($optionData as $optionValues) { $productIds[$optionValues][] = $_productCollection->addAttributeToFilter( array( array('attribute' => "filter_type", 'finset' =...


0

I have fixed this issue in more than 3-4 projects. If you want to resolve this issue, you can upgrade your version with latest one or try below code logic: Try this solution by overriding below function in your custom module :) Path: vendor/magento/module-url-rewrite/Model/Storage protected function doReplace(array $urls){ $this->deleteOldUrls($...


0

I have fixed this issue in more than 3-4 projects. If you want to resolve this issue, you can upgrade your version with latest one or try below code logic: Try this solution by overriding below function in your custom module :) Path: vendor/magento/module-url-rewrite/Model/Storage protected function doReplace(array $urls){ $this->deleteOldUrls($...


0

GOOD GRIEF .... max_input_vars I came across this years ago in Magento1 .... didn't even cross my mind for this issue.


0

Set ImageMagick as Image Adapter from Admin->Stores->Configuration->Advanced->Developer->Image Processing Settings and set the ImageMagick as Image Adapter Install ImageMagick on your server if not available, Check this guide. Then flush all the cache with Catalog Image cache from Additional Cache Management on System->Cache Management page. Hope ...


1

Go to the the file app/design/frontend/Vendor/Theme/etc/view.xml see a variable navdir. change the thumbnails alignment in Fotorama. default set as: <var name="navdir"> horizontal</var> Change the code like this: <var name="navdir"> vertical</var> to make the thumbnails as vertical. Example <?xml version="1.0"?> <...


3

You can use below code class GetProducts{ protected $_productRepository; protected $_searchCriteriaBuilder; public function __construct( \Magento\Catalog\Api\ProductRepositoryInterface $productRepository, \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder ) { $this->_productRepository = $productRepository; $...


0

You install flash plugin in your browser and try again.


1

we added code above but not showing (magento 2.3.4)


0

Please override below file and remove other code and add below code: File Path: app/design/frontend/Yourtheme/Yourtheme/Magento_Catalog/templates/product/view/gallery.phtml <?php $galleryImages = $this->getGalleryImages(); $_product = $this->getProduct(); ?> <div class="gallery-images"> <ul class="small-image" style="list-style: none;...


Top 50 recent answers are included