Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

0

That would be because the admin product form doesn't actually use ProductRepository, at least as of 2.2.2. vendor/magento/module-catalog/Controller/Adminhtml/Product/Save.php: $product->save(); You haven't explained what you're actually trying to accomplish, but you would probably be better served by an observer on event catalog_product_save_before or ...


0

You need to build a category collection of the categories you want to delete. Then it's just the case of something like this: try { $category->delete(); echo 'Category Removed'; } catch (Exception $e) { echo 'Failed to remove category ' . $category->getId(); echo $e->getMessage(); } I cant be more specific without knowing ...


1

There is a good chance validation is failing. You just cant see it to correct it. There are a lot of hidden fields within the admin. Open inventory or pricing on the problem product to see if anything is highlighted in red.


1

Try the following way: app/code/SR/MagentoCommunity/etc/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\CatalogInventory\Model\StockStateProvider"> <plugin name="...


1

Try This :- $productId = $_product->getId(); $customOptions = $obj->create('Magento\Catalog\Model\ProductRepository')->get($productId); $productOption = $product->getOptions(); foreach($productOption as $option) { print_r($option->getData()); //get All Data Of Option }


1

1 .Set System - Configuration - Catalog - Inventory - Stock Options - Display Out of Stock Products to Yes. 2.Set System - Configuration - Catalog - Inventory - Product Stock Options - Backorder to Allow Qty Below 0.


1

Stroes -> Configuration -> Catalog -> Inventory Click on Product stock Options Tab.


0

Magento uses an EAV table structure for products. Names are stored in catalog_product_entity_varchar. If you have the product ID X, you can query this table directly: SELECT entity_id, value, store_id FROM catalog_product_entity_varchar WHERE entity_id = X AND attribute_id = ( SELECT attribute_id FROM eav_attribute WHERE entity_type_id=4 AND ...


0

Looks like this error related to your XML layout files, you have element , this will show the error, You you need to search ' element in admin in XML Layout update field in Category, CMS Page and etc. As you are getting this is product detail page so you should look in product detail xml or it's admin section of layout updates. Or there may be third party ...


0

If you are on product page in Magento 2 then if you want to get current product. So for that you can get current product id like below : In Controller,Block,Phtml -> $currentProductId = $this->getRequest()->getParam('id'); In Observer -> $currentProductId = $observer->getRequest()->getParam('id'); Then load current product by current ...


0

As magento official documentation they are separately giving prices API which is as below : Manage Special Prices https://devdocs.magento.com/guides/v2.3/rest/modules/catalog-pricing.html#manage-special-prices Manage Tier Prices https://devdocs.magento.com/guides/v2.3/rest/modules/catalog-pricing.html#manage-tier-prices Manage Base Prices https://devdocs....


1

You can use the product collection: use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; ... $collection = $this->productCollectionFactory->create(); $collection->addAttributeToSelect('*') ->addAttributeToFilter('url_key', $yourUrlKey); $product = $collection->getFirstItem(); Another option is to use the UrlRewrite ...


1

To disable access from direct URL. You can override the class \Magento\Catalog\Block\Adminhtml\Product using di.xml preference as described below. Assume you are using a custom module name "Company_MyModule" step 1: create di.xml under YOUR-MAGENTO-ROOT/app/code/Company/MyModule/etc/adminhtml File: YOUR-MAGENTO-ROOT/app/code/Company/MyModule/etc/...


0

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');//get current product echo $product->getId(); echo $product->getName(); //echo $currentProduct->getSku(); if ($currentProduct = $product) { $upSellProducts = $currentProduct->...


1

In Your .phtml file :- <?php if ($block->getPagerHtml()): ?> <div class="order-products-toolbar toolbar bottom"><?php echo $block->getPagerHtml(); ?></div> <?php endif ?> Block file :- <?php namespace Vendor\Module\Block; use Magento\Store\Model\StoreManagerInterface; use Magento\Framework\View\Element\Template; ...


1

You can create a Block class and inject Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory in the constructor and you can get/display product collection in phtml file. Check below code: <?php namespace Vendor\Module\Block; class ProductDisplay extends \Magento\Framework\View\Element\Template { protected $...


1

You can override the class \Magento\Catalog\Block\Adminhtml\Product using di.xml preference as describe below. Assume you are using a custom module name "Company_MyModule" step 1: create di.xml under YOUR-MAGENTO-ROOT/app/code/Company/MyModule/etc/adminhtml File: YOUR-MAGENTO-ROOT/app/code/Company/MyModule/etc/adminhtml/di.xml <?xml version="1.0"?> ...


-1

a litte late, but if anyone has the same problem, you also need to add an afterGetFinalPrice() method. This is what get called here. You can add that to your Product Plugin.


0

this is a native magento 2 default, url will be changed , if you duplicate product ( it will add to url index of copy, 1,2,3...etc.) If you want to create new product url on save , you need to create a simple module for this reason. You can create Observer catalog_product_save_after And then : <?php namespace [VendorName]\[ModuleName]...


0

You can change require option value from the attributes. Go to Store->attributes->product search code "name" and set Values Required to NO


0

I have been in similar kind of situation, I have migrated the data from magento 1.9.x to magento 2.2.8 and there was two website in magento, for the default website the product detail page was working fine but for the other website it was not, I was only able to see the blank page where noting rendered in body tag, with that, one thing was sure that it is a ...


0

I had similar problem in Magento 2.3.0. In my custom theme I changed layout of catalog_product_view.xml and "Add To Wishlist" stopped showing up. Any change to the file and it wouldn't be visible. So I called it manually: <block class="Magento\Wishlist\Block\Catalog\Product\View\AddTo\Wishlist" name="wishlist" as="wishlist" template="Magento_Wishlist::...


0

add this in your etc/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Catalog\Model\Product\Image" type="Sample\Code\Model\Product\Image" /> </config> add this in Sample\Code\...


2

Ashen, If you want overall listing page layered navigation should be in horizontal, then change your listing page layout from 2columns-left to 1column in catalog_category_view.xml file. If it needs for specific category, then set 1column layout from backend. Note: make sure your theme is overwritten or parent by luma theme.


1

Here you need to use Magento event observer. create events.xml at the following location. app\code\Vendor\Extension\etc\events.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="catalog_product_save_after"> ...


0

You can create a custom Block with two functions. one for get category image by categoryID and another function for get category data by categoryId . <?php namespace Vendor\Module\Block; use Magento\Catalog\Model\ResourceModel\CategoryFactory; use Magento\Framework\View\Element\Template\Context; use Magento\Store\Model\StoreManagerInterface; class ...


0

There is no predefined logic to get all the discounted products since Magento applies the discount based on various criteria: If the special price is set for the product If the price has been set up based on a particular customer group catalog price rule I assume that you need to show the discounted products in the frontend. In this case, you need to write ...


0

In my case the after debugging and digging into the deep found that the MYSQL was doing some issues it was not communicating well with the Application, So just restart the service and also increased the memory limit as well it resolved the issue now it is working fine.


1

I guess you need to check if the addProduct() is adding the product to cart. You can also try the following way $quoteItem = $quote_data->addProduct($product, $request); $quoteItem->setCustomPrice($customPrice); $quoteItem->setOriginalCustomPrice($customPrice);


0

how do you see this functionality working? As you don't have direct Relationship between Order and Sources. What we have is Order to a Stock relationship (based on the website where this order has been placed). What we will have are Shipments (created in the scope of order fulfillment) assigned to a particular source. So, we introduce Order to Source ...


0

I don't know you guys get solution or not but here you go. $sourceItem = []; // Magento\InventoryApi\Api\SourceRepositoryInterface; $source = $this->sourceRepository->get('default'); $sourceItem['name'] = $source->getName(); // source name $sourceItem['source_status'] = true; $sourceItem['notify_stock_qty'] = 1; $...


0

Use the magento modal widget. You’ll need to override the template file by creating a new one in your theme with the same path. Then wrap the template content you want in the modal with the magento modal template syntax. You’ll want to add a button or some sort of element that will initialize and load the modal on click. Here is the magento modal ...


0

Yes this is possible. Here is how we can add dynamic rows to Product Edit Page: Add DataProvider class as: etc\adminhtml\di.xml <?xml version="1.0" encoding="UTF-8"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <virtualType name="Magento\...


1

Magento is trying to load the product by SKU but you didn't send it in your Json. Even though you are passing the SKU on your URL, SKU is still a required field. , try with: { "product": { "price": 1, "sku": 12345, "extension_attributes": { "stock_item": {"qty": 2} } } } Here in swagger is showing that SKU is required. Follow swagger for your ...


1

I found how to set qty to the product on the 'MSI way'. PS: I'm using the default source. The constructor: private $sourceItemsSave; private $sourceItemInterface; public function __construct( SourceItemInterface $sourceItemInterface, SourceItemsSaveInterface $sourceItemsSave, ) { $this->sourceItemsSave = $sourceItemsSave; $this->...


0

We struggled with importing inventory changes in Magento 1; the issue was resolved when we started using OpenOffice spreadsheets instead of Excel. Our Magento 2 store doesn't seem to like Excel either, and OpenOffice works perfectly. Make sure you have the column headers right, they must be exactly as Magento has them (sku, not SKU, etc). Create the ...


0

For Importing the image using CSV file just provide the image name into your csv into the fields with name base_image, small_image, thumbnail_image, swatch_image You can simply have the csv file structure something like this SKU | product_websites | base_image | small_image | thumbnail_image | swatch_image ABC | product_web_code | base_i.jpg | small_i.jpg |...


0

Use this page for the corresponding match for new Inventory API - https://github.com/magento-engcom/msi/wiki/Magento-MSI-APIs


0

Suppose you have SR_MagentoCommunity module. Now added folowing file in your module that will avoid showing virtual type product in admin grid. app/code/SR/MagentoCommunity/etc/adminhtml/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:...


1

Try this, Add the below code to your block <?php namespace Vendor\ModuleName\Block; class ProductCollection extends \Magento\Framework\View\Element\Template { protected $_productCollectionFactory; public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Catalog\Model\ResourceModel\Product\...


0

If you want to have the product id in the product listing template file, then you can try following code $_product->getId()


0

At the end of the last template I used this instead- <div><?php echo $_product->getData('updated_at'); ?></div> And it works!


1

Try <?php echo $product->getUpdatedAt(); ?>


0

After that, you must reindex and refresh the cache. php bin/magento indexer:reindex php bin/magento cache:flush


Top 50 recent answers are included