Count data Using codeigniter monthly wise - codeigniter

I am using Codeigniter 3.0 and sql Server
This is my table
customers table:
Amount Date Id
1.00 2014-01-05 00:00:00.000 1
2.00 2014-01-11 00:00:00.000 1
3.00 2014-02-03 00:00:00.000 1
2.00 2014-02-05 00:00:00.000 1
And I want to display my output as
January 3.00
February 5.00
!!!!!!
December 12.00
So, how can i count that Amount and how to put all days to a single month
and i am using codeigniter 3.0, my database is sql server 2012
public function overviews(){
// $merchantid=$this->session->userdata('user_password');
$baji=$this->livemerchant_model->overviews();
$name=$this->session->userdata('name');
$data=array('baji'=>$baji,'name'=>$name);
if($this->session->has_userdata('user_email','name')){
$this->load->view('overviews.php', $data);
}
}
sfnerd this is my controller and is it possible to display data like
select year
january 12.00
february 24.00
Total 36.00
and i want display count of amount for selected year only
<label class="tp-label">Select a year</label>
<select>
<?php
foreach($monthlyTotals as $row)
{
?>
<option value = "<?php echo $row->TheYear?>"><?php echo $row->TheYear;?> </option>
<?php
}
?>
so when i did this loop i am getting years repeatedly based on months like 2014 12 times, and i need the output like select year 2015 and i have load button when i click on that button needs to display 12 months
public function overviews()
{
$this->load->model('livemerchant_model');
$name=$this->session->userdata('name');
$data['monthlyTotals'] = $this->livemerchant_model- >overviews($theyear='');
$this->load->view('overviews', $data);
}
And used this controller
Help me

There are likely a few ways to do this, but here are two way to do it (one using Active Record, one straight SQL). I tested with CI 3.0.6 and SQL Server 2012 and created a similar table.
MODEL FUNCTION (assume model is called Customers)
Straight SQL Version:
function get_monthly_totals($theYear = '', $theMonth = '')
{
$sql = "SELECT DATEPART(Year, Date) [TheYear], DATEPART(Month, Date) [TheMonth], DATENAME(Month, Date) [TheMonthName], SUM(Amount) [TotalAmount]
FROM Customers
WHERE Date IS NOT NULL ";
if ($theYear != '') {
$sql = $sql . " AND DATEPART(Year, Date) = '$theYear'";
}
if ($theMonth != '') {
$sql = $sql . " AND DATEPART(Month, Date) = '$theMonth'";
}
$sql = $sql . " GROUP BY DATEPART(Year, Date), DATEPART(Month, Date), DATENAME(Month, Date) ORDER BY [TheYear], [TheMonth], [TheMonthName]";
$query = $this->db->query($sql);
return $query->result();
}
Active Record version:
function get_monthly_totals($theYear = '', $theMonth = '')
{
$this->db->select("DATEPART(Year, Date) [TheYear], DATEPART(Month, Date) [TheMonth], DATENAME(Month, Date) [TheMonthName], SUM(Amount) [TotalAmount]", false);
$this->db->from('Customers');
if ($theYear != '') {
$this->db->where("DATEPART(Year, Date) = '" . $theYear . "'", NULL, FALSE);
}
if ($theMonth != '') {
$this->db->where("DATEPART(Month, Date) = '" . $theMonth . "'", NULL, FALSE);
}
$this->db->group_by("DATEPART(Year, Date), DATEPART(Month, Date), DATENAME(Month, Date)");
$this->db->order_by("1", "asc");
$this->db->order_by("2", "asc");
$this->db->order_by("3", "asc");
$query = $this->db->get();
return $query->result();
}
CONTROLLER FUNCTION
public function index()
{
$this->load->model('Customers_model');
$data['monthlyTotals'] = $this->Customers_model->get_monthly_totals('2014');
$this->load->view('customers', $data);
}
VIEW OUTPUT (customers.php)
<?php
foreach ($monthlyTotals as $row)
{
echo $row->TheYear . " - " . $row->TheMonthName . ": " . $row->TotalAmount . " <br />" . PHP_EOL;
}
?>

In my case i did following code
public function earning_chart_year($DriverId,$year){
$this->db->select_sum('driverCommision');
$this->db->select('MONTHNAME(displayTime) as createDate');
$this->db->group_by('monthname(displayTime)');
$this->db->where('driverId',$DriverId);
$this->db->where('year(displayTime)',$year);
$result=$this->db->get('BookingMaster')->result_array();
return $result;
}
Output :
Array
(
[0] => Array
(
[totalBooking] => 52
[createDate] => November
)
)

Related

How to write laravel model based in this query with pagination?

for ($i = 0; $i < count($keyskill); $i++) {
if ($i == count($keyskill) - 1) {
$key .= "skills like '%" . $keyskill[$i] . "%' ";
} else {
$key .= "skills like '%" . $keyskill[$i] . "%' or ";
}
}
Hear my Query is
$jobs = DB::select("SELECT * from post where ( $key ) and status=1 order by id desc");
How to write laravel model based in this query with pagination???
Post::where('skills' , 'like' , '%php%')->orWhere('skills' , 'like' , '%javascript%')->where('status' , 1)->orderBy('id' , 'desc')->paginate(10);
try this for dynamic array:
Post::where(function ($query) use ($keyskill) {
for ($i = 0; $i < count($keyskill); $i++) {
if ($i == 0) {
$query->where('skills' , 'like' ,"%$keyskill[$i]%");
} else {
$query->orWhere('skills' , 'like' , "%$keyskill[$i]%");
}
}
})->where('status' , 1)->orderBy('id' , 'desc')->paginate(10);
Below is the Eloquent Query considering Post as your Model Name and Page Size 50.
$posts = \App\Post::where('skills','like','%javascript%')
->orWhere('skills','like','%php%')
->where('status',1)
->orderBy('id','desc')
->paginate(50);
Loading records
$posts->items();
Rendering Pagination on Blade
{!! $posts->render() !!}
Just a recommendation
Your table name should be posts instead or post then Laravel can manage it implicitly but in your case currently you will have to mention the table name in your model with code protected $table = 'post'; in your app/post.php file, read more here.

CodeIgniter: How to join two table columns and use like active record for querying both?

public function search($query, $limit) {
// output
$output = "";
// query
$this->db->select("*");
$this->db->from("products");
$this->db->like("brand", $query);
$this->db->or_like("model", $query);
$this->db->limit($limit);
$query = $this->db->get();
// zero
if ($query->num_rows() == 0) {
$output .= "No results found";
return $output;
}
// result
foreach ($query->result_array() as $row) {
// uri
$uri2 = "{$this->base_url}specifications/{$row['brand']}-{$row['model']}";
$uri2 = str_replace(" ", "-", $uri2);
// price format
$row['price'] = number_format($row['price']);
// image url
$image = "{$this->base_url}assets/images/products/{$row['category']}-{$row['brand']}-{$row['model']}/thumb.png";
$image = str_replace(" ", "-", $image);
$output .= "<ul class=\"product\">\n
<a href=\"{$uri2}\">\n
<li class=\"product-image\"><img src=\"{$image}\" height=\"108\" width=\"57\" alt=\"\"></li>\n
<li class=\"product-brand\">{$row['brand']}</li>\n
<li class=\"product-model\">{$row['model']}</li>\n
<li class=\"product-price\">{$row['price']} <span class=\"green\">pkr</span></li>\n
</a>\n
</ul>\n";
}
// return
return $output;
}
Here I do three types of queries:
1- query that contains only brand (i get results)
2- query that contains only model (i get results)
3- query that contains both (i get no results)
How to accomplish the all above three tasks?
It seems that you are performing some kind of search, so the there result that you want to get are coming from controller or view, you jst do that make there if condition like this then do it as
if ($brand_val != '' )
{ //put your where query here }
if ($model_val != '' )
{ //put your where query here }
if ($brand_val != '' && $model_val != '' )
{ //put your where query here }
hope this will give idea
use this to print the query.
echo $this->db->last_query();
and then try execute that query in your phpmyadmin

Joomla 2.5 Trying to get property of non-object error [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Trying to get property of non-object in
I've come upon a problem when developing a custom component for joomla 2.5.
I'm pulling data out of my database through a MVC structure. Everything is working fine, except when the query doesn't return any results.
I'm getting a Trying to get property of non-object error in my view.
Is there someway I can prevend this and show users a nice message that there aren't any results?
Model part:
$this->_gallery = array();
// Load the data
if (empty( $this->_gallery )) {
$query = ' SELECT #__gallery.id, user_id, merk, type, name, bouwjaar, vermogen, #__gallery_kleur.kleur, transmissie, #__gallery_benzine.soort AS brandstof, cilinders, motorinhoud, gewicht, link FROM #__gallery LEFT JOIN #__gallery_merk ON #__gallery.merk_id = #__gallery_merk.merk_id LEFT JOIN #__gallery_type ON #__gallery.type_id = #__gallery_type.type_id LEFT JOIN #__gallery_autoinfo ON #__gallery.id = #__gallery_autoinfo.galleryid LEFT JOIN #__gallery_kleur ON #__gallery_autoinfo.kleur = #__gallery_kleur.kleurid LEFT JOIN #__gallery_benzine ON #__gallery_autoinfo.brandstof = #__gallery_benzine.benzineid LEFT JOIN #__users ON #__gallery.user_id = #__users.id LEFT JOIN (SELECT * FROM #__gallery_foto ORDER BY #__gallery_foto.hoofdfoto ASC) as #__gallery_foto ON #__gallery.id = #__gallery_foto.galleryid GROUP BY #__gallery.id ';
$this->_db->setQuery( $query );
$this->_db->query();
$num_rows = $this->_db->getNumRows();
$this->_gallery = $this->_db->loadObjectList();
}
if (!$this->_gallery) {
$this->_gallery = new stdClass();
$this->_gallery->id = 0;
}
$this->_total = count($this->_gallery);
if ($num_rows == 0) {
if ($this->getState('limit') > 0) {
$this->_gallery = array_splice($this->_gallery, $this->getState('limitstart'), $this->getState('limit') );
}
}
return $this->_gallery;
View:
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla view library
jimport('joomla.application.component.view');
jimport( 'joomla.html.pagination' );
/**
* HTML View class for the HelloWorld Component
*/
class GalleryViewGallery extends JView
{
// Overwriting JView display method
function display($tpl = null)
{
$gallery = $this->get( 'Gallery' );
$this->assignRef( 'gallery', $gallery );
$this->items = $this->get('Gallery');
$this->pagination = $this->get('Pagination');
// Check for errors.
if (count($errors = $this->get('Errors')))
{
JError::raiseError(500, implode('<br />', $errors));
return false;
}
// Display the view
parent::display($tpl);
}
}
default.php:
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
//$document = &JFactory::getDocument(); $document->addStyleSheet('components'.DS.'com_gallery'.DS.'css'.DS.'gallery.css');
$document = &JFactory::getDocument(); $document->addStyleSheet('components/com_gallery/css/gallery.css');
?>
<p>
In onderstaande overzicht wordt overzicht van galleries getoond, ben op je zoek naar iets specifieks ?. Gebruik dan het zoekscherm aan de linkerkant van deze pagina om een aangepast overzicht te tonen.
</p>
<?php
$count = '1';
foreach($this->gallery as $gallery){
if($count == '0'){
echo 'Geen resultaat';
}else{
?>
<div class="gallery_wrapper">
<?php
if($gallery->merk OR $gallery->type > Null){
echo "<div class=\"gallery_merktype\">";
echo "<a href='gallerie?view=gallerydetail&gallery=" . $gallery->id . "' target='_self'>";
echo "<H1>";
echo $gallery->merk;
echo " ";
echo $gallery->type;
echo "</H1>";
echo "</a>";
echo "</div>";
}
//Weergeven afbeelding, bepaling maximale hoogte en breedte gebeurt in CSS.
if($gallery->link > Null){
echo "<div class=\"gallery_foto\">";
echo "<div class=\"gallery_foto_clip\">";
echo "<a href='gallerie?view=gallerydetail&gallery=" . $gallery->id . "' target='_self'><img src='../galleryimage/thumb/" . $gallery->link . "' width='200px' alt='Afbeelding'/></a>";
echo "</div></div>";
}
?>
<div class="gallery_wrapper_info">
<?php
//Weergeven gallery gegevens.
if($gallery->bouwjaar > Null){
echo "<div class=\"gallery_info_title\">Bouwjaar:</div>";
echo "<div class=\"gallery_info_values\">";
echo $gallery->bouwjaar;
echo "</div>";
}
if($gallery->vermogen > Null){
echo "<div class=\"gallery_info_title\">Vermogen:</div>";
echo "<div class=\"gallery_info_values\">";
echo $gallery->vermogen;
echo "</div>";
}
if($gallery->kleur > Null){
echo "<div class=\"gallery_info_title\">Kleur:</div>";
echo "<div class=\"gallery_info_values\">";
echo $gallery->kleur;
echo "</div>";
}
if($gallery->transmissie > Null){
echo "<div class=\"gallery_info_title\">Transmissie:</div>";
echo "<div class=\"gallery_info_values\">";
echo $gallery->transmissie;
echo "</div>";
}
if($gallery->brandstof > Null){
echo "<div class=\"gallery_info_title\">Brandstof:</div>";
echo "<div class=\"gallery_info_values\">";
echo $gallery->brandstof;
echo "</div>";
}
if($gallery->cilinders > Null){
echo "<div class=\"gallery_info_title\">Cilinders:</div>";
echo "<div class=\"gallery_info_values\">";
echo $gallery->cilinders;
echo "</div>";
}
if($gallery->motorinhoud > Null){
echo "<div class=\"gallery_info_title\">Motorinhoud:</div>";
echo "<div class=\"gallery_info_values\">";
echo $gallery->motorinhoud;
echo "</div>";
}
if($gallery->gewicht > Null){
echo "<div class=\"gallery_info_title\">Gewicht:</div>";
echo "<div class=\"gallery_info_values\">";
echo $gallery->gewicht;
echo "</div>";
}
?>
<div class="gallery_bekijken">
<H2>Bekijk Gallery</H2>
</div>
</div>
</div>
<?php
}
}
?>
<form method="post" name="limiet">
<?php echo $this->pagination->getPagesLinks(); ?>
<center>
<?php echo $this->pagination->getLimitbox(); ?>
</center>
</form>
Great!, I've tried it in the way below and it worked for me:
if(is_object($this->gallery)){
echo "No result";
}else{
//DATA
}
For the record:
A print_r of a filled array:
Array ( [0] => stdClass Object ( [id] => 146 [user_id] => 861 [merk] => Seat [type] => Leon [name] => Danny [bouwjaar] => 2004 [vermogen] => 190 [kleur] => Geel [transmissie] => Handgeschakeld [brandstof] => Diesel [cilinders] => 4 [motorinhoud] => 1900 [gewicht] => 1210 [link] => p1793sjnq51u373r12qdobs1d2b2.jpg ) )
And a empty one:
stdClass Object ( [id] => 0 )
Although there was something I missed earlier, in the model I adjusted the limit variable to '0' instead of the default '5' for testing.
If I put it back to '5' there is a array_splice error I'm getting when the query doesn't return any results. It works perfectly when there is data.
Maybe I'm doin somethin wrong here also ?
The piece of code in my model:
$this->_gallery = array();
// Load the data
if (empty( $this->_gallery )) {
$query = ' SELECT #__gallery.id, user_id, merk, type, name, bouwjaar, vermogen, #__gallery_kleur.kleur, transmissie, #__gallery_benzine.soort AS brandstof, cilinders, motorinhoud, gewicht, link FROM #__gallery LEFT JOIN #__gallery_merk ON #__gallery.merk_id = #__gallery_merk.merk_id LEFT JOIN #__gallery_type ON #__gallery.type_id = #__gallery_type.type_id LEFT JOIN #__gallery_autoinfo ON #__gallery.id = #__gallery_autoinfo.galleryid LEFT JOIN #__gallery_kleur ON #__gallery_autoinfo.kleur = #__gallery_kleur.kleurid LEFT JOIN #__gallery_benzine ON #__gallery_autoinfo.brandstof = #__gallery_benzine.benzineid LEFT JOIN #__users ON #__gallery.user_id = #__users.id LEFT JOIN (SELECT * FROM #__gallery_foto ORDER BY #__gallery_foto.hoofdfoto ASC) as #__gallery_foto ON #__gallery.id = #__gallery_foto.galleryid GROUP BY #__gallery.id ';
$this->_db->setQuery( $query );
$this->_gallery = $this->_db->loadObjectList();
}
if (!$this->_gallery) {
$this->_gallery = new stdClass();
$this->_gallery->id = 0;
}
$this->_total = count($this->_gallery);
if ($this->getState('limit') > 0) {
$this->_gallery = array_splice($this->_gallery, $this->getState('limitstart'), $this->getState('limit') );
}
return $this->_gallery;
}
The error in my view when there are no results and limit set to 5:
Warning: array_splice() expects parameter 1 to be array, object given in
Print_R isn't giving back results, but this is obvious I quess.
check the object has data. you can use a combination of following
isset- Determine if a variable is set and is not NULL
is_null - Finds whether a variable is NULL
empty — Determine whether a variable is empty
is_array — Finds whether a variable is an array
is_object — Finds whether a variable is an object
You can use something like(if the number of rows are 0, set the object to null).
If(!is_null($this->gallery))
{
//show data
}
else
{
//show a msg
}
You can just check if the $this->gallery is an object.
If(is_object($this->gallery))
{
//show data
}
else
{
//show a msg
}
Depending on the result set choose the above wisely. If you can post a print_r I can tell you exactly what you have to use.
UPDATE WITH RESPECT TO THE QUESTION
Warning: array_splice() expects parameter 1 to be array, object given
in
The reason it may not work is because $this->_gallery may not be an array.
stdClass Object ( [id] => 0 ) <-- this is an object not an array. if you are to call array_slice() function, 1st parameter should be an array.
To check if something is an array, you can do:
is_array($this->_gallery); // returns true or false
If it is an array, you can then call array_slice().
Hope this helps. If you have any problems ask here.

Lof K2Scroller Module

I have been using K2 Scroller module developed by Land of Coder. When I use this module to display same category items in the items view the module displays items in the ascending order of the date created and it is the default and only setting available in the module parameter settings in the back-end. However, I want the module to display the items in date wise descending order. So I chose to edit the default code in the helper which I suppose is used to process items based on the back-end settings. And this is the part of the code in the helper file which I think controls the order:
public function __getList( $params ){
global $mainframe;
/*some irrelevant code removed*/
$condition = $this->buildConditionQuery( $params );
$limitDescriptionBy = $params->get('limit_description_by','char');
$ordering = $params->get( 'k2_ordering', 'created_desc');
$limit = $params->get( 'limit_items', 5 );
$ordering = str_replace( '_', ' ', $ordering );
$my = &JFactory::getUser();
$aid = $my->get( 'aid', 0 );
/*some irrelevant code removed*/
$extraURL = $params->get('open_target')!='modalbox'?'':'&tmpl=component';
$excludeIds = $params->get('exclude_ids', '');
$db = &JFactory::getDBO();
$date =& JFactory::getDate();
$now = $date->toMySQL();
$dateFormat = $params->get('date_format', 'DATE_FORMAT_LC3');
$limitDescriptionBy = $params->get('limit_description_by','char');
$isAuthor= $params->get('itemAuthor',0);
require_once ( JPath::clean(JPATH_SITE.'/components/com_k2/helpers/route.php') );
$query = "SELECT a.*, cr.rating_sum/cr.rating_count as rating, c.name as categoryname,
c.id as categoryid, c.alias as categoryalias, c.params as categoryparams, cc.commentcount as commentcount".
" FROM #__k2_items as a".
" LEFT JOIN #__k2_categories c ON c.id = a.catid" .
" LEFT JOIN #__k2_rating as cr ON a.id = cr.itemid".
" LEFT JOIN (select cm.itemid as id, count(cm.id) as commentcount from #__k2_comments as cm
where cm.published=1 group by cm.itemid) as cc on a.id = cc.id";
$query .= " WHERE a.published = 1"
. " AND a.access get('featured_items_show','0') == 0 ){
$query.= " AND a.featured != 1";
} elseif( $params->get('featured_items_show','0') == 2 ) {
$query.= " AND a.featured = 1";
}
if( trim($excludeIds) ){
$query .= " AND a.id NOT IN(".$excludeIds.") ";
}
$query .= $condition . ' ORDER BY ' . $ordering;
$query .= $limit ? ' LIMIT ' . $limit : '';
$db->setQuery($query);
$data = $db->loadObjectlist();
/*some irrelevant code removed*/
return $data;
}
/**
* build condition query base parameter
*
* #param JParameter $params;
* #return string.
*/
public function buildConditionQuery( $params ){
$source = trim($params->get( 'k2_source', 'k2_category' ) );
if( $source == 'k2_category' ){
$catids = $params->get( 'k2_category','');
if( !$catids ){
return '';
}
$catids = !is_array($catids) ? $catids : '"'.implode('","',$catids).'"';
$condition = ' AND a.catid IN( '.$catids.' )';
} else {
$ids = preg_split('/,/',$params->get( 'k2_items_ids',''));
$tmp = array();
foreach( $ids as $id ){
$tmp[] = (int) trim($id);
}
$condition = " AND a.id IN('". implode( "','", $tmp ) ."')";
}
return $condition;
}
Am I editing the right part of the code or am I missing something else.
I am looking forward to your help
Thanks.
Maybe the best way would be to modify the xml file of the module.
I looked at the code of Lof K2Scroller (v 2.2 for Joomla 2.5) and the different ordering options are there.
However if you want to modify the default option, you are in the right file, just replace 'created_desc' for 'created_asc' .

Daily Inventory Update through remote FTP file

It’s been 2 days and I came across many tutorials, videos, extension which explains how to do daily updates on my products but none of them seem to work.
I have a website which has around 3,000 products with attributes and all. My supplier updates the inventory file on daily basis and the updated inventory file is kept on a remote ftp to which I have access to.
What I need is the following:
Daily inventory update which will include, prices, quantity, etc
Remove items which has quantity 0
Add new items as per the updated inventory file
I am sure someone out there has answer to my questions. So please get back to me asap.
Fisrt, by "Remove items which has quantity 0", I think you mean to set products as "out of stock" when the inventory is decreased to 0. This is handled automatically by Magento after you update the inventory.
The built-in import/export function should fulfill your requirements.
Some more tutorials if you don't mind:
Tutorial: Using Magento’s Import/Export Profiles
How to add/edit/remove products using the import/export tool
Here, I will share just inventory update ( but this is not good way ). You should create "tab delimited" file as follows :
SKU QTY
978 34
633 0
Then you can create cron job to run this script.
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
set_time_limit(0);
ini_set('memory_limit','1024M');
include('app/Mage.php');
Mage::App('default');
//get magento db connection for query
$db_query = Mage::getSingleton('core/resource')->getConnection('core_read');
//get magento db connection for update, add, delete sql statements
$db_update = Mage::getSingleton('core/resource')->getConnection('core_write');
//mail receipent
$to = 'youremail#yoursite.com';
if ($handle = opendir('./var/export'))
{
while (false !== ($file = readdir($handle)))
{
$sku_success = '';
if ($file != '.' && $file != '..')
{
$filename = './var/export/'.$file;
$handle_file = fopen($filename,'r');
$counter = 1;
while (($data = fgetcsv($handle_file, 1000, '\t'))!== FALSE) //read tab delimited
{
if($counter!=1)
{
$sku= $data[0];
$qty = $data[1];
$exists = $db_query->query("SELECT COUNT(sku) cnt FROM catalog_product_entity WHERE sku = '$sku' LIMIT 1");
$found = (($exists->fetchObject()->cnt) > 0) ? true : false;
if ($found == true) //product found, update
{
$entity_id = getEntityIdBySku($db_query, $sku);
updateStockQty ($db_update, $entity_id, $qty);
echo 'product $sku inventory updated?';
$sku_success.= $sku;
} else {
//sku not found, notify by email
$body = "SKU#:".$sku." of ".$file." with a qty of ".$qty." was not found in the the inventory";
sendMsg("SKU#:".$sku." not found!",$to,$body);
}
}
$counter++;
}
fclose($handle_file);
$body = "<strong>SKU?S IMPORTED</strong>".$sku_success."<br/>";
sendMsg($file." successfully imported!",$to,$body);
}
}
closedir($handle);
}
function getEntityIdBySku($db_connection, $sku) //get entity id by its sku
{
$entity_row = $db_connection->query("SELECT entity_id FROM catalog_product_entity p_e WHERE p_e.sku = '$sku'")->fetchObject();
$entity_id = $entity_row->entity_id;
return $entity_id;
}
function updateStockQty($db_connection, $entity_id, $qty) //updates the stock quantity
{
$db_connection->query("UPDATE cataloginventory_stock_item s_i, cataloginventory_stock_status s_s
SET s_i.qty = '$qty', s_i.is_in_stock = IF('$qty'>0, 1,0),
s_s.qty = '$qty', s_s.stock_status = IF('$qty'>0, 1,0)
WHERE s_i.product_id = '$entity_id' AND s_i.product_id = s_s.product_id ");
}
function sendMsg($subject, $to, $body)//sends email
{
$headers = 'MIME-Version: 1.0' . '\n';
$headers .= 'Content-type: text/html; charset=iso-8859-1'. '\n';
$headers .= 'To: '.$to. '\n';
$headers .= 'From: webmaster#yoursite.com'. '\n';
if (mail($to, $subject, $body,$headers))
{
echo('Message sent!');
} else {
echo('Message failed.');
}
}
?>
The script by courtesy of the Deepcodeonline

Resources