I am new in magento i am getting issue while calling the view.phtml file in custom layout.
Folowing is my code which is i am including in cutom layout file but i am getting Fatal error
Fatal error: Call to a member function getMetaTitle() on a non-object in D:\wamp\www\projects\magento\app\code\core\Mage\Catalog\Block\Product\View.php on line 56.
<?php echo $this->getLayout()->createBlock('catalog/product_view')->setTemplate('catalog/product/view.phtml')->toHtml(); ?>
Please reply me for this issue.
Thanks in advance.
Your error occurs in the file D:\wamp\www\projects\magento\app\code\core\Mage\Catalog\Block\Product\View.php on this line
$product = $this->getProduct();
$title = $product->getMetaTitle();
When you create a block you do not specify a product for which the block is created, and this is an important and required parameter.
Function to get the product :
public function getProduct()
{
if (!Mage::registry('product') && $this->getProductId())
{
$product = Mage::getModel('catalog/product')->load($this->getProductId());
Mage::register('product', $product);
}
return Mage::registry('product');
}
Do you actually have one option how to fix this problem, but it is not quite beautiful, but working.
<?php
Mage::register('product',Mage::getModel('catalog/product')->load(YOUR_PRODUCT_ID));
echo $this->getLayout()->createBlock('catalog/product_view')->setTemplate('catalog/product/view.phtml')->toHtml();
Mage::unregister('product');
?>
This decision can not be used on the product page.
You shouldn't instantiate a Block like that.
Take a look at the standard product page to understand how it works :
You have a controller named catalog/product/view wich is defined in the Mage_Catalog_ProductController class
This controller is linked to a Layout update handle defined in the catalog.xml file in app/design/package/theme/layout/catalog.xml
In this layout file, you'll see that the block catalog/product_view is declared with a few children :
<catalog_product_view translate="label">
[...]
<reference name="content">
<block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
<block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>
<block type="core/text_list" name="alert.urls" as="alert_urls" translate="label">
<label>Alert Urls</label>
</block>
[...]
This this the part you're missing by instantiate it manually.
You must adapt/understand the layout in catalog.xml for your needs
Good luck
Related
If I click on a product from my product overview on the left side, the shop does not load with the list.phtml. As soon as I swap view to grid or list, it swaps to the list.phtml file and everything is fine. But as I said, if I click on the products on the sidebar, it doesnt work (it's not even affected by list.phtml at all). I removed all the code inside it and it still showed (a bit different, that's why I want to change it) the products, but as soon as I swapped mode, everything disappeared -- as it should. Do you know where I can change that?
Thank you.
It should use list.phtml file. In that file it is defined for both list mode and grid mode.
<?php echo $this->getToolbarHtml() ?>
<?php // List mode ?>
<?php if($this->getMode()!='grid'): ?>
<?php $_iterator = 0; ?>
And
<?php else: ?>
<?php // Grid Mode ?>
<?php $_collectionSize = $_productCollection->count() ?>
You can see something like above code in your list.phtml file,one is for list mode and another for grid mode. This is the default case unless you haven't changed the layout or template code.
If you want to know the file location than you can always enable template path hint. If you don't know how to do that you can follow this.
After knowing from which file it is rendering you can fix it.
Hope this will help.
I am trying to write my first simple Sitecore Speak Component.
Nothing fancy about it i just need to get started. So i create in Visual Studio my Speak Component and in Sitecore i have my rendering that is pointing to my component. This is all out of the box. I insert my rendering on my SPEAK layout and when i visit the page i get an error saying this
Anyone has an idea why? What do i have to do? I am using Sitecore 7.5.
My cshtml looks like this:
#using Sitecore.Mvc
#using Sitecore.Mvc.Presentation
#using Sitecore.Web.UI.Controls.Common.UserControls
#model RenderingModel
#{
var rendering = Html.Sitecore().Controls().GetUserControl(Model.Rendering);
rendering.Class = "sc-Test2";
rendering.Requires.Script("client", "Test2.js");
var htmlAttributes = rendering.HtmlAttributes;
}
<div #htmlAttributes>
</div>
Basically the issue here is Sitecore SPEAK is unable to locate your javascript for the component.
It appears that you have your SPEAK component rendering and javascript in your own directory which is best practice. What you have to do is tell SPEAK where to look for your components. This is controlled within the Sitecore SPEAK config within the Include folder.
Here is an example of a patch include file to patch in directories for SPEAK to look for javascript components.
Set the source to the directory containing your custom components.The Deep = true parameters will scan subdirectories. Also note the category name here "MikeRobbins" in this example. Choose anything meaningful to your components, i would avoid using the Sitecore one not to impact sitecore standard components.
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<speak.client.resolveScript>
<processor type="Sitecore.Resources.Pipelines.ResolveScript.Controls, Sitecore.Speak.Client">
<sources hint="raw:AddSource">
<source folder="/sitecore/shell/client/MikeRobbins/Layouts/Renderings" deep="true" category="mikerobbins" pattern="*.js,*.css" />
</sources>
</processor>
</speak.client.resolveScript>
</pipelines>
</sitecore>
</configuration>
Update your component CSHTML and set the userControl.Requires.Script("mikerobbins"..... part to your category name you chose above. see example below.
#using Sitecore.Mvc
#using Sitecore.Mvc.Presentation
#using Sitecore.Web.UI.Controls.Common.UserControls
#model RenderingModel
#{
var userControl = Html.Sitecore().Controls().GetUserControl(Model.Rendering);
userControl.Requires.Script("mikerobbins", "JsonDataSource.js");
userControl.Attributes["type"] = "text/x-sitecore-jsondatasource";
userControl.DataBind = "Json: json";
var htmlAttributes = userControl.HtmlAttributes;
}
<script #htmlAttributes>
</script>
An example of this can be seen in my project here. https://github.com/sobek1985/SitecoreSPEAKBulkRolePermissions
Hope this helps, any problems give me a shout.
You can also specify the full javascript path in the Requires.Script method.
rendering.Requires.Script("/sitecore/shell/client/MikeRobbins/Layouts/Renderings/Test2.js");
Ok, with some help I found the code to add a new application / section without modifying the config manually. Add an assmebly with this class in the /bin folder and the section is automatically added to Umbraco.
[Application("guestbook", "Guestbook", ".trayguestbook", 20)]
public class Class1 : IApplication
{
Then you can modify the Tree by adding a class that inherits from BaseTree.
[Tree("guestbook", "guestbookTree", "Guestbook")]
public class Class2 : BaseTree
{
Is there a way to modify the dashboard with a similair approach as well?
Thanks!
As far as I know, there isn't a code first approach to modifying the dashboard.config. However, if you wrap your project into an Umbraco package, you can use package actions to add a dashboard section. Here's an example from the documentation:
<Action runat="install" alias="addDashboardSection" dashboardAlias="MyDashboardSection">
<section>
<areas>
<area>default</area>
<area>content</area>
</areas>
<tab caption="Last Edits">
<control>/usercontrols/latestEdits.ascx</control>
<control>/usercontrols/PostCreate.ascx</control>
</tab>
<tab caption="Create blog post">
<control>/usercontrols/new.ascx</control>
</tab>
</section>
</Action>
For more details on package actions see Package Action Samples. For more information of creating Umbraco packages see How to create a project package for Umbraco?.
Does anyone know how to, without purchasing an addon/extension, add php code to the product and category descriptions? If you try to add it automatically gets commented out when you save, e.g. <!-- <?php echo "test" ?> -->
Workaround: For anyone else.. I used borderless iframe to include an external .php file which contained the php code I needed ....
The Crosssells do not seem to be working on my Magento EE install, for the product view page.
Ive debugged the product list crosssells block, but seems to crash out somewhere on its way through the various code, whilst collecting the collection. Cant work out why (whitescreens when debug to a certain level...and item collection thus not being set. Hard to figure out. No exceptions being logged).
I have no errors on the install...and sure i should not need to edit any logic, as the functionality is provided by default.
Ive followed this example:
http://www.magentocommerce.com/boards/viewthread/51529/
My crossells show on the cart page, as they usually do...but i cant get them to display on my product view page.
Heres my bits of code:
Catalog.xml:
<block type="catalog/product_list_crosssell" name="product.info.crosssell" as="crosssell_products" template="catalog/product/list/crosssell.phtml"/>
product/list/crosssell.phtml:
if(count($this->getItems())): ?>
<div id="also_bought_productslist" class="inner">
<?php $i=0;
foreach ($this->getItems() as $product):
Anyone know what i may be missing. And has anyone added crossells to their product view page?
Just to clarify...THIS IS USING THE DEFAULT PRODUCT_LIST_CROSSELL block...and im NOT trying to utilise the checkout/cart/crossell code (i know this relies on cart functionality/data to work correctly. I did attempt this though, and still get no crossell items....but they DO show in the cart page.)
many thanks
Syntax within the catalog xml file. Namely, an AFTER="blahblah" declaration...and use of same block code twice
Old code:
<block type="catalog/product_list_crosssell" name="product.info.crosssell" as="crosssell_products" template="catalog/product/list/crosssell.phtml"/>
<block type="catalog/product_list_related" name="alsoboughttabs" after="forgettoaddproducts" template="pagetabs/alsobought_pagetabs.phtml" />
<block type="catalog/product_list_related" name="forgettoaddproducts" after="product.info" template="catalog/product/list/dontforgettoadd.phtml" />
New code:
<block type="catalog/product_list_crosssell" name="product.info.crosssell" as="crosssell_products" template="catalog/product/list/crosssell.phtml"/>
<block type="catalog/product_list_upsell" name="alsoboughttabs" template="pagetabs/alsobought_pagetabs.phtml" />
<block type="catalog/product_list_related" name="forgettoaddproducts" after="product.info" template="catalog/product/list/dontforgettoadd.phtml" />