0

I'm trying to add a new custom image attribute for category, following the guide here "https://webkul.com/blog/add-custom-image-attribute-category-magento-2/comment-page-1/#comment-16835"

However, after I added these files under /app/code/[vendor]/[Module]/

Then run

php bin/magento setup:di:compile  
php bin/magento setup:upgrade  
php bin/magento c:c c:f

but nothing shows up, and I cannot find the module on the list. Please help

3
  • you forgot to run php bin/magento s:s:d Feb 8, 2019 at 21:53
  • I tried to run that, but it's still not showing. also, can not find the module from the list "php bin/magento module:status" Feb 8, 2019 at 22:34
  • you have to register your own module first
    – fmsthird
    Feb 8, 2019 at 22:44

1 Answer 1

1

You can create your own custom module wherein you can use the resources from the guide provided in a link included in your post.

Follow the steps below

registration.php
app/code/Vendor/CustomModule/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Vendor_CustomModule',
    __DIR__
);  

module.xml
app/code/Vendor/CustomModule/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_CustomModule" setup_version="1.0.0" />
</config>   
3
  • 1
    This works, thanks a lot. After created the registration.php file, I had to delete the Vendor/Module/di.xml from the guide which was causing error, and replace the module.xml you provided. After that, just run setup:upgrade, and everything works now! Thanks, i'm new to creating modules. Feb 8, 2019 at 23:15
  • Can you show me how to call the image in the front end? Feb 8, 2019 at 23:52
  • it's on the comment: Please follow below steps in order to get image url at frontend. create instance of class Magento\Catalog\Model\CategoryRepository then get category model by calling get method like $category = $categoryRepository->get($categoryId, $storeId); $imageUrl = “magento_media_url_path”.”catalog/category/”.$category->getCustomImage(); And then you can use this $imageUrl in your custom category page or as per your design.
    – fmsthird
    Feb 9, 2019 at 2:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.