How to override view.xml file in custom module
-
21-02-2021 - |
Question
I have change magnifier vars in view.xml file under luma theme. Its working fine .
I have change it in my custom module like this ...
app/code/XXX/YYY/etc/view.xml.
<view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/view.xsd">
<var name="magnifier">
<var name="fullscreenzoom">20</var> <!-- Zoom for fullscreen (integer)-->
<var name="top"></var> <!-- Top position of magnifier -->
<var name="left"></var> <!-- Left position of magnifier -->
<var name="width">400</var> <!-- Width of magnifier block -->
<var name="height">400</var> <!-- Height of magnifier block -->
<var name="eventType">hover</var> <!-- Action that atcivates zoom (hover/click) -->
<var name="enabled">true</var> <!-- Turn on/off magnifier (true/false) -->
<var name="mode">outside</var> <!-- Zoom type (outside/inside) -->
</var>
Its not working .
And also In theme.xml
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
<title>theme name</title>
<parent>Magento/blank
registration.php:
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::THEME,
'frontend/OX/yyy',
__DIR__
);
/app/design/frontend/XXX/yyy/etc/view.xml
<view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/view.xsd">
<var name="magnifier">
<var name="fullscreenzoom">20</var> <!-- Zoom for fullscreen (integer)-->
<var name="top"></var> <!-- Top position of magnifier -->
<var name="left"></var> <!-- Left position of magnifier -->
<var name="width">400</var> <!-- Width of magnifier block -->
<var name="height">400</var> <!-- Height of magnifier block -->
<var name="eventType">hover</var> <!-- Action that atcivates zoom (hover/click) -->
<var name="enabled">true</var> <!-- Turn on/off magnifier (true/false) -->
<var name="mode">outside</var> <!-- Zoom type (outside/inside) -->
</var>
</view>
its also not working.
If anything i want to change it.
Thanks.
Solution
Try this,
To create a theme and override a view.xml
app/design/frontend/{Vendor}/{theme-name}/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::THEME,
'frontend/{Vendor}/{theme-name}',
__DIR__);
then create theme.xml
app/design/frontend/{Vendor}/{theme-name}/theme.xml
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
<title>Theme Title</title>
<parent>Magento/blank</parent></theme>
Check whether the theme is installed by the following query via mysql
select * from theme;
then add
app/design/frontend/{Vendor}/{theme-name}/etc/view.xml
and add composer.json in
app/design/frontend/{vendor}/{theme-name}/composer.json
then add the below code in it
{
"name": "{vendor}/{theme-name}",
"description": "N/A",
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0",
"magento/theme-frontend-blank": "100.0.*",
"magento/framework": "100.0.*"
},
"type": "magento2-theme",
"version": "100.0.1",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"autoload": {
"files": [
"registration.php"
]
}}
You must configure your theme to see the changes on frontend.
To configure new theme for your store, just follow the below steps :
Go to-> content-> configuration-> select your store-> then change the new theme by clicking drop down and save configuration.
NOTE : After creating theme setup:upgrade and once after configured theme cache:flush.
Hope this helps :)
OTHER TIPS
according documentation custom theme files must be under following path:
/app/design/frontend/<Vendor>/<Theme>
So your view.xml should be there:
/app/design/frontend/<Vendor>/<Theme>/etc