New answers tagged

0

As mentioned "ObjectManager is absolutely prohibited" and "Registry is deprecated", the following atwix registry alternative appears to represent the current correct approach to the original question by using Service and ViewModel. https://www.atwix.com/magento-2/alternatives-for-deprecated-registry-class-magento-2-3/ https://github.com/...


0

i am trying to access the template from the theme itself that's why i am getting error, now i created a module and added phtml file in template folder. now its coming good.


0

The error means Magento can't find your phtml file. template="Company_module::menubtn.phtml" your phtml file should be in either following location: app/code/Company/module/view/frontend/templates/menubtn.phtml or app/design/Company/module/view/frontend/templates/menubtn.phtml Though, I assume your module is actually named "Module" and ...


0

You have several options: You can use a tool like Hotjar to track the clicks on the banners. You can track with js the 'onclick' events and make an ajax call to a controller which could record the element and number of clicks on it. You could again use js to track the 'onclick' event and trigger sending data to dataLayer if you have Google Tag Manager ...


0

I advise you to create a custom block and load a product collection filtered by your conditions. You would have control over what is loaded there. The collection retrieval would look something like this: public function getLimitedProductCollection($categoryId, $limit) { $collection = Mage::getResourceModel('catalog/product_collection') -&...


0

Try to move it instead: <move element="wishlist_sidebar" destination="mylocation.block" before="-"/> Also make sure to clear the cache, sometimes not even when running flush and clear cache, magento stop using cached. When it happens I need to clear static files. I recommend disable full_page and block_html cache while ...


1

Your method is not working because your blocks are siblings and do not have a parent/child relationship. The key is the word child in getChildHtml. If you nest your wishlist block inside the location block that will work. Also, header.panel is a container, not a block. See https://github.com/magento/magento2/blob/5e57ddd6b0452121e26ce93c74029cf58c4b1d6b/app/...


0

First of all core/template is not a part of Magento 2. Answers. To add any phtml file you need a block or layout file to define a path of your phtml file. type is use to define your Block class which is connected to your phtml file. So you can access block methods in your phtml file. name is used to set a name of your block. It must be unique. template ...


0

A general practice in many frameworks is that if you want to reuse the same function in multiple places you write the function in a lightweight helper If you want a function that is there in a controller and you want to reuse it in a block, it would be best to move that function in a helper class and inject the object of the helper class in the constructor ...


0

Please follow the below step to call the controller function in the block. Step 1: Create a function in the controller file like below. Vendor\Module\Controller\Index\ControllerName.php public function getControllerFunction() { return __('Controller Function'); } After that call controller class in block construct and call controller function like ...


0

First, match your live server configuration with the dev server configuration. Then run below commands on your dev server Magento root: rm -rf vendor/* composer install rm -rf generated/* php bin/magento s:up php bin/magento s:d:c <!-- For Production mode --> php bin/magento s:s:d <!-- For developer mode --> php bin/magento s:s:d -f php bin/...


0

You need to create a model that will represent your table and will hold your class also, then you need to have resource model and collections, then in your layout file using collections and the method defined in your block of $block->getName() will execute will give you the correct result.


0

This code class="Magento\Contact\Block\ContactForm" means that in your template you have access to all methods of the class vendor/magento/module-contact/Block/ContactForm.php or Magento\Framework\View\Element\Template In that class you have no getName method. What do you need? the name entered in the form? in this case you need to use javascript. ...


0

I figured it out: All Methods are defined here: vendor\magento\framework\View\Element\AbstractBlock.php It works like this: <?php $name = $block->getNameInLayout(); // Output -> firstname


0

<block class="Magento\Catalog\Block\Product\View" name="bundle.product.view.options.notice" template="Magento_Bundle::catalog/product/view/options/notice.phtml"/> <block class="Magento\Bundle\Block\Catalog\Product\View\Type\Bundle" name="product.info.bundle.options" as="...


Top 50 recent answers are included