Prestashop 1.7 get admin orders link in module - php

I am building a module and I am trying to get the link directly or an order in the admin e.g. load up the order details page like adminXXXXXX/index.php/sell/orders/ORDERNUMBER.
I can get get a link to generate but it always sends me to the orders overview page (the list of orders) not directly into an order.
At the moment I am using:
$link = Context::getContext()->link;
$link = $link->getAdminLink('AdminOrders', true, [], ['id_customer' => 3473|intval, 'viewcustomer' => 1]);
$this->context->smarty->assign( "link", $link );
this generates:
/adminXXXXX/index.php/sell/orders/?id_customer=3473&viewcustomer=1&_token=XXXXXXXXXX
which just loads the view all orders page.
Can anyone shed any light how I link directly to the order details page?

worked it out. For anyone else it's:
$link->getAdminLink('AdminOrders', true, [], ['orderId' => ORDERNUMBER, 'vieworder' => 1]);

Related

PHP function returning different data on each call on separate php pages

I am developing a website that has a cart. basically the customer will login and choose what they want and then add it to the cart. this works perfectly. the problem comes when displaying the cart. when i add a product to my cart it adds it successfully (can see it in phpmyadmin), but when view my cart it does not display the product i added. i wait a few minutes it then shows up. i am struggling to find out why it has such a long delay to display.
Here is my php function that i call:
function CartGetAll($cid)
{
$query = "SELECT `cart`.`cart_id`, `cart`.`cart_product`, `cart`.`cart_qty`, `product`.`product_name`, `product`.`product_price`, `product`.`product_image` FROM `product` INNER JOIN `cart` ON `product`.`product_id` = `cart`.`cart_product` WHERE `cart`.`cart_customer` = $cid ORDER BY `product`.`product_name`";
$result = mysqli_query($this->link, $query);
$items = array();
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
$items[] = array('cart_id' => $row['cart_id'], 'cart_product' => $row['cart_product'], 'cart_qty' => $row['cart_qty'], 'product_name' => $row['product_name'], 'product_price' => $row['product_price'], 'product_image' => $row['product_image']);
}
return $items;
}
EDIT 1:
here is my code where i call the method:
require './connection.php';
$cart = $con->CartGetAll($cid);
the $con is the object in the connection class that i use to call all my database functions. $cid is the customer id i pass as a parameter.
EDIT 2:
I forgot to mention that this only happens on the hosted website. When i was developing and testing my website on a local pc with wamp server & netbeans, it never had this issue. only on my online site i get this issue.
Your help would be greatly appreciated.

Moodle: Using the returnto query parameter to redirect back to my local plugins index after course edit

tl;dr; Trying to link the 'save and return' button when editing/deleting a course to my local plugins index.php instead of moodles default redirect for these features, moodle allready has a returnTo query parameter so i was thinking if that could be used somehow.
Hey
I am creating a local plugin that has a administration panel, where you can access CRUD on all courses in the system as seen in the picture below:
The problem now is that whenever I click edit, I get into the course edit page of course, but when I return from there I click "save and return" I would like to get back to my own admin page instead of the course page or category manage page.
The code I have right now looks like this:
//edit
$edit_course_moodle_url = new moodle_url('/course/edit.php', array('id' => $course->id, 'returnto' => 'local/adminpanel/index.php'));
$edit_course_url = $edit_course_moodle_url->get_path() . '?id=' . $edit_course_moodle_url->get_param('id') . '&returnto=' . $edit_course_moodle_url->get_param('returnto');
//delete
$delete_course_moodle_url = new moodle_url('/course/delete.php', array('id' => $course->id, 'returnto' => 'local/adminpanel/index.php'));
$delete_course_url = $delete_course_moodle_url->get_path() . '?id=' . $delete_course_moodle_url->get_param('id') . '&returnto=' . $delete_course_moodle_url->get_param('returnto');
As you can see I use the "returnto" query parameter, normally moodle has a "catmanage" as "returnto" that returns you to the category management page, where moodle has its own CRUD for categories and courses. So my question is, can I create my own alias for a link and use it like moodle uses the catmanage link, but for my admin page instead.
Thanks a lot ! :)
EDIT:
Change code to the following:
if (empty($CFG->loginhttps)) {
$securewwwroot = $CFG->wwwroot;
} else {
$securewwwroot = str_replace('http:','https:',$CFG->wwwroot);
}
$returnurl = new moodle_url($securewwwroot . '/local/adminpanel/index.php');
$edit_course_moodle_url = new moodle_url($securewwwroot . '/course/edit.php', array(
'id' => $course->id,
'sesskey' => sesskey(),
'returnto' => 'url',
'returnurl' => $returnurl->out(false))
);
$edit_course_url = $edit_course_moodle_url->out();
But it looks like moodle took away the button from edit course called "save and return" now it only has "save and display" or "Cancel" , both of which brings me back to the course, sad times :(
According to the code I can see in course/edit.php, you should use the following URL arguments:
returnto: 'url'
returnurl: The url
sesskey: sesskey()
In code that gives us:
$returnurl = new moodle_url('/local/plugin/page.php');
$editurl = new moodle_url('/course/edit.php', array(
'id' => 2,
'sesskey' => sesskey(),
'returnto' => 'url',
'returnurl' => $url->out(false)
));
echo $editurl->out();
The page course/delete.php does not seem to support those arguments. But it's probably easier for your plugin to delete the course by itself, it's as simple as calling delete_course($courseid);.

How to add Rating to sort list in Magento 1.7

Looking for some help adding sort by Rating in Magento. I have added code snippets to toolbar.php which seem to add the sort by Rating but when trying to select it, it gets stuck until I reload the page. Any help would be greatly appreciated. Code can be found below: This is the Toolbar.php file.
// Begin new Code
$this->getCollection()->joinField('rating',
'review/review_aggregate',
'rating_summary',
'entity_pk_value=entity_id',
'{{table}}.store_id=1',
'left');
// End new Code
AND
// Add rating to "Sort by"
$_availableOrder = $this->_availableOrder;
$_availableOrder['rating'] = 'Rating';
return $_availableOrder;
$this->_availableOrder = array(
‘rating_summary’ => Mage::helper(’catalog’)->__(’Rating’),
‘price’ => Mage::helper(’catalog’)->__(’Price’),
‘newest’ => Mage::helper(’catalog’)->__(’Newest’),
‘name’ => Mage::helper(’catalog’)->__(’Name’)
);
Best is to make this in a module but here you go:
First we shall alter the way products are retrieved from the database, to include the overall rating (shown as the number of stars on the product) along with the rest of the product attributes. Copy the file app/code/core/Mage/Catalog/Block/Product/List.php to app/code/local/Mage/Catalog/Block/Product/List.php and open it for editing.
In the new List.php file find the following line (around line 86):
$this->_productCollection = $layer->getProductCollection();
After this add the following:
$this->_productCollection->joinField('rating_summary', 'review_entity_summary', 'rating_summary', 'entity_pk_value=entity_id', array('entity_type'=>1, 'store_id'=> Mage::app()->getStore()->getId()), 'left');
Now we need to add in an option so that the customer can select "Rating" as an attribute to sort by. Copy the file app/code/core/Mage/Catalog/Model/Config.php to app/code/local/Mage/Catalog/Model/Config.php and edit.
In the new Config.php file find the following code (which should start around line 298):
$options = array(
'position' => Mage::helper('catalog')->__('Position')
);
Replace with code with:
$options = array(
'position' => Mage::helper('catalog')->__('Position'),
'rating_summary' => Mage::helper('catalog')->__('Rating')
);
Now when viewing categories on your website you should have an option of "Rating" in addition to the others. Note that the sort order defaults to ascending so the lowest rated products will be displayed first. The sort order can be changed by the customer by clicking the arrow next to the drop-down box. Aside from this caveat the new sort is fairly easy to implement and extends the usefulness of the ratings.
Credits: https://www.fontis.com.au/blog/sort-products-rating

Drupal/Ubercart custom price php code for roles

Im building an e-commerce site for wholesale foods and the pricing for products change depending on the user logged in. Ive looked at member pricing and basically every module i could find to do with altering the price but they are either for drupal 6 or not really what im after. Im using Drupal 7 with ubercart 3.
Ive found this module http://drupal.org/project/uc_custom_price. It adds a field within product creation that allows custom php code to be added to each individual product which is exactly what im after. however im not that good with php which is why ive been hunting modules instead of changing code.
What ive got at the moment is:
if ([roles] == 'test company') {
$item->price = $item->price*0.8;
}
Except the [roles] part is the wrong thing to use there and it just throws errors. Ive tried using things like $users->uid =='1' to try to hook onto a user like that but that didnt work either.
what would be the correct variable to put there?
thanks
try this Drupal 7 global $user object
global $user; // access the global user object
if(in_array("administrator",$user->roles)){ // if its administrator
$item->price = $item->price*0.8;
}elseif(in_array("vip",$user->roles)){ // if its a vip
//..
}elseif(in_array("UserCompanyX",$user->roles)){ // if its a user from company X
//..
}
or
if($user->roles[OFFSET] == "ROLE"){
// price calculation
}
$user->roles is an array of the roles assigned to the user.
hope it helped
Make your own module with UC Price API:
http://www.ubercart.org/docs/developer/11375/price_api
function example_uc_price_handler() {
return array(
'alter' => array(
'title' => t('Reseller price handler'),
'description' => t('Handles price markups by customer roles.'),
'callback' => 'example_price_alterer',
),
);
}
function example_price_alterer(&$price_info, $context, $options = array()){
global $user;
if (in_array("reseller", $user->roles)) { //Apply 30% reseller discount
$price_info["price"] = $context["subject"]["node"]->sell_price - (
$context["subject"]["node"]->sell_price * 0.30) ;
}
return;
}
See also: http://www.ubercart.org/forum/development/14381/price_alteration_hook

Programatically getting the order the user just completed in Ubercart

When the user is sent to the "thank you page" (cart/checkout/complete) I need to get some info about the order to send it to a 3rd party tracking API. Problem is that in this point there is no info about the order, either in session nor in any other place that I know of. As a workaround I tried querying the last order for the currently connected user but this fails when the user is unregistered as Ubercart registers an account on the fly and leaves the user unlogged.
So my question is, is there a way to get the Order object at this point (cart/checkout/complete) from the page-cart.tpl.php template ?
My solution so far:
Grab the $_SESSION['cart_order'] variable at cart/checkout/review , assign it to $_SESSION['faux_order'] and use faux_order in my script at cart/checkout/complete ... which feels as ugly as seeing a giraffe choke to death.
WARNING! DO NOT USE THE ANSWER ABOVE. See my comment for explanation.
Instead of the answer submitted above (which you should NEVER! use) create a custom Ubercart conditional action (CA) and add it to the section "Trigger: Customer completes checkout" in your Ubercart CA workflow, found in https://dev.betternow.org/admin/store/ca/overview
Here I am defining a custom CA
function my_module_ca_action() {
$order_arg = array(
'#entity' => 'uc_order',
'#title' => t('Order'),
);
$actions['my_module_status_update'] = array(
'#title' => t('Some Title'),
'#category' => t('Custom UC AC'),
'#callback' => 'my_module_some_function_name',
'#arguments' => array(
'order' => $order_arg,
),
);
return $actions;
}
Now I can use the order id in my own callback function defined in my module:
function my_module_some_function_name(&$order, $settings) {
echo "This is the order id: " . $order->order_id;
}
I use this approach myself to show a "Thank You" page to users with a link to the product they just purchased.
$_SESSION['cart_order'] is available on the order review page.
So ...
Create a cookie representing the order ID like this:
<?php setcookie('orderID', '$_SESSION['cart_order']'); ?>
Then, on the order confirmation page, you can call the saved cookie like this:
<?php
if (isset($_COOKIE['orderID'])):
$theOrder = $_COOKIE['orderID'));
echo 'The order ID is: ' . $theOrder;
endif;
?>
If the user then goes back and creates a new order, the cookie will be updated whenever they reach the order review page.

Categories