Joomla Virtuemar 2.x - joomla

im traying to show in the products detail page, the list of the other products by the same Manufacturer. I mean, if you are in a Shoes from Adidas, the page shows up the another adidas products. So i have this code:
http://codepad.org/pO8XF0OI (Dont Know how to write code here)
Is actually working but only shows the products by the Category no by the Manufacturer.
What i'm doing wrong?

Try this,
If you are using Vm2.x It will gives you full products under one manufacture.You can add or remove another tables based on your requirement.
$db = &JFactory::getDBO();
$sql = "SELECT N.product_name,M.virtuemart_product_id,MN.mf_name
FROM jos_virtuemart_product_manufacturers AS M
LEFT JOIN jos_virtuemart_products AS P ON M.virtuemart_product_id = P.virtuemart_product_id
LEFT JOIN jos_virtuemart_products_en_gb AS N ON N.virtuemart_product_id = M.virtuemart_product_id
LEFT JOIN jos_virtuemart_manufacturers_en_gb AS MN ON MN.virtuemart_manufacturer_id = M.virtuemart_manufacturer_id
WHERE M.virtuemart_manufacturer_id = '$manufature_id'";
$db->setQuery($sql);
$db->query();
$res = $db->loadAssocList();
echo "<pre/>";
print_r($res);
Hope this may help...

Is done, here is the code:
<?php
$db = &JFactory::getDBO();
$manufacturer = $this->product->virtuemart_manufacturer_id;
$sql = "SELECT N.product_name,I.virtuemart_media_id,M.virtuemart_product_id,MN.mf_name
FROM h3ls8_virtuemart_product_manufacturers AS M
LEFT JOIN h3ls8_virtuemart_products AS P ON M.virtuemart_product_id = P.virtuemart_product_id
LEFT JOIN h3ls8_virtuemart_products_es_es AS N ON N.virtuemart_product_id = M.virtuemart_product_id
LEFT JOIN h3ls8_virtuemart_product_medias AS I ON M.virtuemart_product_id = I.virtuemart_product_id
LEFT JOIN h3ls8_virtuemart_manufacturers_es_es AS MN ON MN.virtuemart_manufacturer_id = M.virtuemart_manufacturer_id
WHERE M.virtuemart_manufacturer_id = '$manufacturer'"; // h3ls8_ is your table Prefix
$db->setQuery($sql);
$db->query();
/* $res = $db->loadAssocList(); //This Load the info as a List */
$prod = $db->loadObjectList(); // This Load the info as a group of objects for loading it.
JRequest::setVar('virtuemart_manufacturer_id',$this->product->virtuemart_manufacturer_id,'GET');
$productModel = VmModel::getModel('product');
if ($this->product->virtuemart_manufacturer_id !=0 ) {
$products = $prod;
$productModel->addImages($products);
$this->assignRef('products', $products);
}
// Show Products
if (!empty($products)) { ?>
<div class="seven columns obras">
<h5> Obras </h5>
<div class="row">
<?php
// Start the Output
foreach ($products as $product) {
// Show Products
?>
<div class="four columns mobile-two end producto">
<div class="imagen">
<!-- <?php //if ($product->product_special == 1) { ?>
<div class="oferta">
<br />
</div>
<?php}?> *** If you wanna add some especial icon to a Special product uncommnent this *** -->
<?php
echo JHTML::_('link', JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id='.$product->virtuemart_product_id.'&virtuemart_category_id='.$product->virtuemart_category_id),$product->images[0]->displayMediaThumb('class="catImage"',false));
?>
</div>
</div> <!-- end of product -->
<?php } ?>
</div>
</div>
<?php } ?>

Related

add blog picture to user profile page in joomla contact page

I want to add the article's pictures before the articles titles in the contact (user profile page ) like so:
Also, I have created an ovveride into a template html/com_contact/contact
and I have added this code but it gives a warning:
"Notice: Undefined property: stdClass::$images"
and no image.
Code:
/ Create a shortcut for params.
$images = json_decode($this->item->images);
$introImage = $images->image_intro;
?>
<?php if ($this->params->get('show_articles')) : ?>
<div class="contact-articles">
<ul class="nav nav-tabs nav-stacked">
<?php foreach ($this->item->articles as $article) : ?>
<li>
<?php echo JHtml::_('link',
JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article-
>catid, $article->language)), htmlspecialchars($article->title, ENT_COMPAT,
'UTF-8')); ?>
<?php echo $introImage; ?>
</li>
How can I get this fixed?
i have fixed it by using this cod ;
// Create a shortcut for params.
$article_id = $article->id; // get article id
//aticle_id = JFactory::getApplication()->input->get('id'); // get article
id
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('images'))
->from($db->quoteName('#__content'))
->where('id = '. $db->Quote($article_id));
$db->setQuery($query);
$result = $db->loadResult();
$intro_image = json_decode($result)->image_intro;
//var_dump($intro_image);
//echo $intro_image;
echo "<img src=\"".$intro_image."\" alt=\"icon\" >";

pass newly added attributes from product detail page to cart page (magento)

I am using Magento Version 1.7.0
I have added shirt size(newly added attributes) drop down box in product detail page.using below code
app\design\frontend\default{mytempalte}\template\catalog\product\view.phtml
<?php $product = $_product->getAttributeText('size_chart'); ?> shirt size
<select name="size_chart">
<option value="Select">Select</option>
<?php for($i = 0;$i < count($product);$i++) { ?>
<option value="<?php echo $product[$i]; ?>"><?php echo $product[$i]; ?></option>
<?php } ?>
</select>
customer can able to select the shirt size .After select the shirt size i need to show shirt size in cart and checkout page.
how to pass the shirt size value from product detail to other page?.
Thanks
Actually, in cart page you may get cart items in quote object.
$cart = Mage::getModel('checkout/cart')->getQuote();
$items = $cart->getAllVisibleItems();
foreach ($items as $item){
$options = $item->getProductOptions();
$superAttributes = $options['info_buyRequest']['super_attribute'];
if (!!$superAttributes){
$attributeObjSize = Mage::getModel('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY,'size_chart');
$attributeObjSizeId = $attributeObjSize->getAttributeId();
foreach ($superAttributes as $code=>$superAttribute){
if ($attributeObjSizeId == $code){
$sizeCode = $superAttribute;
$sizeLabel = $attributeObjSize->getSource()->getOptionText($sizeCode);
}
}
}
}
The $sizeLabel should be want you would like to have. Hope it works.

How to sort products

How to sort by position products.
I am making a slider and a want products to be sorted on slider. I want to use build in sorting like best match, which is on category -> product tab
Here is how I am doing but won't work:
$product_collection = Mage::getModel('catalog/category')->getProductCollection()->setOrder('position','ASC');
$selected = 0;
foreach($product_collection as $product) {
$full_product = Mage::getModel('catalog/product')->load($product->getId());
if($full_product->getTypeId() === 'configurable'){ ?>
<li>
<img>
</li>
<? }
} ?>
You need to load a category in the category model before pulling out its product collection
$product_collection = Mage::getModel('catalog/category')->getProductCollection()->setOrder('position','ASC');
should be replaced by
$product_collection = Mage::getModel('catalog/category')->load($somecategoryid)->getProductCollection()->setOrder('position','ASC');

Sorting categories in Magento according to the position in admin

I would like to know how to sort this list of categories (I followed this tutorial here http://www.devinrolsen.com/magento-custom-category-listing-block/) in magento by position in the admin panel? Currently it is sorted by id
<?php
$cats = Mage::getModel('catalog/category')->load(3)->getChildren();
$catIds = explode(',',$cats);
?>
<ul>
<?php foreach($catIds as $catId): ?>
<li>
<?php
$category = Mage::getModel('catalog/category')->load($catId);
echo '<a href="' . $category->getUrl() . '">';
echo $category->getName() . '</a>';
?>
</li>
<?php endforeach; ?>
</ul>
You're making way too much work for yourself trying to deal with IDs and stuff. The following is already sorted by position as standard.
<?php
$cats = Mage::getModel('catalog/category')->load(3)->getChildrenCategories();
?>
<ul>
<?php foreach($cats as $category): ?>
<li>
<?php echo $category->getName() ?>
</li>
<?php endforeach; ?>
</ul>
If you want to sort the categories by the position created in adminhtml you can then, since catalog/category is an instance of Mage_Catalog_Model_Resource_Category_Collection, make a query where you specify what you want to select, filter and/or sort.
The case here is getting categories from catalog_category_entity select only the name, filtering after the id and sort the query on the position.
<?php
$subcategories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('name')
->addFieldToFilter('parent_id', $categoryId)
->addAttributeToSort('position', ASC);
?>
This is what I did:
$allCategories = Mage::getModel('catalog/category');
$CategoriesTree = $allCategories->getTreeModel()->load();
$categoriesIds =
$CategoriesTree->getCollection()->addAttributeToSort('position', 'asc')->getAllIds();
after to retrieve the categories:
$categoryChildren = array();
if ($categoriesIds) {
foreach ($categoriesIds as $categoryId){
$category = Mage::getModel('catalog/category')->load($categoryId);
$categoryChildren[] = $category;
}
}
and then:
// Sort by position
function comparePosition($a, $b) {
if ($a->position == $b->position)
return 0;
return ($a->position > $b->position) ? 1 : -1;
}
usort($categoryChildren, 'comparePosition');
Inverting the return (1 and -1) would obviously change the order.
It worked just fine for me.
Hope it helps someone.
I strongly suggest to lok here first http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-8-varien-data-collections and also other articles in knowledge base are a must read for any magento dev.
<?php
$cats = Mage::getModel('catalog/category')->addAttributeToSort('yourfield', 'desc')->getCollection()->getChildren();
$catIds = explode(',',$cats);
?>
<?php
$model_category = Mage::getModel('catalog/category')->load($_category->getEntityId());
$sub_categories = $model_category->getCollection();
$sub_categories -> addAttributeToSelect('url_key')
-> addAttributeToSelect('name')
-> addAttributeToFilter('is_active',1)
-> addIdFilter($model_category->getChildren())
-> setOrder('position', 'ASC')
-> load();
?>
<?php foreach($sub_categories->getData() as $each_subcat): ?>
<?php $model_subcat = Mage::getModel('catalog/category')->load($each_subcat['entity_id']); ?>
<?php endforeach; ?>

in one foreach call second foreach! codeigniter

hier is the problem:
in codeigniter in controller I have next code:
$query_not_voted = "SELECT * FROM photos WHERE p_id NOT IN (SELECT distinct p_id FROM p_votes where u_id = ".$this->session->userdata('u_id').") LIMIT ".$this->db->escape_str($segment_url).", ".$config['per_page'];
$q = $this->db->query($query_not_voted);
$data['myphotos'] = $q->result_array();
foreach($data['myphotos'] as $key=>$val)
{
$query_g = "SELECT * FROM users WHERE u_id = (SELECT u_id FROM p_votes WHERE p_id = ".$val['p_id'].")";
$q_2 = $this->db->query($query_g);
$data['allvotess'] = $q_2->result_array();
$query_u = "SELECT * FROM users WHERE u_id = ".$val['u_id']." LIMIT 0, 5";
$q_1 = $this->db->query($query_u);
$data['author'] = $q_1->result_array();
}
So now I have $data['myphotos'] and this is can be outputted in view with next codes:
<?php foreach ($myphotos as $keys => $myphoto){ ?>
<div id="voteblock">
<div id="voteleft">
<img src="<?php echo base_url().$myphoto['p_thumb']; ?>" />
</div>
<?php } ?>
but how can I output $data['allvotess'] in last foreach loop?
I tried to do same, but didn't work out.
Then I tried to push the results inside $data['myphotos'] and no good result!
So What I'm Doing???
Just need someone to help me with foreachloop insite foreachloop!!!
For a week I just can't do, I can even pay for solution right now!!!
I posted also at codeingiter forum, but they say it's easy hier is link
Generally in views I use the more semantic way to write foreach and if statements, and I'll also illustrate a tiered foreach loop...
$array1 = array(1,2,3,4);
$array2 = array(1,2,3,4);
$array3 = array(1,2,3,4);
$second_array[] = $array1;
$second_array[] = $array2;
$second_array[] = $array3;
so now we have $second_array that is a multi-dimensional array...
$data->second_array = $second_array;
$this->load->view('your/view',$data);
in a view file...
<? foreach($second_array as $array): ?> //<--start first foreach loop
<div>do some stuff</div>
<? foreach($array as $array_item): ?> //<--start second foreach loop, inside the first
<div>do some other stuff for every item in $array</div>
<? endforeach; ?> //<--end first foreach
<? endforeach; ?> //<--end second foreach

Resources