I'm trying to override the file vendor/magento/module-catalog/view/base/web/js/price-box.js in my theme using requirejs-config.js unsuccessfully.
Location of my requirejs-config.js:
app/design/frontend/Mytheme/mytheme/requirejs-config.js
Contents of my requirejs-config.js file:
var config = {
map: {
'*': {
priceBox:'js/price-box',
}
}
};
I placed my new file price-box.js in here:
app/design/frontend/Mytheme/mytheme/web/js/price-box.js
I also tried placing it under:
app/design/frontend/Mytheme/mytheme/Magento_Catalog/web/js/price-box.js
but none of those worked.
In the frontend the file that gets loaded is:
pub/static/frontend/Mytheme/mytheme/en_US/Magento_Catalog/js/price-box.js
Which is the default vendor file, and not mine? My file is here:
pub/static/frontend/Mytheme/mytheme/en_US/js/price-box.js
We are working in Developer mode and Cached Disabled.
I tried a few commands to see if that would actually help:
php bin/magento setup:static-content:deploy
php bin/magento cache:clean
php bin/magento setup:upgrade
php bin/magento setup:di:compile
Any suggestions?
Related questions:
- Magento2: How can I override core js module price-box.js
- How to extend js class/method of checkout model class in magento 2
- Magento 2 does not read my requirejs-config.js
Official documentation:
Update 1
Following suggestions of a StackExchange user I just did:
- Move requirejs-config.js inside the web/ folder of my theme.
- Manually remove everything under /pub/static/ except the .htaccess file
- Execute this command:
php bin/magento dev:source-theme:deploy
It didn't do any effects, the loaded file keeps being:
pub/static/frontend/Mytheme/mytheme/en_US/Magento_Catalog/js/price-box.js
Update 2 - Solution
As suggested by David Verholen I did the following steps:
- Remove the
mapfrom the requirejs-config.js file in the root folder of my theme. - Place my new files
price-box.jsin:app/design/frontend/Mytheme/mytheme/Magento_Catalog/web/js/price-box.js
- Manually remove all the contents from
/pub/static/by doing:rm -rf pub/static/*
2 Answers 2
placing the file under app/design/frontend/Mytheme/mytheme/Magento_Catalog/web/js/price-box.js should be sufficient (without any require config) to overload the file in your theme.
As already said, try clearing the pub/static/ folder content (except the .htaccess). On unix systems you can do this with the command rm -rf pub/static/* from the root directory since * does not include any files starting with a .
If this does not work, I assume there is a problem, since the original File is located in the base area while your theme is in the frontend area. Logically (if this is not working), since base should be inherited by all areas, this might be a bug in the overloading mechanism.
-
David one thing is noticeable in your answer that if js falls in the base directory then it may cause problem. Is there any way to fix this. In my case js is in base directory so i am not able to override it with my custom module.Dhaval Solanki– Dhaval Solanki2018年03月27日 04:25:17 +00:00Commented Mar 27, 2018 at 4:25
Contents of requirejs-config.js should be:
var config = {
map: {
'*': {
'Magento_Catalog/js/price-box':'Vendor_Module/js/price-box'
}
}
};
Tested in Magento 2.1.4.
-
Not working. Help me with this -> magento.stackexchange.com/questions/305247/…Kowsigan Atsayam– Kowsigan Atsayam2020年02月25日 09:48:39 +00:00Commented Feb 25, 2020 at 9:48
Explore related questions
See similar questions with these tags.
priceBox:try:'Magento_Catalog/js/price-box':.