Add to cart button not adding product in cart - magento

I have created a new1.phtml file in catalog/product with following content
<?php
//getting new product collection
$product=Mage::getModel("catalog/product")->getCollection();
$filtered_prodduct=$product->addAttributeToSelect("*")
->setOrder("created_at","desc")
->addPriceData();
echo "<ul>
<li>";
$i=0;
$row=3;
foreach($filtered_prodduct as $prod){
$i++;
if($i>$row*3){
break;
}
?>
<div class="prod_box">
<div class="center_prod_box">
<div class="product_title">
<a href="<?php echo $prod->getProductUrl()?>">
<?php echo $prod->getName() ?>
</a>
</div>
<div class="product_img">
<a href="<?php echo $prod->getproductUrl()?>">
<img src="<?php echo $prod->getImageUrl()?>" alt="" border="0" height="100" width="100">
</a>
</div>
<div class="prod_price">
<span class="reduce"><?php echo $prod->getSpecialPrice()?></span>
<span class="price"><?php echo $prod->getPrice()?></span><br/>
</div>
</div>
<div class="prod_details_tab">
<?php if($prod->isSaleable()): ?>
<a href="<?php echo $this->getUrl()?>checkout/cart/add? product=<?php echo $prod->getId(); ?>&qty=1" class="prod_buy">
<?php echo $this->__('Add') ?>
</a>
<?php else: ?>
<p class="availability out-of-stock"><span>
<?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<a href="<?php echo $prod->getProductUrl()?>" class="prod_details">
Details
</a>
</div>
</div>
<?php }
?>
Every thing is ok ,but 'Add' button (means add to cart) is not working .It just opens checkout/cart.
i have added this phtml file in layout xml of home page. what is wrong in the code ?

You can do this my using below code ,which generated add to cart url.
Mage::helper('checkout/cart')->getAddUrl(($prod);
If product type is configurable and group or if product type is simple and it have customoption ,then it did not cart directly without selecting any options

The controller's action validates request therefore you should send formKey
public function addAction()
{
if (!$this->_validateFormKey()) {
$this->_goBack();
return;
}
...
{

Mage::helper('checkout/cart')->getAddUrl(($prod);

Related

magento move configurble product options using css

please visit these links:
configurable product
simple product
in configurable product, i want to move "color" & charactar to top of the page.
i want to move this above "Check Delivery Availability " block.
Means i want this next to text "Age: 2 Years & Above". There is a gap after 4 lines. i want to move color and charactar there.
please help me to find solution.
This is view.phtml
<?php
?>
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $pageLayout = str_replace(array('page/','.phtml'),'',Mage::app()->getLayout()->getBlock('root')->getTemplate()); ?>
<?php $_product = $this->getProduct(); ?>
<?php $setting = Mage::helper('em0113settings'); ?>
<script type="text/javascript">
var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<div class="Individual">
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
<div class="product-view">
<div class="product-essential">
<form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php echo $this->getBlockHtml('formkey') ?>
<div class="no-display">
<input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
<input type="hidden" name="related_product" id="related-products-field" value="" />
</div>
<div class="product-img-box" style="width:<?php echo $setting->getImageProduct_BaseImageWidth(390) ?>px;">
<?php echo $this->getChildHtml('media') ?>
</div>
<?php
$related_product_collection = $_product->getRelatedProductCollection();
$related_product_collection->AddStoreFilter();
$count = count($related_product_collection);
?>
<div class="product-shop <?php if($count > 0 && $pageLayout=='1column'): ?>has-related<?php else: ?>no-related<?php endif ?>">
<div class="product-shop-wrapper <?php if($_product->isGrouped()): ?>grouped<?php endif ?>">
<?php list($_prev_prod, $_next_prod) = Mage::helper('em0113settings/product')->getPreviousNextProducts($this->getProduct()); ?>
<!--<?php if($_prev_prod != NULL): ?>
<?php echo $this->__('Previous') ?>
<?php endif; ?>
<?php if($_next_prod != NULL): ?>
<?php echo $this->__('Next') ?>
<?php endif; ?>-->
<div class="product-name">
<h2><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h2>
</div>
<?php echo $this->getReviewsSummaryHtml($_product, false, true)?>
<!--<?php if ($this->canEmailToFriend()): ?>
<p class="email-friend"><?php echo $this->__('Email to a Friend') ?></p>
<?php endif; ?>-->
<div class="Pro_des">
<?php if ($_product->getShortDescription()):?>
<div class="short-description">
<hr>
<br/>
<!-- <h2><?php echo $this->__('Quick Overview') ?></h2> -->
<div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
</div>
<?php endif;?>
</div>
<!--
<?php if ($this->displayProductStockStatus()): ?>
<?php if($_product->isSaleable()): ?>
<p class="availability in-of-stock"><span><?php echo $this->__('In of stock') ?></span></p>
<?php else : ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<?php endif; ?>
-->
<hr class="hr">
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<?php endif;?>
<hr class="hr">
<div class="check_delivery">
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('checkdelivery/checkdelivery.phtml')->toHtml();?>
</div>
<div class="Quick">
<div class="Quick_1">
<!--<?php if ($_product->getShortDescription()):?>
<div class="short-description">
<h2><?php echo $this->__('Quick Overview') ?></h2>
<div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
</div>
<?php endif;?>-->
<div class="product-data">
<?php echo $this->getChildHtml('alert_urls') ?>
<?php echo $this->getChildHtml('product_type_data') ?>
<?php echo $this->getChildHtml('extrahint') ?>
<?php echo $this->getTierPriceHtml() ?>
</div>
<?php if (!$this->hasOptions()):?>
<div class="add-to-box">
<?php if($_product->isSaleable()): ?>
<?php echo $this->getChildHtml('addtocart') ?>
<?php else:?>
<?php echo $this->getChildHtml('addto') ?>
<?php endif; ?>
<!-- <?php if ($_product->isAvailable()) {?>
<div><?php //$buttonTitle = $this->__('Add to Cart'); ?>
<button type="button" title="<?php //echo $buttonTitle ?>" id="product-addtocart-button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php //echo $buttonTitle ?></span></span></button>
</div>
<br/>
<div ><button class="button buy-now" onclick="location.href ='{{config path="web/unsecure/base_url"}}/checkout/cart/add?product=1&qty=1'">
<span><span>Buy Now</span></span></button>
</div>
<?php }?>-->
</div>
<?php echo $this->getChildHtml('extra_buttons') ?>
<?php elseif (!$_product->isSaleable()): ?>
<div class="add-to-box">
<?php echo $this->getChildHtml('addto') ?>
</div>
<?php endif; ?>
</div>
<div class="Quick_2">
<!-- Soled By -->
<div class="soled_by">
<?php
$helper=Mage::helper('marketplace');
$_product=Mage::registry('current_product');
$productowner=Mage::getModel('marketplace/product')->isCustomerProduct($_product['entity_id']);
if($productowner['userid']!=""){
$captchenable = $percent = Mage::getStoreConfig('marketplace/marketplace_options/captcha');
$rowsocial=Mage::getModel('marketplace/userprofile')->getPartnerProfileById($productowner['userid']);
}
?>
<script type="text/javascript">
if (typeof jQuery == 'undefined'){
document.write(unescape("%3Cscript src='//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
<div class="soled-by-dealer">
<!--<div class="block-title"><strong><span>
<?php if($rowsocial['shoptitle']!='')
echo $rowsocial['shoptitle'];
else
echo $rowsocial['profileurl']; ?>
</span></strong>
</div>-->
<h5> SOLD BY : </h5>
<span>
<?php if($rowsocial['profileurl'] == "kidsdial2")
{?>
<a href="<?php echo Mage::getUrl('marketplace/seller/collection').$rowsocial['profileurl'] ?>" title="<?php echo "Totaltoys"; ?>" id="siteconnect">
<?php echo "Totaltoys"; ?></a><?php
}
else{?>
<a href="<?php echo Mage::getUrl('marketplace/seller/collection').$rowsocial['profileurl'] ?>" title="<?php echo $rowsocial['profileurl']; ?>" id="siteconnect">
<?php echo $rowsocial['profileurl']; ?></a><?php
}
?>
</span>
</div>
<br/>
<div class="delivery_details">
<div class="COD">
<?php $attribute = $_product->getResource()->getAttribute('cod_available');
$attribute_value = $attribute ->getFrontend()->getValue($_product);
if ($attribute_value == "Yes"){ ?>
<h5> CASH ON DELIVERY </h5>
<div class="Delivery_hover_details">?<p class="killing"><?php echo "Available";?></p></div>
<?php }else{ ?>
<i class="fa fa-times"></i>
<p>
<h5 style="position:relative;bottom: 11px;">CASH ON DELIVERY </h5>
<p class="reduce"><?php echo " Not Available"; ?></p>
</p>
<?php } ?>
<span class="coupontooltip">
<div class="cod_content">
<h5>How do I place a Cash on Delivery (COD) order?</h5>
<p>All items that have the "Cash on Delivery Available" icon are valid for order by Cash on Delivery.</p>
<p>Add the item(s) to your cart and proceed to checkout.When prompted to choose a payment option, select "Cash on Delivery". </p>
<p>Once you place the order you will receive confirmation call from our customer support for validation with in 48 hours. Once verified and confirmed, your order will be processed for shipment in the time specified, from the date of confirmation. You will be required to make a cash-only payment to our courier partner at the time of delivery of your order to complete the payment.</p>
<p>Terms & Conditions</p>
<p>The maximum order value for COD is ₹5000.</p>
<p>e-Gift Vouchers or Store Credit cannot be used for COD orders.</p>
<p>Cash-only payment at the time of delivery.</p>
</div>
</span>
</div>
<div class= "bottom3">
<!-- wholesale available -->
<?php
//$product is your current product
if($_product->getTierPrice()) {
echo "
<div class = 'quickphp'>
<h5>Wholesale</h5>
Available.<br>
Usually Delivered in 10-15 business days.
</div>
";
}
else{
echo "
<div class = 'quickphp'>
<h5>Wholesale</h5>
Not Available.<br>
</div>
";
}
?>
<div class="avail">
<?php if ($this->displayProductStockStatus()): ?>
<?php if($_product->isSaleable()): ?>
<p class="availability in-of-stock"> <h5>Availability</h5> <?php echo $this->__('In Stock') ?></span></p>
<?php else : ?>
<p class="availability out-of-stock"> <h5>Availability</h5> <?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<?php endif; ?>
</div>
<div class="replace">
<span> <b>7 days</b> Replacement Guarantee</span>
<div class="Delivery_hover_details">?
<span class="coupontooltip">
<h5> How do I return an item purchased on Totaltoys.com</h5>
<p>Conveniently, you can call us at 092-434-22233 and email us at contact#totaltoys.com with order number, invoice number and product name. If you've received an item in a 'Damaged', 'Defective' or 'Not as Described' state.</p>
<h5>Return & Replacement policy:</h5>
<p>Returns or replacement request should be placed within 7 days from the date of delivery.</p>
<p>As we receive your request, our concerned team will contact you to validate the compliant. The validation process may require submitting of product photos. Once the validation process is completed then further action will be taken.
Once the product reaches to us/seller, the replacement will be proceed in 1-2 working days after physical inspection of the goods and shipment will be done simultaneously.</p>
<p>If you've received an item in a 'Damaged', 'Defective' or 'Not as Described' state, all replacements/pickups will be done free of cost.</p>
<p>If the packaging is tampered with or damaged, before accepting delivery of the goods, please refuse to take delivery of the package, and call us on 092-434-22233 or mail us at contact#totaltoys.com , mentioning your order reference number. We shall make our best efforts to ensure that a replacement delivery is made to you at the earliest.</p>
<p>In the rare circumstances where a pickup cannot be done, you can ship the product through any courier. You will be reimbursed the shipping charges against the original receipt.</p>
<p>Replacement is subjected to availability of stock. In case a replacement is not available, the amount will be refunded to your account from which the purchase was made. (Amount includes shipping and gift wrapping charges)</p>
<h5> Return Request is not Accepted If:</h5>
<li>Return request is made outside the specified time period</li>
<li>Missing of tags, labels, original packing, and invoice.</li>
<li>Misused or Mishandle of the product from customer end.</li>
<p>For all refunds we will refund the amount to same mode of payment as used during checkout. Refunds for cash on delivery will be made via online transfer of funds to the customers bank account.</p>
<p>If the customer chooses to cancel the order before the product is shipped, he will be entitled to a 100% refund.
Do I have to return the free gift when I return a product?</p>
<p>Yes. The free gift is included as part of the item order and needs to be returned along with the originally delivered product</p>
<p>Please contact us on contact#totaltoys.com or call us at 092-434-22233 for any doubts and concerns</p>
</span>
</div>
</div>
</div>
</div>
<div class="Delivery">
<h5> Delivered By </h5>
<div class="Delivery_hover_details">?
<span class="coupontooltip">
<div class="delivery_content">
<h5>What is the estimated delivery time?</h5>
<p>Sellers generally procure and ship the items within the time specified on the product page. Business days exclude public holidays and Sundays.</p>
<p>Estimated delivery time depends on the following factors:
<li>Time of the order, usually orders made after 2:00pm can be shipped only on next workingday</li>
<li>The Seller offering the product</li>
<li>Product's availability with the Seller</li>
<li>The destination to which you want the order shipped to and the Seller's location</li></p>
</div>
</span>
</div>
<ul class="fk-ul-disc">
<li>Usually Delivered in 3-5 business days.</li>
<li> Delivery Time may exceed than usual due to Festival Holidays</li>
</ul>
</div>
</div>
</div>
<!--<?php if (!$this->hasOptions()):?>
<div class="add-to-box">
<?php if($_product->isSaleable()): ?>
<?php echo $this->getChildHtml('addtocart') ?>
<?php else:?>
<?php echo $this->getChildHtml('addto') ?>
<?php endif; ?>
</div>
<?php echo $this->getChildHtml('extra_buttons') ?>
<?php elseif (!$_product->isSaleable()): ?>
<div class="add-to-box">
<?php echo $this->getChildHtml('addto') ?>
</div>
<?php endif; ?>-->
<?php echo $this->getChildHtml('other');?>
<?php echo $this->getChildHtml('short_des_after'); ?>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container1', '', true, true) ?>
<?php endif;?>
<?php echo $this->getChildHtml('shippingreturns') ?>
</div>
</div>
<!--<span class="or_buy_now"> -- OR --</span>-->
<!--<button type="button" title="<?php echo $buttonTitle ?>" id="product-addtocart-button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>-->
<!-- Buy Now -->
<div class="clearer"></div>
</form>
</div>
<!-- Add button share facebook -->
<?php if ($setting->getImageProduct_ViewSocial()): ?>
<div id="social-share" class="hide-lte0 hide-lte1 hide-lte2"></div>
<script type="text/javascript">
jQuery(document).ready(function($){
jQuery('#social-share').dcSocialShare({
buttons: 'facebook,plusone,twitter,pinterest',
twitterId: 'designchemical',
email: 'moc//niamod/liame',
align: 'right',
floater: false
});
});
</script>
<?php endif; ?>
<script type="text/javascript">
//<![CDATA[
var productAddToCartForm = new VarienForm('product_addtocart_form');
productAddToCartForm.submit = function(button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
try {
this.form.submit();
} catch (e) {
}
this.form.action = oldUrl;
if (e) {
throw e;
}
if (button && button != 'undefined') {
button.disabled = true;
}
}
}.bind(productAddToCartForm);
productAddToCartForm.submitLight = function(button, url){
if(this.validator) {
var nv = Validation.methods;
delete Validation.methods['required-entry'];
delete Validation.methods['validate-one-required'];
delete Validation.methods['validate-one-required-by-name'];
// Remove custom datetime validators
for (var methodName in Validation.methods) {
if (methodName.match(/^validate-datetime-.*/i)) {
delete Validation.methods[methodName];
}
}
if (this.validator.validate()) {
if (url) {
this.form.action = url;
}
this.form.submit();
}
Object.extend(Validation.methods, nv);
}
}.bind(productAddToCartForm);
//]]>
</script>
</div>
<div class="product-collateral">
<?php foreach ($this->getChildGroup('detailed_info', 'getChildHtml') as $alias => $html):?>
<div class="box-collateral <?php echo "box-{$alias}"?>">
<?php if ($title = $this->getChildData($alias, 'title')):?>
<h2><?php echo $this->escapeHtml($title); ?></h2>
<?php endif;?>
<?php echo $html; ?>
</div>
<?php endforeach;?>
<?php echo $this->getChildHtml('product_additional_data') ?>
<?php echo $this->getChildHtml('product_additional_collateral') ?>
</div>
<?php echo $this->getChildHtml('catalog.product.related'); ?>
<?php echo $this->getChildHtml('review_list') ?>
<?php echo $this->getChildHtml('upsell_products') ?>
<?php if (Mage::helper('em0113settings')->getImageProduct_UseTabs()): ?>
<script type="text/javascript">
//<![CDATA[
jQuery(window).ready(function() {
setTimeout(function() {
timeout = null;
EM.tools.decorateProductCollateralTabs();
}, 200);
});
//]]>
</script>
<?php endif ?>
</div>
<!-- mobile -->
<div class="set">
<?php $attributeSetModel = Mage::getModel("eav/entity_attribute_set");
$product=Mage::getModel('catalog/product')->load($_product->getId());
$attributeSetModel->load($product->getAttributeSetId());
$attributeSetName = $attributeSetModel->getAttributeSetName();
if($attributeSetName=='Mobile'){ echo $this->__('color may vary as shown in above image'); } ?>
</div>
<!-- mobile end-->
<style>
.reduce {
clear: both;
float: left;
bottom: 13px;
border-radius: 2px;
color: #666;
display: inline-block;
font-size: 11px;
height: 0px;
line-height: 6px;
position: relative;
text-align: center;
text-decoration: none;
}
.set {
position:relative;
bottom:950px;
}
</style>
Why do you want to move it using CSS, when you can move it via phtml file code.
Search for the below code:
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<?php endif;?>
MOVE and place this just BEFORE:
<div class="check_delivery">
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('checkdelivery/checkdelivery.phtml')->toHtml();?>
</div>
So your code will now look like:
<hr class="hr">
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<?php endif;?>
<hr class="hr">
<div class="check_delivery">
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('checkdelivery/checkdelivery.phtml')->toHtml();?>
</div>
After you have done this, CLEAR CACHE - Delete /var/cache and /var/full_page_cache (if applicable) folders.
Few additional inputs about your code, there are Magento Standard ways of coding which MUST be followed for best practices.
1. Like for example, you might want to clean up the code. Magento's recommendation is to use the below way of coding when adding any CONTENT via phtml files.
<?php echo $this->__('Your Content'); ?> //this is called TRANSLATION in Magento
This means, you should be doing something like this:
<span class="coupontooltip">
<div class="cod_content">
<h5><?php echo $this->__('How do I place a Cash on Delivery (COD) order?'); ?></h5>
...
...
..
</div>
</span>
This TRANSLATION helps when you are creating websites with a different locale.
2. Secondly, Recommendation for commenting out lines.
DO NOT comment out code using HTML comments. Use as below:
Single line comment
<?php //<b>Strong</b> ?>
Multi line comment
<?php /*<b>Strong</b>*/ ?>
3. DO NOT write CSS in the same phtml file
Use styles.css under /skin/frontend/yourpackage/youtheme/css folder
[Editing answer based on the modifications required]
Look for catalog.xml file inside /app/design/frontend/yourpackage/yourtheme/layout folder, Search for as="container2"
<catalog_product_view translate="label">
...
...
...
<block type="core/template_facade" name="product.info.container2" as="container2">
<action method="setDataByKey"><key>alias_in_layout</key><value>container2</value></action>
<action method="setDataByKeyFromRegistry"><key>options_container</key><key_in_registry>product</key_in_registry></action>
<action method="append"><block>product.info.options.wrapper</block></action>
<!--action method="append"><block>product.info.options.wrapper.bottom</block></action>
</block--> <!--comment out this line-->
<action method="unsetCallChild"><child>container1</child><call>ifEquals</call><if>0</if><key>alias_in_layout</key><key>options_container</key></action>
<action method="unsetCallChild"><child>container2</child><call>ifEquals</call><if>0</if><key>alias_in_layout</key><key>options_container</key></action>
</block>
...
</catalog_product_view>
To move the COLOR and CHARACTER dropdowns/options next to each other, update the code this way:
<div class="desc-options"> //add new div
<div class="Pro_des">
<?php if ($_product->getShortDescription()):?>
<div class="short-description">
<hr>
<br/>
<div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?>
</div>
</div>
<?php endif;?>
</div>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<?php endif;?>
</div>
Remove below code block from above "Check Delivery ..."
<hr class="hr">
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<?php endif;?>
Add CSS as below
styles.css line no: 1021, search for ".product-options"
Change the width: 100% to width: 50%;
In THEME CSS do the below:
.product-view .short-description { width: 50%; float:left; }
dl dt {
font-weight: bold;
display: block;
margin: 0 0 .5em;
}
.product-options dd {
margin: 4px 0;
display: inline-block;
}
To move ADD TO CART and BUY NOW buttons as Simple Product, update your code this way:
<div class="Quick_1">
<div class="product-data">
<?php echo $this->getChildHtml('alert_urls') ?>
<?php echo $this->getChildHtml('product_type_data') ?>
<?php echo $this->getChildHtml('extrahint') ?>
<?php echo $this->getTierPriceHtml() ?>
<?php echo $this->getChildHtml('product.info.options.wrapper.bottom') ?> // add this line
</div>
Let me know if this helps.
Happy Coding...

magento 2 how to display the category product in homepage?

<p>{{block type="catalog/product_list"
column_count="4"
category_id="13"
template="catalog/product/list.phtml"}}</p>
I have used the above code in magento version 1.x to display the category products in the home page
After updating to Magento version 2.0., the above code doesn't work anymore.
How can I rectify it?
{{widget type="Magento\CatalogWidget\Block\Product\ProductsList"
products_count="4"
template="product/widget/content/grid.phtml"
conditions_encoded="a:2:[i:1;a:4:[s:4:`type`; s:50:`Magento|CatalogWidget|Model|Rule|Condition|Combine`;s:10:`aggregator`;s:3:`all`;s:5:`value`;s:1:`1`;s:9:`new_child`;s:0:``;]s:4:`1--1`;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Product`;s:9:`attribute`;s:12:`category_ids`;s:8:`operator`;s:2:`==`;s:5:`
value`;s:1:`13`;]]"}}
in the above code last line, 13 represents the category id
change the category_id as you need
Try this
{{block type="core/template" column_count="4" category_id="13" template="catalog/product/list.phtml"}}
after that go to yourtheme/catalog/product/list.phtml and then something try to print or echo at the top of this file
Hope it will work
{{widget type="Magento\CatalogWidget\Block\Product\ProductsList"
products_count="4"
template="product/widget/content/grid.phtml"
conditions_encoded="a:2:[i:1;a:4:[s:4:`type`; s:50:`Magento|CatalogWidget|Model|Rule|Condition|Combine`;s:10:`aggregator`;s:3:`all`;s:5:`value`;s:1:`1`;s:9:`new_child`;s:0:``;]s:4:`1--1`;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Product`;s:9:`attribute`;s:12:`category_ids`;s:8:`operator`;s:2:`==`;s:5:`
value`;s:1:`13`;]]"}}
try this code
<p>{{widget type="Magento\CatalogWidget\Block\Product\ProductsList" title="CTlog" show_pager="1" products_per_page="5" products_count="10" template="product/widget/content/grid.phtml" conditions_encoded="a:1:[i:1;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Combine`;s:10:`aggregator`;s:3:`all`;s:5:`value`;s:1:`1`;s:9:`new_child`;s:0:``;]]" page_var_name="pmqabw"}}</p>
Try this
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$categoryFactory = $objectManager->get('\Magento\Catalog\Model\CategoryFactory');
$categoryHelper = $objectManager->get('\Magento\Catalog\Helper\Category');
$categoryRepository = $objectManager->get('\Magento\Catalog\Model\CategoryRepository');
$priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data');
$productmodel = $objectManager->create('Magento\Catalog\Block\Product\ListProduct');
?>
<div class="worldcup-deals">
<div class="deals-baaner">
<img src='<?php echo $this->getViewFileUrl('images/worldcup/2.png'); ?>' alt="deal-banner">
</div>
<div class="deals-products">
<div class="category-product-listing-world">
<?php
$bestsamrtphoneid = 6685;
$category = $categoryFactory->create()->load($bestsamrtphoneid);
$samrtphonecategoryProducts = $category->getProductCollection()
->addAttributeToSelect('*');
$samrtphonecategoryProducts->getSelect()->order('RAND()');
$samrtphonecategoryProducts->getSelect()->limit(8);
//->setPageSize(8) // only get 10 products
//->setCurPage(1);
?>
<?php foreach ($samrtphonecategoryProducts as $product) { ?>
<div class="product-listing-world-item">
<?php
$imagehelper = $objectManager->create('Magento\Catalog\Helper\Image');
$image = $imagehelper->init($product,'category_page_list')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(300, 300)->getUrl();
?>
<div class="inner-world-wrap">
<a href="<?php echo $product->getProductUrl(); ?>">
<img src="<?php echo $image; ?>">
</a>
<h3 class="product-name">
<a href="<?php echo $product->getProductUrl(); ?>">
<?php echo $product->getName() ?>
</a>
</h3>
<?php echo $productmodel->getProductPrice($product);?>
<div class="shop-new">
<a href="<?php echo $product->getProductUrl(); ?>">
<?php echo __('Shop now >'); ?>
</a>
<img src="<?php echo $this->getViewFileUrl('images/demo/demo.png'); ?>">
</div>
</div>
</div>
<?php } ?>
</div>
<a class="view" href="https://avechi.com/wakilisha-world-cup/cool-phones.html" target="_blank">view more >></a>
</div>
</div>

Drop Down Menu in Magento

I have this code in template to make a static home button. On the home button on hover over I would like to have a blog button underneath.
<?php $_menu = $this->getHtml('level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
<div class="container_24">
<div class="grid_24">
<div id="menu-icon">Categories</div>
<ul id="nav" class="sf-menu">
<li class="level0 level-top<?php if (Mage::helper('core/url')->getCurrentUrl() === Mage::helper('core/url')->getHomeUrl()) echo ' active'; ?>">
<a class="level-top" href="<?php echo $this->getUrl('')?>">
<span>Home</span>
</a>
</li>
<?php echo $_menu ?>
</ul>
</div>
<div class="clear"></div>
</div>
</div>
<?php endif ?>

Jooma K2 show user description in comments

I really need help this time - Joomla 2.5 and latest K2.
I'm using the default K2 comment system and I want to show the "Description" field for every commenter on that page.
So far I have this code:
$thisUserdata =& JFactory::getUser($comment->userID);
echo $thisUserdata->profile->description;
But this shows the description for the author of the page only.
If I log in with another account, it'll also show my own Description as long as I'm logged in.
All the coding I'm doing is in /components/com_k2/templates/default/item.php
The whole code for comments looks like this:
<?php if($this->item->numOfComments>0 && $this->item->params->get('itemComments') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2'))): ?>
<!-- Item user comments -->
<ul>
<?php foreach ($this->item->comments as $key=>$comment): ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; echo (!$this->item->created_by_alias && $comment->userID==$this->item->created_by) ? " author-comment" : ""; echo($comment->published) ? '':' unpublishedComment'; ?>">
<div class="avatar">
<?php if($comment->userImage): ?>
<a href="<?php echo JFilterOutput::cleanText($comment->userLink); ?>" target="_blank" rel="nofollow">
<img src="<?php echo $comment->userImage; ?>" alt="<?php echo JFilterOutput::cleanText($comment->userName); ?>" width="<?php echo $this->item->params->get('commenterImgWidth'); ?>" />
</a>
<?php endif; ?>
</div>
<div class="inner">
<div class="author">
<?php if(!empty($comment->userLink)): ?>
<a href="<?php echo $comment->userLink; ?>" title="View <?php echo $comment->userName; ?> profile" target="_blank" rel="nofollow">
<?php echo $comment->userName; ?>
</a>
<?php else: ?>
<a rel="nofollow"><?php echo $comment->userName; ?></a>
<?php endif; ?>
</div>
<div class="date">
 <?php echo JHTML::_('date', $comment->commentDate, JText::_('K2_DATE_FORMAT_COM_MARIO')); ?>
</div>
<p><?php echo $comment->commentText; ?>
<?php
// USER DESCRIPTION
$thisUserdata =& JFactory::getUser($comment->userID);
echo $thisUserdata->profile->description;
?>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
<div class="itemCommentsPagination">
<?php echo $this->pagination->getPagesLinks(); ?>
<div class="clr"></div>
</div>
<?php endif; ?>
<?php if($this->item->params->get('commentsFormPosition')=='below' && $this->item->params->get('itemComments') && !JRequest::getInt('print') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2' && K2HelperPermissions::canAddComment($this->item->catid)))): ?>
<!-- Item comments form -->
<div class="itemCommentsForm">
<?php echo $this->loadTemplate('comments_form'); ?>
</div>
<?php endif; ?>
With Joomla 2.5 you can use that to get basic user information, but you want to use the following to get the "description" or "about me" content of the commenting user..
$commentUser = JUserHelper::getProfile($comment->userID);
print_r($commentUser);
$about_me = $commentUser->profile['aboutme'];
echo $about_me;
Here is the link as well, this might help if you would like to do other things with the JUserHelper..
http://api.joomla.org/Joomla-Platform/User/JUserHelper.html#getProfile
EDIT: Make sure the plugin "User - Profile" is enabled or this will not work.

Magento displays incorrect products in category view

When I load a productcollection in list.phtml for the first time (or when I turn of caching completely) the products that are returned are the products which reside in the category which was created last (i.e. the category with the highest id). When cache is turned on, on page-refresh the correct products are shown. After the cache is deleted, the same situation occurs (for the correct products to show I need to refresh the page once when the productlisting is shown).
One extra strange thing; If I call
$_product->getCategory()->getName()
the correct categoryname is returned, but when
$_product->getName()
is called, the wrong productname returns... Im at a complete loss here. I have read a similar post elsewhere which stated that when cache is turned on, this problem goes away, but only after the first page-refresh which is highly undesirable.
<?php $_coreHelper = $this->helper('core'); ?>
<?php $_productCollection=$this->getLoadedProductCollection() ?>
<?php echo Mage::getModel('catalog/layer')->getCurrentCategory()->getName(); ?>
<?php echo Mage::getModel('catalog/layer')->getCurrentCategory()->getId(); ?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = 4; ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php echo var_dump($_product->getCategory()->getName()); ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid" style="padding-left:0px;">
<?php endif ?>
<li style="height:230px;" class="hreview-aggregate hproduct item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<h2 class="item fn product-name">
<?php echo substr($this->htmlEscape($_product->getName()), 0, 22).'...' ?>
</h2>
<div>
<div>
<img class="photo fn" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(100); ?>" width="100" height="100" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />
</div>
<div style="clear:both"></div>
</div>
<div>
<div>
<div>
<div>
<div><span style="font-size:13px;font-weight:bold;"><?php echo $_coreHelper->currency($newprice,true,false) ?> <?php echo $this->helper('tax')->__('Ex. BTW') ?></span></div><br />
<div><?php echo $_coreHelper->currency($newtaxprice,true,false) ?> <?php echo $this->helper('tax')->__('Inc. BTW') ?></div>
</div>
</div>
<div style="clear:both;"></div>
<br />
<form action="<?=$this->getAddToCartUrl($_product);?>" method="post" id="product_addtocart_form_<?=$_product->getId();?>" <?if($_product->getOptions()){?> enctype="multipart/form-data"<?}?>>
<?if(!$_product->isGrouped()){?>
<input type="text" name="qty" id="qty" maxlength="12" value="<?echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1);?>" style="width:30px;" /> x
<?}?>
<button type="button" class="button-order" onclick="this.form.submit()"><span><span><?=$this->__('Bestellen');?></span></span></button>
<br /><br />
<span>Zet in verlanglijst</span>
</form>
</div>
</div>
<div style="clear:both"></div>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
<?php endif; ?>
<div class="toolbar-bottom">
<?php echo $this->getToolbarHtml() ?>
</div>
</div>
Re-Index all your products in re-indexing page.
Clear your cache.
Reload your products page.

Resources