Jump to content

[Solved] Modify statsproduct module to display customer name


Rhapsody

Recommended Posts

The BO tab for stats calls a module that displays product stats including who has ordered a particular item. The "product details" display includes a table that displays the following fields:

Date Order Customer Attribute Qty Price

 

It appears that the code for this is in the statsproduct.php file in the statsproduct module as pasted below. How would I modify the code to display the customer first name (initial letter only) and the last name, instead of displaying the customer number (e.g. display Sam Jones as S. Jones)?

{
			$sales = $this->getSales($id_product, $cookie->id_lang);
			$this->_html .= '<br class="clear" />
			<h3>'.$this->l('Sales').'</h3>
			<div style="overflow-y: scroll; height: '.min(400, (count($sales)+1)*32).'px;">
			<table class="table" border="0" cellspacing="0" cellspacing="0">
			<thead>
				<tr>
					<th>'.$this->l('Date').'</th>
					<th>'.$this->l('Order').'</th>
					<th>'.$this->l('Customer').'</th>
					'.($hasAttribute ? '<th>'.$this->l('Attribute').'</th>' : '').'
					<th>'.$this->l('Qty').'</th>
					<th>'.$this->l('Price').'</th>
				</tr>
			</thead><tbody>';
			$tokenOrder = Tools::getAdminToken('AdminOrders'.(int)(Tab::getIdFromClassName('AdminOrders')).(int)($cookie->id_employee));
			$tokenCustomer = Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)($cookie->id_employee));
			foreach ($sales as $sale)
				$this->_html .= '
				<tr>
					<td>'.Tools::displayDate($sale['date_add'], (int)($cookie->id_lang), false).'</td>
					<td align="center"><a href="?tab=AdminOrders&id_order='.$sale['id_order'].'&vieworder&token='.$tokenOrder.'">'.(int)($sale['id_order']).'</a></td>
					<td align="center"><a href="?tab=AdminCustomers&id_customer='.$sale['id_customer'].'&viewcustomer&token='.$tokenCustomer.'">'.(int)($sale['id_customer']).'</a></td>
					'.($hasAttribute ? '<td>'.$sale['product_name'].'</td>' : '').'
					<td>'.(int)($sale['product_quantity']).'</td>
					<td>'.Tools::displayprice($sale['total'], $currency).'</td>
				</tr>';

Link to comment
Share on other sites

Try changing:

 

foreach ($sales as $sale)
   $this->_html .= '
   <tr>
       <td>'.Tools::displayDate($sale['date_add'], (int)($cookie->id_lang), false).'</td>
       <td align="center"><a href="?tab=AdminOrders&id_order='.$sale['id_order'].'&vieworder&token='.$tokenOrder.'">'.(int)($sale['id_order']).'</a></td>
       <td align="center"><a href="?tab=AdminCustomers&id_customer='.$sale['id_customer'].'&viewcustomer&token='.$tokenCustomer.'">'.(int)($sale['id_customer']).'</a></td>
       '.($hasAttribute ? '<td>'.$sale['product_name'].'</td>' : '').'
       <td>'.(int)($sale['product_quantity']).'</td>
       <td>'.Tools::displayprice($sale['total'], $currency).'</td>
  </tr>';

 

to:

 

foreach ($sales as $sale)
{
  $customer = new Customer($sale['id_customer']);
  $this->_html .= '
      <tr>
          <td>'.Tools::displayDate($sale['date_add'], (int)($cookie->id_lang), false).'</td>
          <td align="center"><a href="?tab=AdminOrders&id_order='.$sale['id_order'].'&vieworder&token='.$tokenOrder.'">'.(int)($sale['id_order']).'</a></td>
          <td align="center"><a href="?tab=AdminCustomers&id_customer='.$sale['id_customer'].'&viewcustomer&token='.$tokenCustomer.'">'.substr($customer->firstname, 0, 1).'. '.$customer->lastname.'</a></td>
         '.($hasAttribute ? '<td>'.$sale['product_name'].'</td>' : '').'
         <td>'.(int)($sale['product_quantity']).'</td>
         <td>'.Tools::displayprice($sale['total'], $currency).'</td>
    </tr>';
}

Link to comment
Share on other sites

  • 1 year later...

I have created two statsproduct.php files that contain the modification above. One file is for PS version 1.4.9.0 and the other is for 1.5.3.1. The following features have been added:

 

1. The customer name is displayed formatted F. Last (First Initial followed by the last name)

2. The stats for product attributes are displayed in a graph and a table for purchased items that have attributes.

3. A column has been added to display "Sold" quantity in addition to the "Available Stock" quantity. This is useful for shops that don't use stock management but want to track how many items are sold.

 

Download the desired file below and place it in the \modules\statsproduct directory. Rename the file to remove PS version from the name.

statsproduct-1490.php

statsproduct-1531.php

Link to comment
Share on other sites

  • 1 month later...

I'd like to modify statsproduct.php further so it only displays product details if a product has been sold. I'm not proficient with php syntax but understand the logic of what needs to be done. Below is the section of code annotated on where I want to make the change. You'll see a commented section about a loop. What is the proper syntax so that the table is populated if a product has been sold (otherwise skip it and don't populate the table with that product)?

 

 else
 {
  $categories = Category::getCategories((int)$cookie->id_lang, true, false);
  $this->_html .= '
  <label>'.$this->l('Choose a category').'</label>
  <div class="margin-form">
   <form action="" method="post" id="categoriesForm">
 <input type="hidden" name="submitCategory" value="1" />
 <select name="id_category" onchange="this.form.submit();">
  <option value="0">'.$this->l('All').'</option>';
  foreach ($categories as $category)
   $this->_html .= '<option value="'.(int)$category['id_category'].'"'.($cookie->id_category == $category['id_category'] ? ' selected="selected"' : '').'>'.$category['name'].'</option>';
  $this->_html .= '
 </select>
   </form>
  </div>
  <div class="clear space"></div>
  '.$this->l('Click on a product to access its statistics.').'
  <div class="clear space"></div>
  <h2>'.$this->l('Products available').'</h2>
  <div style="overflow-y: scroll; height: 600px;">
  <table class="table" border="0" cellspacing="0" cellspacing="0">
  <thead>
   <tr>
 <th>'.$this->l('Ref.').'</th>
 <th>'.$this->l('Name').'</th>
 <th>'.$this->l('Sold').'</th>
 <th>'.$this->l('Stock').'</th>
   </tr>
  </thead><tbody>'; //Rhapsody added Sold
  foreach ($this->getProducts($cookie->id_lang) AS $product)
// insert loop here to only display products that have sold
//	  if (this->getTotalBought($product['id_product']) != 0)
  if ($product['id_product'])
						    $this->_html .= '<tr><td>'.$product['reference'].'</td><td><a href="'.$currentIndex.'&token='.Tools::safeOutput(Tools::getValue('token')).'&module='.$this->name.'&id_product='.$product['id_product'].'">'.$product['name'].'</a></td><td>'.$this->getTotalBought($product['id_product']).'</td><td>'.$product['quantity'].'</td></tr>'; //Rhapsody added 3rd field for qty sold
// insert loop here to only display products that have sold

  $this->_html .= '</tbody></table><br /></div><br />
   <a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a><br />';
 }

Link to comment
Share on other sites

I figured out the correct syntax. This works so only products that have been sold are displayed.

 

  foreach ($this->getProducts($cookie->id_lang) AS $product)
// Rhapsody inserted loop here to only display products that have sold
 if ($this->getTotalBought($product['id_product']) != 0) // Rhapsody added for loop
						    $this->_html .= '<tr><td>'.$product['reference'].'</td><td><a href="'.$currentIndex.'&token='.Tools::safeOutput(Tools::getValue('token')).'&module='.$this->name.'&id_product='.$product['id_product'].'">'.$product['name'].'</a></td><td>'.$this->getTotalBought($product['id_product']).'</td><td>'.$product['quantity'].'</td></tr>'; //Rhapsody added 3rd field for qty sold
 else
 ; // end of loop here to only display products that have sold
  $this->_html .= '</tbody></table><br /></div><br />

Link to comment
Share on other sites

  • 1 year later...

Thanks A lot for your its work for me but i have some question 

 

 

how can i get sum product same like sold but i want display product order by order_statue "Awaiting bank wire"

 

 

for example 

 

ref name  sold    in stock    awaiting bank wire

001 Abc   10           9                    2

 

that is i want display into modules statsproduct

 

my pleasure if you want to help me 

Thanks..

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...