Auto redirect to another page In Joomla - joomla

I am making payment through paypal. After payment completion it redirect to my website(complete.php) page. I have code in complete.php that will update the credit in database. when i refresh the same page then it automatically update credits in database. I want to update credit only when payment is done. The code i am using in complete.php is:
$db = JFactory::getDBO();
$result = null;
$user = JFactory::getUser();
if ($user->guest) {
return false;
}
$query = 'SELECT credit' .
' FROM #__vodes_credits' .
' WHERE userid = ' . (int) $user->id
;
$db->setQuery($query);
$result = $db->loadResult();
$result_final=$result+20;
$query = 'update #__vodes_credits SET credit='.$result_final.
' WHERE userid = ' . (int) $user->id
;
//echo $query;
//echo $query;
$db->setQuery($query);
$result = $db->loadResult();
if ($db->getErrorNum()) {
JError::raiseWarning( 500, $db->stderr());
}
return $result;
?>
Please help me to sought it out.

I recommend you to create a COOKIE before the payment and then destroy that COOKIE after the first time the user has visited the complete.php, that will work.
Regards.

In case you want to redirect, I am not sure where are you writing your code but try the below code
$app=JFactory::getApplication();
$app->setRedirect('url','msg');

Related

Laravel session

I have done projects laravel shopping cart when clicking on the product detail page will open and click the add to cart sends the id to CartController # index. I then access the database and retrieve product information and I put on the session. Then I bought other products but my older products lost in session when I turn the page. Who can help me thanks
Probably you don't add this to existed array in session, but replace it.
Should do it this way:
$products = Session::get('products', array()); // get existed products or empty array
$products[] = $newProduct; // add new product to list
Session::put('products', $products); // put all products to session
this is my code for cart
public function addItem($ids,Request $request){
$data = Product::find($ids)->toArray();
$name =$data['name'];
$price = $data['price'];
$cart = $request->session()->get('cart');
if($cart==null){
$cart['quantity'][$ids] = 1;
$cart['price'][$ids] = $price;
$cart['name'][$ids] = $name;
$request->session()->put('cart', $cart);
}else{
if(array_key_exists($ids,$cart['quantity'])){
$cart['quantity'][$ids] += 1;
$cart['price'][$ids] = $price * $cart['quantity'][$ids];
$cart['name'][$ids] = $name;
}else{
$cart['quantity'][$ids] = 1;
$cart['price'][$ids] = $price;
$cart['name'][$ids] = $name;
}
$request->session()->put('cart', $cart);
}
}

How to get id of last purchase with multiple addresses?

I have a payment method that needs to be redirected to the page it like paypal, I can add a code block on the page of success but need to know if petido that was just completed was paid with my payment method, so I can redirect.
Note: several people say it is not possible to redirect payments with multishipping.
I just want to get the id of the application of the current purchase being multishipping.
I got this way, but it's not exactly what I want:
$fromDate = date('Y-m-d') . ' 0:0:0';
$toDate = date('Y-m-d H:i:s');
$orderCollection = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('customer_id', array('eq' => array(Mage::getSingleton('customer/session')->getCustomer()->getId())));
$orderCollection = $orderCollection->addAttributeToFilter('created_at', array('from'=>$fromDate, 'to'=>$toDate));
foreach($orderCollection as $order_row){
Solution:
$last_quote_id = Mage::getSingleton('checkout/session')->getLastQuoteId();
$orderCollection = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('customer_id', array('eq' => array(Mage::getSingleton('customer/session')->getCustomer()->getId())));
$orderCollection = $orderCollection->addFilter('quote_id', $last_quote_id);
foreach($orderCollection as $order_row){
if($order_row->getPayment()->getMethodInstance()->getTitle() == 'PagSeguro'){ $pagseguro = 1; }
echo $order_row->getId() . ' - ' . $order_row->getPayment()->getMethodInstance()->getTitle() . '<br />';
}

STRANGE...Not able to get cart items in magento on a custom page (only when the customer is logged in)

Here is the standard code I am using for getting cart items and their attributes which works only when the customer is not logged in. As soon as I log in using my account this script stops working and does not return the items in the cart. Also the cart items count is also 0. But as soon as I close the browser(session ends..) and the script returns the cartitems correctly! Very strange, I have not been able to find out the cause. Please guide, anyone?
require_once('../app/Mage.php') ;
umask(0);
Mage::app();
Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('checkout/session');
$items = $session->getQuote()->getAllVisibleItems();
foreach ($items as $item) {
//$canProceed=0;
echo $productname = $item->getName(); //HERE IS THE COMPLETE CODE:<?php
ini_set('display_errors',true);
require_once('../app/Mage.php') ;
Mage::setIsDeveloperMode(true);
umask(0);
Mage::app();
//Getting buyer's country label
$bcountry1 = $_REQUEST['country']; //gets country code
$_countries = Mage::getResourceModel('directory/country_collection')
->loadData()
->toOptionArray(false);
foreach($_countries as $_country){
if ($_country['value']==$bcountry1){$bcountry = $_country['label'];}
}
//Fetching vendor for each product
$config = Mage::getConfig()->getResourceConnectionConfig("default_setup");
$dbinfo = array("host" => $config->host,
"user" => $config->username,
"pass" => $config->password,
"dbname" => $config->dbname );
$hostname = $dbinfo["host"];
$user2 = $dbinfo["user"];
$password = $dbinfo["pass"];
$dbname = $dbinfo["dbname"];
$dbhandle = mysql_connect($hostname,$user2,$password) or die("Unable to connect");
$selected = mysql_select_db("myart2",$dbhandle);
$Proceed=0;
//Getting all products in the cart
//echo $cart = Mage::getSingleton('checkout/cart')->getItemsCount();
// Secret Sauce - Initializes the Session for the FRONTEND
// Magento uses different sessions for 'frontend' and 'adminhtml'
Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('checkout/session');
$items = $session->getQuote()->getAllVisibleItems();
foreach ($items as $item) {
//$canProceed=0;
$productname = $item->getName();
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $item->getSku(), array('manufacturer'));
$manufacturer = $product->getResource()->getAttribute('manufacturer')->getFrontEnd()->getValue($product);
$qry="select * from vendors WHERE company_name='$manufacturer'";
$result = mysql_query($qry) or die("Unable to run select query");
$row = mysql_fetch_array($result) or die("Unable to fetch data");
if( strcasecmp($row['country'],$bcountry)!=0 && $row['ships_abroad']!=1)
{$Proceed=1;$productnames[]=$productname;}
}
if($Proceed==1)
{
echo implode(',',$productnames);
}
else {echo 1; }
?>
I've tested the following four main permutations, and the code works in a stock CE1.7 instance in all cases:
Create guest quote
Convert guest quote to customer quote via login
Instantiate existing customer quote via login
Merge guest quote with customer quote via login
Adjust the server & app environment params as follows to view & rule out any errors (edit - added complete script; note the closing "}"):
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors',true);
require_once('../app/Mage.php') ;
Mage::setIsDeveloperMode(true);
umask(0);
Mage::app();
$session = Mage::getSingleton('checkout/session');
$items = $session->getQuote()->getAllVisibleItems();
foreach ($items as $item) {
//$canProceed=0;
echo $productname = $item->getName();
}

In Joomla2.5, how to differentiate the user login from the front-end or backend

How to find out the user login from the site frontend or from the admin backend.
Is there any way to find out the user login?.
Try like this, I think it may help you.
<?php
$db = JFactory::getDbo();
$user = JFactory::getUser();
$query = $db->getQuery(true);
$query->select('s.time, s.client_id, u.id, u.name, u.username');
$query->from('#__session AS s');
$query->leftJoin('#__users AS u ON s.userid = u.id');
$query->where('s.guest = 0');
$db->setQuery($query);
$users = $db->loadObjectList();
foreach ($users as $user)
{
if($user->client_id) {
echo JText::_('JADMINISTRATOR');
} else {
echo JText::_('JSITE');
}
}
?>

CI pagination, POST method not working

Okay, I am pretty new in CI and I am stuck on pagination. I am performing this pagination on a record set that is result of a query. Now everything seems to be working fine. But there's some problem probably with the link. I am displaying 10 results per page. Now if the results are less than 10 then it's fine. Or If I pull up the entire records in the table it works fine. But in case the result is more than 10 rows, then the first 10 is perfectly displayed, and when I click on the pagination link to get to the next page the next page displays the rest of the results from the query as well as, other records in the table. ??? I am confused.. Any help??
Here's the model code I am using ....
function getTeesLike($field,$param)
{
$this->db->like($field,$param);
$this->db->limit(10, $this->uri->segment(3));
$query=$this->db->get('shirt');
if($query->num_rows()>0){
return $query->result_array();
}
}
function getNumTeesfromQ($field,$param)
{
$this->db->like($field,$param);
$query=$this->db->get('shirt');
return $query->num_rows();
}
And here's the controller code ....
$KW=$this->input->post('searchstr');
$this->load->library('pagination');
$config['base_url']='http://localhost/cit/index.php/tees/show/';
$config['total_rows']=$this->T->getNumTeesfromQ('Title',$KW);
$config['per_page']='10';
$this->pagination->initialize($config);
$data['tees']=$this->T->getTeesLike('Title',$KW);
$data['title']='Displaying Tees data';
$data['header']='Tees List';
$data['links']=$this->pagination->create_links();
$this->load->view('tee_res', $data);
What am I doing wrong here ???? Pls help ...
I guess the problem is with the $KW=$this->input->post('searchstr'); ..
Because if I hard code a value for $KW it works fine. May be I should use POST differently ..but how do I pass the value from the form without POSTING it , its CI so not GET ... ??????
In Controller
<?php
$KW=$this->input->post('searchstr');
$this->load->library('pagination');
$count = $this->model_name->getNumTeesfromQ($KW);//Count
$config['base_url']= base_url().'index.php/tees/show/';
$config['total_rows']= $count;
$config['per_page']='10';
$config['uri_segment'] = 4;
$limit = $config['per_page'];
$this->pagination->initialize($config);
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
$data['links'] = $this->pagination->create_links();
$data['tees']=$this->model_name->getTeesLike($KW,$limit,$page);
$data['title']='Displaying Tees data';
$data['header']='Tees List';
$this->load->view('tee_res', $data);
In Model
public function getNumTeesfromQ($KW)
{
$query = $this->db->query("SELECT * FROM title WHERE table_field='$KW'");
$result = $query->result_array();
$count = count($result);
return $count;
}
public function getTeesLike($KW,$limit,$page)
{
$query = $this->db->query("SELECT * FROM title WHERE table_field='$KW' LIMIT $page, $limit");
$result = $query->result_array();
return $result;
}
in view
echo all data using foreach
then at bottom of page use <?php echo $links; ?>this will show your Pagination

Resources