display total number of clients product - codeigniter

Hello i having a problem with displaying the number of the attached products to the client and not the total number of products in db.
So here is my code
<div class="span2 action-nav-button">
<a href="<?php echo base_url();?>index.php?client/product">
<img src="<?php echo base_url();?>template/images/icons/product.png" />
<span><?php echo get_phrase('manage_product');?></span>
<span class="label label-blue">
**<?php echo $this->db->count_all_results('product');?>**
</span>
</a>
</div>
As you can see it displays 297 products (total) and not 7 as it supposed to. In what do i need to modify this line ( db->count_all_results('product');?>) to display the correct nubmer? Thank you in advance !
-image-> http://postimg.org/image/bb1ce26nv/

Use num_rows():
$productsQuery = 'SELECT * FROM product WHERE clientid = "SOME_CLIENT_ID" ';
$query = $this->db->query($productsQuery);
echo $query->num_rows();
Of course, replace clientid with the actual field in your product table. Or adjust the request to get only the products for the client you want.

Related

Display comment regarding posts

I am developing a blog using codeigniter, every thing works good like posts are being stored comments are being made likes also works the only problem is fetching the comments using codeigniter against each post. What i want to do is that i want to send id to controller of each id when page loads. Here is the screenshot to make it more clear how i am working.
Front end is like this
Now the code section:
1. Code on the blog page where all messages and posts are being shown
<div class="col-lg-11 col-md-10 col-sm-10 col-xs-9 post_message" id="getComments<?php echo $blog -> blog_id; ?>">
<p>
<?php echo $blog -> message; ?>
</p>
<span class="pull-left">
<small> Posted By: <?php echo $blog -> name; ?></small>
</span>
<!-- onclick="get_comments(this.id, '<?php //echo base_url('users/get_comments_total'); ?>')" id="<?php// echo $blog -> blog_id; ?>-->
<a>
<i class='fa fa-comment' aria-hidden='true'></i> Comments (<small> <?php echo $rows; ?> </small>)
</a>
<a onclick="update_like('<?php echo $blog -> blog_id; ?>', '<?php echo base_url('users/update_like'); ?>')">
<i class='fa fa-thumbs-up' aria-hidden='true'></i> Likes (<small><?php echo $blog -> likes; ?></small>)
</a>
<div class="result_id<?php echo $blog -> blog_id; ?>" style="display: block;float: left;width: 100%;"></div>
</div> <!-- End of post message -->
In the above code there is a line written in comments where on-click function is defined i want to pass each id on page load to controller instead of click and all this code is written in foreach loop.
Help me with this thing or tell if there is any better idea to achieve this. Please do see the image attached with this so that you can know easily how i want to display the comments. one hint is like FB comments.
What is $rows?
If the likes are working OK then you can use the same idea for the comments. Probably you have joined the likes table and that is why you have $blog -> likes;. You should join the comments table to the query and then use Comments (<small> <?php echo $blog->comments; ?> </small>).
If this does not work you should provide your query in the model and your database structure.

Magento - Four Products on Homepage - Random Order - Foreach Loop

I'm trying to get 4 random products on the homepage using PHP within a TPL file I've created. I'd like to be able to format the products in a foreach loop as I'm using some formatting in the code seen below...
<div class="three columns">
<div class="product_container no_border">
<div class="product">
<img src="<?php echo $this->getSkinUrl('images/products/place_holder.jpg'); ?>" alt=" ">
</div>
<div class="product_title">
240 Serving Package
</div>
<div class="price_hp">$454.99</div>
<div class="free_shipping">
<div class="fs"></div>
Free shipping for this package
</div>
<div class="shop_btn">
ADD TO CART
</div>
</div>
</div>
I don't know what PHP to use though to grab the 4 products from any category and randomize the order. May I have some guidance please?
Thanks!
use following code in your phtml file for randomize products..
$categoryid = 15;
$category = new Mage_Catalog_Model_Category();
$category->load($categoryid);
$products = $category->getProductCollection();
$products->addAttributeToSelect('*');
$products->getSelect()->order('RAND()');
$products->getSelect()->limit(4);
foreach($products as $prod)
{
echo $prod->getName() ."<br>";
$img=$prod->getSmallImageUrl();
echo "<img src='$img'>" ."<br>";
}

Get numbers of completed sales by product ID in Magento

I have a .phtml file and i want to show all products of a category with the number of Completed sales and if possible the price x the number of sales so i can make a total for each product.
Now i have this code where i can see the product in a category and the product ID but i can't get it to work with the number of sales and the price.
<?php
$categoryid = 19;
$category = new Mage_Catalog_Model_Category();
$category->load($categoryid);
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');
foreach ($collection as $_product) { ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200); ?>" width="200" height="200" alt="" /> <?php echo $_product->getName(); ?><?php echo $_product->getId(); ?>
<?php }?>
If someone could help me a little bit futher that would be great!
Thanks!
Take a look at table sales_flat_invoice_item (or sales_flat_invoice_item)
You could create a custom query e.g
SELECT * from sales_flat_invoice_item
WHERE product_id = YOUR_PRODUCT_ID
# GROUP BY order_id # if you have product with custom option

Display pricing and add to cart button in related products Virtuemart 2.0

I would like to display the related product pricing and have add to cart button along with each of the related products.
Below is the code snippet from the related products page. The $field does not have any pricing available. How can I show the pricing and "add to cart" button? Thanks in advance
<?php
foreach ($this->product->customfieldsRelatedProducts as $field) {
?><div class="product-field product-field-type-<?php echo $field->field_type ?>">
<span class="product-field-display"><?php echo $field->display ?></span>
<span class="product-field-desc"><?php echo jText::_($field->custom_field_desc) ?></span>
</div>
<?php } ?>
I have found solution here and it works for me:
no need to edit core files
It requires copying the "default_relatedproducts.php", "default_showprices.php" and "default_addtocart.php" to your "template/html/com_virtuemart/productdetails" folder. Then replace all of the code in the "default_relatedproducts.php" with the following code:
<?php
// Check to ensure this file is included in Joomla!
defined ( '_JEXEC' ) or die ( 'Restricted access' );
$model = new VirtueMartModelProduct();
$calculator = calculationHelper::getInstance();
$currency = CurrencyDisplay::getInstance();
?>
<div class="product-related-products">
<h4><?php echo JText::_('COM_VIRTUEMART_RELATED_PRODUCTS'); ?></h4>
<div>
<?php
foreach ($this->product->customfieldsRelatedProducts as $field) {
?>
<div class="product-field">
<?php
$product = $model->getProductSingle($field->custom_value,true);
?>
<h2><?php echo JHTML::link ($product->link, $product->product_name); ?></h2>
<a title="<?php echo $product->product_name ?>" rel="vm-additional-images" href="<?php echo $product->link; ?>">
<?php
echo $this->product->images[0]->displayMediaThumb('class="browseProductImage"', false);
?>
</a>
<div class="short_desc"><?php echo $product->product_s_desc; ?></div>
<?php include 'default_showprices.php'; ?>
<?php include 'default_addtocart.php'; ?>
</div>
<?php } ?>
</div>
</div>
Had a same problem. But I had to show only the price.
So the fastest way is to change sql select statement in customfields.php
Path in Joomla 2.5 for Virtuemart 2.0 administrator/components/com_virtuemart/models/customfields.php
line 548 of
public function getProductCustomsFieldRelatedProducts($product)
change only
$query=
with
'SELECT C.`virtuemart_custom_id` , `custom_parent_id` , `admin_only` , `custom_title` , `custom_tip` , C.`custom_value`
AS value, `custom_field_desc` , `field_type` , `is_list` , `is_hidden` , C.`published` , field.`virtuemart_customfield_id` ,
field.`custom_value`, field.`custom_param`, price.`product_price`, field.`ordering`
FROM `#__virtuemart_customs` AS C
LEFT JOIN `#__virtuemart_product_customfields` AS field ON C.`virtuemart_custom_id` = field.`virtuemart_custom_id`
LEFT JOIN `#__virtuemart_product_prices` AS price ON
field.`custom_value` = price.`virtuemart_product_id`
Where field.`virtuemart_product_id` ='.(int)$product->virtuemart_product_id.' and `field_type` = "R"';
After all on line 559 change
$field->custom_price
to
$field->product_price
And finally...
In template view of product description insert the code below to show the prices of related products
<?php echo $field->product_price ?>
The only problem with the below solution is that it doesn't display the correct images for the related products. It's using the main products image and just repeating it.

Magento: Adding current currency code infront of prices

I am wanting to show my prices in Magento with the current code in front of the price:
AUD $5.50
I can't seem to find a setting for this and I'm having trouble trying to find some code or a plugin to do this.
Any suggestions?
You can try free module Currency Manager
There is available currency symbol replace for every currency. Change "$" to "AUD $".
In app/design/frontend/YourInterface/YourTheme/template/catalog/product/price.phtml, find proper place(you should have many try :) )like this snippet code:
<span class="price-excluding-tax">
<span class="label"><?php echo $this->helper('tax')->__('Excl. Tax:') ?></span>
<span class="price" id="price-excluding-tax-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
<?php echo $_coreHelper->currency($_price+$_weeeTaxAmount,true,false) ?>
</span>
</span>
change
<?php echo $_coreHelper->currency($_price+$_weeeTaxAmount,true,false) ?>
to
<?php echo 'AUD '.$_coreHelper->currency($_price+$_weeeTaxAmount,true,false) ?>
This will add 'AUD ' to all of the prices.

Resources