I am unable to make magento display static CMS block under category > display settings.
Contents of app/design/frontend/base/default/template/catalog/category/view.phtml seem to be correct as per similar question on SE. Here you go:
<?php if($this->isContentMode()): ?>
<?php echo $this->getCmsBlockHtml() ?>
<?php elseif($this->isMixedMode()): ?>
<?php echo $this->getCmsBlockHtml() ?>
<?php echo $this->getProductListHtml() ?>
<?php else: ?>
<?php echo $this->getProductListHtml() ?>
<?php endif; ?>
I have configured 3 categories, lets say
category_a (only products)
category_b (both products and cms)
category_c (only cms block).
Things I tried which don't work:
Disabled custom theme and used default theme of magento.
Replaced view.phtml from another magento installation (where its working fine).
Replace the if-else block with
<?php if($this->isContentMode()): ?>
MODE: CMS
<?php echo $this->getCmsBlockHtml() ?>
<?php elseif($this->isMixedMode()): ?>
MODE: MIXED
<?php echo $this->getCmsBlockHtml() ?>
<?php echo $this->getProductListHtml() ?>
<?php else: ?>
MODE: PRODUCTS
<?php echo $this->getProductListHtml() ?>
<?php endif; ?>
This displayed MODE: PRODUCTS for all 3 cases (product / cms / mixed)
Removing the if-else block and using only lines to force magento to display both cms and product blocks. Assuming the control was not flowing to correct block.
<?php echo $this->getCmsBlockHtml() ?>
<?php echo $this->getProductListHtml() ?>
Only product block got displayed for all 3 categories mentioned above (product / cms / mixed)
I can see that there are 2 problems here, or atleast I think so.
category display mode is always coming as "products only"
getCmsBlockHtml() does not return anything
so I tried following code snippet based on Mage_Catalog_Block_Category_View
Product:
<?php echo $this->getCurrentCategory()->getDisplayMode()==Mage_Catalog_Model_Category::DM_PRODUCT; ?>
MIXED:
<?php echo $this->getCurrentCategory()->getDisplayMode()==Mage_Catalog_Model_Category::DM_MIXED; ?>
CMS:
<?php echo $this->getCurrentCategory()->getDisplayMode()==Mage_Catalog_Model_Category::DM_PAGE; ?>
and got response as >>Product: MIXED:1 CMS: for all three category display modes (product / cms / mixed).
Can someone help me out please.
I have disabled caches and have tried reindexing also.
I found a fix for my issue here
Magento 1.9.2.0
App/Code/Core/Mage/Catalog/Block/Category/View.php
inside function getCmsBlockHtml
On Line 109 it read
return
but should read
return $this->getData('cms_block_html');
Regards paul
Related
I trying to loop through posts in a custom php page but no matter what I do, no posts are found
here is the code I wrote in my-custom-page.php
<?php
require_once("/wp-load.php");
get_header();?>
<div id="blog">
<?php if(have_posts()) : ?>
<?php echo"anything"; ?>
<?php endif; ?>
</div>
<?php get_footer();?>
You should require wp-load.php via the full path to this file.
Hardcoded example:
require_once("user/home/public-html/wordpress/wp-load.php");
Softcoded example (suposing your file is in the same directory as WordPress):
require_once(dirname(__FILE__)."/wp-load.php");
You have also to query the posts before you display them. So, you need to add this line to your code:
query_posts('post_type=post');
The query arguments may vary depending on what you want to display. Some of them are the member variables of the WP_Post class. Go to https://codex.wordpress.org/Class_Reference/WP_Post for reference.
Here you have a re-writing of your code that displays the titles of the 30 latest posts published:
<?php
require_once(dirname(__FILE__)."/wp-load.php");
query_posts('post_type=post&showposts=30');
get_header();?>
<div id="blog">
<?php
if (have_posts()) :
while (have_posts()) :
the_post();
the_title();
echo '<br />';
endwhile;
else :
echo 'Sorry, no posts found.';
endif;?>
</div>
<?php get_footer();
wp_count_posts :
#return object Number of posts for each status.
you're trying to echo an object which ends in a fatal error. Furthermore if you want to see all posts the_post is not right. Look for it at the function reference : https://codex.wordpress.org/Function_Reference/the_post. I would do it other (google smth like "get all posts").
if you will use the code inside your theme
use the same code of Mr.Carlos but with out dir
require_once("/wp-load.php");
Firstly I would like to apologise if this question has been answered somewhere else but I am unable to find what I am looking for as I am new to PHP and assume I need this to solve my problem.
I have built a website and am using Mals-e shopping cart. I have everything up and running but I would like to show how many products are still in stock under the product description and if there are no items in stock. For example:
Available stock: 2
or
Sold Out
I have read that I need a text file with product name, price and quantity, a PHP file to read and rewrite the quantity available and out put the results on the product page and a mypage.php page but I really don't know where to start. I've spent days trying to sort this out.
I have Mysql database with some items in table called (items) with available quantity but don't know how to go about sorting it out. Any help would be most appreciated.
Thank you.
Without seeing the actual code you're using to display the product, it's hard to say buy all you should need is something like:
<?php
// get the product and stock level
if($product->numberInStock > 0) {
echo 'Available: ' . $product->numberInStock;
} else {
echo 'Out of stock';
}
If you're editing a phtml type template (HTML with embedded PHP), you might display it like:
<? if($product->numberInStock > 0): ?>
<p>Available: <?= $product->numberInStock; ?></p>
<? else ?>
<p>Out of stock</p>
<? endif; ?>
Had same issue, found out following.
Inside your catalog/product type template you can use this:
<?php
$_product = $this->getProduct();
$_qty = $_product->getStockItem()->getQty();
?>
<p>
<?php if($_qty > 0): ?>
Available: <?php echo $_qty; ?>
<?php else: ?>
Out of stock
<?php endif; ?>
</p>
session_start($_POST['quantity']);
if(isset($_POST['quantity']))
{
$postedquantity=$_POST['quantity'];
$productQuantity="20";
if($postedquantity<$productQuantity){
echo "In stock";
echo "<br/>";
}
$productQuantity=$productQuantity-$postedquantity;
echo $productQuantity."Remaining";
}
You can even do like this,storing quantity value in session and everytime it's posted it will check whether it is in stock or not and it will show how much quantity is remaining.
I was looking for a way to display the "estimated delivery" of a product by using the attribute 'delivery' I've made.
So far I've managed to put together this:
<?php $delivery= Mage::getSingleton('catalog/product')->load($this->getProduct()->getId())->getAttributeText('Delivery'); ?>
<?php if(isset($delivery)){
echo $delivery;
}
?>
I have added this piece to:
template/checkout/cart/item/default.phtml - between line 38/39 (Magento Version 1.6.2)
Here is the default.phtml from line 35-49 with the code added to the h2 tag:
<h2 class="product-name">
<?php $_item = $this->getItem()?>
<?// Delivery - Script ?>
<?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProductId()) ?>
<?php $delivery= Mage::getSingleton('catalog/product')->load($this->getProduct()->getId())->getAttributeText('Delivery'); ?>
<?php if(isset($delivery)){
echo $delivery;
}
?>
<?php if ($this->hasProductUrl()):?>
<?php echo $this->htmlEscape($this->getProductName()) ?>
<?php else: ?>
<?php echo $this->htmlEscape($this->getProductName()) ?>
<?php endif; ?>
</h2>
The problem is, the first product added to cart is being skipped, it's always showing the attribute as not set, but the second, third and rest of the products added to cart, works great, showing their est. delivery date just fine.
From here, I'm unsure how to proceed?
Use of singleton will result in same object being called repeatedly so previous object data will get overwritten.
Once you changed from singleton to getModel you have an instance for each product so no over writing on same instance.
After some Google'ing I found this, which seems to work - But I still cannot see why, and what the big difference is, if anyone would like to clarify it, I would be very happy.
This is the working solution, it's so simple, yet I don't understand:
<?php
$custom = Mage::getModel('catalog/product')->load($_item->getProductId());
echo $custom->getAttributeText('delivery');
?>
This does not skip the first product?
app/design/frontend/{YOURTEMPLATE}/default/template/checkout/cart/item/default.phtml
Past this code:
<?php $_item = $this->getItem(); ?>
<?php $_product = $_item->getProduct()->load(); ?>
<?php $_product->get{YOUR ATTRIBUT HERE}(); ?>
I am trying to understand the dependancies of catalog/product.view.phtml. A lot seems to depend on the following code:
<?php foreach ($this->getChildGroup('detailed_info', 'getChildHtml') as $alias =>$html):?>
<div class="box-collateral < ?php echo "box-{$alias}"?>
<?php echo $html;?>
</div>
<?php endforeach;?>
With this code in place I can pull in the product options, availabilty and buy now button with the following code:
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<?php endif;?>
<?php echo $_helper->productAttribute($_product, $_product->getDescription(), 'description') ?>
The difficulity is I wish to have them appear after the description which is contained within .box-collateral
This seems to present a problem in so much as when I move the latter snippet above the first one, the buy now button still appears but the options do not- (the same thing happens when I simply remove the first snippet)- leading in me to think that these depend on some of the data being pulled by this?
I am able to add the description at the bottom using
<?php echo $_helper->productAttribute($_product, $_product->getDescription(), 'description') ?>
however hacky css aside I still can't find a way to stop the description appearing above.
Any pointers, directions or consise explainations appreciated.
(I found this similar question but the file the answer points to just leads to more child_html I don't know the origin of)
Thanks
I have a site running on Magento and i have build some hand made code onto the view.phtml and list.phtml
<?php $category = Mage::getModel('catalog/layer')->getCurrentCategory();?>
<?php if($category->getId()==80): ?>
Command what to do
<?php else: ?>
Else command this
<?php endif; ?>
What i would like to make is to check more categories ( like eg. 80,81 ) before echo it.
How do i have to change the code?
Use in_array()
<?php if(in_array($category->getId(), array(80, 81, ...))): ?>
If you want different code for the various categories:
<?php if($category->getId()==80): ?>
...
<?php elseif($category->getId()==81): ?>
...