magento get default view - magento

I have a magento multistore website, I need to list all the store and create a link to their home page, for do it I create this template:
<?php $stores = Mage::app()->getWebsite()->getStores();?>
<?php foreach ($stores as $_store): ?>
<div class="store">
<div class="title">
<?php echo $this->htmlEscape($_store->getName()) ?>
</div>
<div class="description">
<p><?php echo Mage::getStoreConfig('design/head/default_description',$_store->getStoreId()); ?></p>
Vai al sito
<a class="link-to-store" href="<?php echo $this->htmlEscape($_store->getHomeUrl())?>">Vai al Negozio</a>
</div>
</div>
<?php endforeach; ?>
the code works until I have 2 store view, intact the code display all 2 view instead only one, there is a way to display only the store and link to correct home page based on current language?

Take a look # Getting a list of magento stores
foreach (Mage::app()->getWebsites() as $website) {
foreach ($website->getGroups() as $group) {
$stores = $group->getStores();
foreach ($stores as $_store) {
<div class="store">
<div class="title">
<?php echo $this->htmlEscape($_store->getName()) ?>
</div>
...
</div>
}
}
}

Related

How can I display images in carousel using Codeigniter

I am using CI_3 and successfully inserted images to database and in directory but I can't get the image to display on carousel. How should I properly get the image to display it on a carousel?
(EDITED)
I have this on my Model:
function carousel(){
$this->db->select('*');
$this->db->where('status = 1');
$query = $this->db->get('image');
return $query->result_array();
}
Controller:
public function index()
{
$data['content'] = $this->Home_model->getRows();
$data['title'] = 'Products List';
// Load the list page view
$this->load->view('template/header');
$this->load->view('template/topBarNav');
$image = new Home_model;
$data['images'] = $image->carousel();
$this->load->view('pages/home', $data);
$this->load->view('template/footer');
}
and display it on view like this:
<div class="carousel-inner">
<?php foreach ($images as $row) : ?>
<div class="carousel-item card">
<div class="parent d-flex justify-content-center">
<img id="carousel_image" src="<?php echo base_url('uploads1/'.$row['upload_path']) ; ?>" class="img-responsive">
<div class="carousel-caption">
<h3><?php echo stripslashes(html_entity_decode($row['description'])); ?></h3>
</div>
</div>
</div>
<?php endforeach; ?>
But it doesn't display any images. I only get the folder path of the image and not the actual image.
Every uploaded image will create a folder according to their id, therefore every image are inside the generated folders inside uploads1 where I set the upload path for the images.
Your carousel is not working because your are set every item active that's the issue in this only first item was active only other are automatically active by your carousel .
You can try with removing active in loop make it first active only using condtions
<div class="carousel-inner">
<?php foreach ($images as $i => $row) : ?>
<div class="carousel-item card">
<div class="parent d-flex justify-content-center">
<img src="<?php echo base_url().'tourism/uploads1/'.$row['upload_path'] ?>" class="img-responsive">
<div class="carousel-caption">
<h3><?php echo stripslashes(html_entity_decode($row['description'])); ?></h3>
</div>
</div>
</div>
<?php endforeach; ?>

Check duplicate data in CodeIgniter result

I have a small forum and want to show the last 10 reply's.
My problem:
I get some duplicate entries from the database because there have some replies in one post. How I can disable all duplicate posts and show only one from all posts. I try to say, if more then 1 replys with the same forum_post_id > show only the last.
My View:
<?php foreach ($forum_reply as $item): ?>
<?php $standing = $item->forum_post_id ?>
<div class="col-lg-12 robie" onClick="location.href='<?= site_url('viewtopic/index/' . $item->forum_post_id) ?>'">
<div class="catcenter55 row">
<div class="col-md-3 deta grew">
<?php echo $this->db->where('forum_post_id', $item->forum_post_id)->get('forum_post')->row()->post_head; ?>
</div>
<div class="col-md-2 deta">
<?php $topcat = $this->db->where('forum_post_id', $item->forum_post_id)->get('forum_post')->row()->forum_cat_id ;?>
<?php echo $this->db->where('forum_cats2_id', $topcat)->get('forum_cats2')->row()->forum_name; ?>
</div>
<div class="col-md-2 deta">
<?php echo $this->db->where('forum_post_id', $item->forum_post_id)->get('forum_post')->row()->views; ?>
</div>
<div class="col-md-2 deta">
<div class="likebg2">+<?php echo $this->db->where('forum_post_id', $item->forum_post_id)->get('forum_post')->row()->likes; ?></div>
</div>
<div class="col-md-3 deta">
<?php foreach ($this->db->order_by('timestamp', 'DESC')->get('forum_reply')->result() as $stan): ?>
<?php if($standing == $stan->forum_post_id): ?>
<?php echo $this->db->where('user_id', $stan->user_id)->get('users')->row()->username; ?> | <?php echo $this->db->order_by('timestamp', 'DESC')->where('forum_reply_id', $stan->forum_reply_id)->get('forum_reply')->row()->timestamp; ?>
<?php break; ?>
<?php endif; ?>
<?php endforeach; ?>
</div>
</div>
</div>
<?php endforeach; ?>
My Controller
public function index() {
$data['forum_reply'] = $this->db->get('forum_reply')->result();
}
My result
Managed to get what I think you are trying to achieve by using a group by i.e.
SELECT * FROM posts GROUP BY forumId;
However this makes things more complicated when ordering the posts, this is a bit hacky but have a look at this:
SELECT *
FROM (
SELECT *
FROM posts
ORDER BY date DESC
LIMIT 18446744073709551615
) AS sub
GROUP BY sub.forumId
ORDER BY id DESC
For reference regarding the sub query look at this previous question and this post
Thank you Jake,
I was change
$data['forum_reply'] = $this->db->get('forum_reply')->result();
to
$data['forum_reply'] = $this->db->group_by('forum_post_id')->order_by('timestamp', 'DESC')->get('forum_reply')->result();
and it´s working.

Add to cart button not adding product in cart

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);

Magento get price featured product

I have a featured product selection in pHtml, which instead of creating an attribute set in Magento, all i am doing is calling on a specific category (this is then added to the front end with XML ont he home page). It seems to work just fine, which is good. However when i try to call in the price I get nothing, i know Im not doing something right, but im just not sure what? here is my code:
<?php
$categoryid = 13;
$category = new Mage_Catalog_Model_Category();
$category->load($categoryid);
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');
?>
<div class="featured-products group">
<h1 class="featured-header">Featured Products</h1>
<div >
<ul class="group multiple" id="featured-set-home">
<?php foreach ($collection as $_product) { ?>
<li>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(138); ?>" width="138" height="138" alt="" />
<?php echo $this->getTierPriceHtml(); ?>
<a href="<?php echo $_product->getProductUrl(); ?>" class="button right" ><span><span>View Item</span></span></a>
</li>
<?php } ?>
</ul>
</div>
</div>
Its not overly complicated. If anyone can help that would be awesome.
<?php echo $this->getTierPriceHtml(); ?>
Will get the price block (it must be added in the XML layout of the custom page that you have created)
I would just go for if you only need to show the price:
$this->helper('core')->currency(Mage::helper('tax')->getPrice($_product, $_product->getFinalPrice()), true, false)); ?>

Show only current category’s products in Product View

I’ve been struggling with this question for a long time and it seems very easy to solve, I just can’t do it by myself.
Take a look at this page: http://adegean.dominiotemporario.com/porcelanas-brancas/artigos-de-mesa/linha-americana/saladeira-pequena-americana.html
This product is associated with 2 different categories, and I would like to show only a list of products of this current category (in this case, ID 188), not from all the cats the product is listed in. It’s just something like filtering this list by “current_cat_Id” or something.
The current code is this:
<div class="box base-mini mini-related-items">
<?php
$test = Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
echo 'Current Main Category of this product this list should show:'.$test;
?>
<?php
if ($_product) {
// get collection of categories this product is associated with
$categories =$_product->getCategoryCollection()
//->setPage(1, 1) //selects only one category
->addFieldToFilter('level','4') //selects only 3rd level categories
//->addFieldToFilter('parent_id','188' ) //select only child categories of no 3
// ->setOrder("level") //combined by setPage, returns the lowest level category
->load();
// if the product is associated with any category
if ($categories->count())
foreach ($categories as $_category)
{
$cur_category = Mage::getModel('catalog/category')->load($_category->getId());
?>
<div class="head"><h4>Todos os produtos da coleção <strong><?=$cur_category->getName()?> (Id: <?=$cur_category->getId()?>)</strong></h4></div>
<div class="content">
<ol>
<? $products = Mage::getResourceModel('catalog/product_collection')
->addCategoryFilter($_category)
->addAttributeToSelect('small_image');
foreach ( $products as $productModel )
{
$_product = Mage::getModel('catalog/product')->load($productModel->getId());
$width=50; $height=50;
$_imageUrl = $this->helper('catalog/image')->init($productModel, 'small_image')->resize($width, $height);
?>
<li<?php if($_product->isComposite() || !$_product->isSaleable()): ?> class="super-products"<?php endif; ?> class="product-box">
<div class="product-images">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(50) ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" width="50" height="50" />
</div>
<div class="product-details">
<?php echo $this->htmlEscape($_product->getName()) ?>
<!-- Price -->
<?php echo $this->getPriceHtml($_product, true) ?>
</div>
</li>
<? }
echo "</ol><div class=\"clear\"></div></div>";
}
}
?>
</div>
Could someone please help me solving that??
Thank you in advance for your help!
Cheers,
jw
Tks to http://www.magentocommerce.com/boards/viewthread/51638/ I finally came to an answer. The following code works great in he view.html page:
<div class="box base-mini mini-related-items">
<div class="head"><h4>Todos os produtos da coleção <strong><?php echo $this->getProduct()->getCategory()->getName() ?> </strong></h4></div>
<div class="content" style="float:left">
<ol>
<?php
$cat_id = Mage::getModel('catalog/layer')->getCurrentCategory()->getId(); // set current category id
$category = Mage::getModel('catalog/category')->load($cat_id);
$products = $category->getProductCollection()->addCategoryFilter($category)->addAttributeToSelect('*');
?>
<?php foreach ( $products as $_product ): ?>
<li<?php if($_product->isComposite() || !$_product->isSaleable()): ?> class="super-products"<?php endif; ?> class="product-box">
<div class="product-images">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(50) ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" width="50" height="50" />
</div>
<div class="product-details">
<?php echo $this->htmlEscape($_product->getName()) ?>
<!-- Price -->
<?php echo $this->getPriceHtml($_product, true) ?>
</div>
</li>
<?php endforeach; ?>
</ol></div><div style="clear:both"><br /></div>
</div></div>

Resources