I have install MVCSitemapProvider on my MVC 3 application for breadcrumbs trail. It has auto generate following node in Mvc.sitemap.xml
<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0"
xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0 MvcSiteMapSchema.xsd"
enableLocalization="true">
<mvcSiteMapNode title="Home" controller="Home" action="Index">
<mvcSiteMapNode title="About" controller="Home" action="About"/>
</mvcSiteMapNode>
</mvcSiteMap>
And Following is the HTML Helper for displaying breadcrumbs
#Html.MvcSiteMap().SiteMapPath()
In my application, there is lot of controller and their action that is hectic to add all mvcSiteMapNode in mvcSiteMap of those action and question is that Is it possible to list all controller and their respective action in mvcSiteMapNode of Mvc.sitemap.xml without writting all manually.
I think the closest thing is using attributes on the methods, see https://github.com/maartenba/MvcSiteMapProvider/wiki/Defining-sitemap-nodes-in-code. Example:
// GET: /Checkout/Complete
[MvcSiteMapNodeAttribute(Title = "Checkout complete", ParentKey = "Checkout")]
public ActionResult Complete(int id)
{
// ...
}
Related
I want to display application_no if payment method is FN in order details page.
I have created a block.
class Custom extends \Magento\Framework\View\Element\Template
{
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
array $data = []
) {
parent::__construct($context, $data);
}
}
Also, I have created a sales_order_view.xml to display my application_no (Tested it with static value and working fine).
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="left">
<referenceContainer name="payment_additional_info">
<block class="Limesharp\FinanceNow\Block\Adminhtml\Order\View\Custom" name="sales_order_view_custom" template="order/view/custom.phtml" />
</referenceContainer>
</referenceContainer>
</body>
</page>
Here is my view file -
FN: <?php echo $block->getOrder(); ?>
Now I wanna pass application_no(custom column already in sales_order table) and payment_method. How can I pass this information from block to view of current order and display it conditionally?
Hi I want to add "VAT excl " text after the product price in single product page . How can i do this . Which file i need to edit . Please suggest the correct path
app/design/frontend/mythemes/default/Magento_Catalog/templates/
Method - 1: If you want to display custom text only in product view page, then create catalog_product_view.xml in your custom theme
app/design/frontend/Vendor/theme/Magento_Catalog/layout/catalog_product_view.xml
<?xml version="1.0" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="product.info.main">
<block class="Magento\Framework\View\Element\Template" name="custom.text" template="Magento_Catalog::view/customtext.phtml" after="product.info.price"/>
</referenceContainer>
</body>
</page>
Now create customtext.phtml and add your custom text
app/design/frontend/Vendor/theme/Magento_Catalog/templates/view/customtext.phtml
Now flush the cache and check
Method - 2: If you want to display custom text after price at everywhere then override final_price.phtml
FROM
vendor/magento/module-catalog/view/base/templates/product/price/final_price.phtml
TO
app/design/frontend/Vendor/theme/Magento_Catalog/templates/product/price/final_price.phtml
Method - 3: Last and the most simple way to do it with CSS
.product-info-price .price:after {
content: 'Custom Text';
}
I would like to add 2 custom attributes after the product name EVERYWHERE in the magento 2 shop.
Like "Productname Attribute1 Attribute2"
Is this possible and how? Do i need to modify every page or is there a way to act directly on the product name rendering for the whole system?
thanks
Fot that you have to create extension. Please check my code
Create folder in app/code/Magenest
Create sub folder in app/code/Magenest/Sample
Now create registration.php with following code
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Magenest_Sample',
__DIR__
);
Create etc folder in app/code/Magenest/Sample/
Create module.xml in etc folder with following code
<?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="Magenest_Sample" setup_version="2.0.0">
</module></config>
Create folder in frontend in app/code/Magenest/Sample/etc/
Create a file di.xml file in app/code/Magenest/Sample/etc/frontend with following code
<?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" type="Magenest\Sample\Model\Product"/>
</config>
Now create a Model folder in app/Magenest/Sample/
Create Product.php in Model folder with following code
<?php
namespace Magenest\Sample\Model;
class Product extends \Magento\Catalog\Model\Product
{
public function getName()
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($this->_getData('entity_id'));
$myattribute = $product->getResource()->getAttribute('putyourcustomattribute')->getFrontend()->getValue($product);
$changeNamebyPreference = $this->_getData('name') . ' '. $myattribute;
return $changeNamebyPreference;
}
}
my over all goal is to grab the articles content after they have saved it and send it though my API. It's stated that onContentAfterSave is fired after they save to the database, my database is getting updated, but nothing coming though api.
Im using Joomla! 3.2.3 Stable
Owtest is my api call, it currently has hard coded data in it.
I feel im either extending the wrong class or missing an import. code below.
<?php
// no direct access
defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
class plgContentHelloworld extends JPlugin
{
public function onContentAfterSave( $context, &$article, $isNew )
{
owTest();
}
}
?>
Xml Code:
<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5" type="plugin" group="content" method="upgrade">
<name>plg_content_helloworld</name>
<author>Keith</author>
<creationDate>March 18th, 2014</creationDate>
<copyright></copyright>
<license>GNU General Public License</license>
<authorEmail></authorEmail>
<version>1.0</version>
<files>
<filename plugin="helloworld">helloworld.php</filename>
<filename>index.html</filename>
</files>
</extension>
file names are helloworld.php and helloworld.xml respectfully.
what solved my problem was passing article by value and not reference
I'm using MVC sitemap for MVC3 but having problems with it.
Consider the following sitemap file:
<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">
<mvcSiteMapNode title="Home" controller="Home" action="Index" changeFrequency="Always" updatePriority="Normal" Description="Test HOME">
<mvcSiteMapNode title="Today" controller="Dashboard" action="Today" />
<mvcSiteMapNode title="Today1" controller="Dashboard" action="Today1" />
<mvcSiteMapNode title="Today2" controller="Dashboard" action="Today2" />
<mvcSiteMapNode title="Today3" controller="Dashboard" action="Today3" />
<mvcSiteMapNode title="Today4" controller="Dashboard" action="Today4" />
</mvcSiteMapNode>
</mvcSiteMap>
When I load my web page up I only get the following options:
Today1, Today2, Today3, Today4
But Today is not displayed. This is an action on a controller whereas the other actions don't exist. Why is it hiding the item which actually exists on the controller? I took off authorization on the controller to rule out it had anything to do with authorization but still same effect.
This is the sitemap config (set in web.config):
<siteMap defaultProvider="MvcSiteMapProvider" enabled="true">
<providers>
<clear />
<add name="MvcSiteMapProvider"
type="MvcSiteMapProvider.DefaultSiteMapProvider, MvcSiteMapProvider"
siteMapFile="~/Mvc.Sitemap"
securityTrimmingEnabled="true"
cacheDuration="5"
enableLocalization="true"
scanAssembliesForSiteMapNodes="false"
includeAssembliesForScan=""
excludeAssembliesForScan=""
attributesToIgnore="visibility"
nodeKeyGenerator="MvcSiteMapProvider.DefaultNodeKeyGenerator, MvcSiteMapProvider"
controllerTypeResolver="MvcSiteMapProvider.DefaultControllerTypeResolver, MvcSiteMapProvider"
actionMethodParameterResolver="MvcSiteMapProvider.DefaultActionMethodParameterResolver, MvcSiteMapProvider"
aclModule="MvcSiteMapProvider.DefaultAclModule, MvcSiteMapProvider"
siteMapNodeUrlResolver="MvcSiteMapProvider.DefaultSiteMapNodeUrlResolver, MvcSiteMapProvider"
siteMapNodeVisibilityProvider="MvcSiteMapProvider.DefaultSiteMapNodeVisibilityProvider, MvcSiteMapProvider"
siteMapProviderEventHandler="MvcSiteMapProvider.DefaultSiteMapProviderEventHandler, MvcSiteMapProvider" />
</providers>
</siteMap>
</system.web>
I find out the problem.
The HttpContext user's InRole() method is used in the MvcSiteMapProvider.DefaultAclModule within the library code.
I am using Forms Authentication which means the InRole will never work as the roles property on the user context is not set (it doesn't know how roles are applied).
I could either write my own aclmodule provider which checks the authentication ticket for the roles stored within the ticket, or alternatively for every authentication request event in global.asax, set the context with the roles set. In the end I chose the latter:
e.g.
if (HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.User.Identity is FormsIdentity)
{
FormsIdentity formsId = (FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = formsId.Ticket;
// need to do this so MVC sitemap IsInRole works inside default acl module: MvcSiteMapProvider.DefaultAclModule
var authData = new AuthenticationModel(ticket.UserData);
var roles = new List<string>(authData.EffectiveRoles).ToArray();
HttpContext.Current.User = new GenericPrincipal(formsId, roles);
}
}
}
#jaffa, your approach helped me !! thanks. Here, is how I implemented it.. maybe it can help others too!
public class MenuVisibilityController : Controller, ISiteMapNodeVisibilityProvider
{
public bool IsVisible(SiteMapNode Node, HttpContext context, IDictionary<string, object> sourceMetadata)
{
return context.User.Identity.IsAuthenticated;
}
}
Implemented Visibility Provider for MVC sitemap and then used it for visibility of a particular node like below:
<mvcSiteMapNode title="Test Menu" controller="Account" action="Index" visibilityProvider="MyProject.Controllers.MenuVisibilityController, MyProject">
<mvcSiteMapNode title="Test Item 1" controller="Account" action="GetItems" />
</mvcSiteMapNode>
specifying implemented controller in VisibilityProvider should serve the purpose.