Trying to auto apply a coupon code (2 of them actually) when a customer checks out so that I can offer discounts when 4 and 10 items in a specif category or bought, WITHOUT the need for the customer to enter a code. I have tried adding manually the name of my coupon into the "amount" voucher of the /catalog/controller/checkout/cart.php file without success. Is there an easy fix for this?
// Gift Voucher
$data['vouchers'] = array();
if (!empty($this->session->data['vouchers'])) {
foreach ($this->session->data['vouchers'] as $key => $voucher) {
$data['vouchers'][] = array(
'key' => $key,
'description' => $voucher['description'],
'amount' => $this->currency->format($voucher['FOUR'], $this->session->data['currency']),
Related
I am pretty much below beginner level for REGEX/REGEXP and have hit a blocking point in a project I am working in, where I am trying to get the ids for posts that match the search criteria , but I want to restrict the search between 2 sub-strings. I am trying to figure out is how to write the REGEXP in the meta_query:
$args = array(
'post_type'=> 'custom',
'order' => 'DESC',
'posts_per_page' => 10,
'paged' => $page,
'meta_query' => array(
array(
'key' => 'key',
'value' => "title*".$search."*_title",
'compare' => 'REGEXP',
)
),
);
And an example of the field in the DB :
a:302:{s:5:"title";s:10:"Test title";s:6:"_title";s:19:"
Unfortunately none of the combinations I tried based on documentation of SQL REGEXP won't return any values and I am trying to understand how I can pull this off and would appreciate any input.
Also would rather stick to WP_Query for now even though an SQL LIKE "%title%{$search}%_title%" works perfectly , so an alternative solution would be how to set the compare to 'LIKE' and parse it '%' since that is not possible out of the box as the % get escaped I believe.
I'm developing a plugin that lets me add and delete custom table records. Adding and deleting records works fine.
I also want to be able to update the records. This is where I cannot figure out what I'm doing wrong.
Here is my update code if anyone can point me in the right direction (I'm currently focused on the "update selected record" script:
function url_update() {
global $wpdb;
$id = $_GET["id"];
$launchname=$_POST["launchname"];
$url1 = $_POST["url1"];
$url2 = $_POST["url2"];
$urluser = $_POST["urluser"];
$urlpwd = $_POST["urlpwd"];
$wpfirstname = $_POST["wpfirstname"];
$wplastname = $_POST["wplastname"];
$wpemail = $_POST["wpemail"];
$activated = $_POST["activated"];
//update selected record
if(isset($_POST['update'])){
$wpdb->update('launcher',
array(
'id' => $id,
'launchname' => $launchname,
'url1' => $url1,
'url2' => $url2,
'urluser' => $urluser,
'urlpwd' => $urlpwd,
'wpfirstname' => $wpfirstname,
'wplastname' => $wplastname,
'wpemail' => $wpemail,
'activated' => $activated
),
array( 'ID' => $id ), //this line fixed the issue
array('%d','%s','%s','%s','%s','%s','%s','%s','%s','%s'));
}
//delete
else if(isset($_POST['delete'])){
$wpdb->query($wpdb->prepare(
"DELETE FROM wp_tincan_launcher WHERE id = %d",$id
));
}
else{
//selecting row to update
$selected_record = $wpdb->get_results($wpdb->prepare(
"SELECT id,launchname,url1,url2,urluser,urlpwd,wpfirstname,
wplastname,wpemail,activated from launcher where id=%d",$id
));
foreach ( $selected_record as $s ){
$launchname=$s->launchname;
$url1=$s->url1;
$url2=$s->url2;
$urluser=$s->urluser;
$urlpwd=$s->urlpwd;
$wpfirstname=$s->wpfirstname;
$wplastname=$s->wplastname;
$wpemail=$s->wpemail;
$activated=$s->activated;
}
}
I think my code is correct, however, I would really appreciate some feedback that directly addresses my code.
EDIT: Thanks to Pekka for pointing out that I did not identify the error results.
The Error I'm getting from WP is "Notice: Undefined index: each column in the DB."
Best Regards
I resolved it myself by changing my update query to include a new line as follows: array( 'ID' => $id ), before the types line.
None of the links I was led to, not any of the generic advice I was provided was of any help what-so-ever.
I've edited the original code to reflect the complete working code.
I would like to change the tickets history that is showing when you start to create a new ticket based on the customer user that is starting the ticket creation and not on the Customer ID as is the default.
Any guidance? Thank you.
Do you mean the open tickets that show on the right-hand side, in the Customer Information box? You can add history for the customer login rather than the customer ID by enabling
Frontend::CustomerUser::Item###16-OpenTicketsForCustomerUserLogin and disabling Frontend::CustomerUser::Item###15-OpenTickets in SysConfig.
If you'd mean the list of tickets that is shown on the bottom of the screen, the limitation to searching by customerid is unfortunately hard-coded in AgentCustomerSearch.pm so changing that would need code changes.
In
...otrs/Kernel/Modules/AgentCustomerSearch.pm
in this block of code (around line 250),
Add: CustomerUserLoginRaw => $CustomerUserID
Comment out: CustomerIDRaw => #CustomerIDs,
It should look like this:
my #ViewableTickets;
if (#CustomerIDs) {
#ViewableTickets = $TicketObject->TicketSearch(
Result => 'ARRAY',
Limit => 250,
SortBy => [$SortBy],
OrderBy => [$OrderBy],
# CustomerIDRaw => \#CustomerIDs,
CustomerUserLoginRaw => $CustomerUserID,
UserID => $Self->{UserID},
Permission => 'ro',
);
}
I am busy with a site built on Code Igniter that needs integration with Prestashop. In the site, when creating a user account, I save a "shop_id" to the database, which is then retrieved as a session variable when logging in.
I am using the Prestashop API to retrieve the customer successfully (using above "shop_id")
$xml = $this->PSWebService->get(
array('resource' => 'customers', 'id' => (int)$this->user['shop_id'])
);
This successfully returns the user in question, but there is no Cart IDs in this result.
Logging in to the back-end of my shop, I see that there are multiple carts associated with the logged in user.
My question is: How to I retrieve the LATEST cart ID using the API?
$userId = (int) $this->user['shop_id'];
$opt['resource'] = 'carts';
$xml = $this->PSWebService->get($opt);
$carts = $xml->carts->children();
foreach ($carts as $cart) {
$cartIds[] = $cart['id'];
}
for ($i = count($cartIds) - 1; $i > -1; $i--) {
$opt['id'] = $cartIds[$i];
$xml = $this->PSWebService->get($opt);
//since cart ids are descending the first found will be the latest
if ($xml->cart->id_customer == $userId) {
$latestCartId = $cartIds[$i];
break;
}
}
Kind of late, but I struggled a bit with this same problem and found a way to do it just from query, based on yenshirak's tip (since cart ids are descending the first found will be the latest).
I query the API directly using postman like this:
get all carts:
GET webserver/api/carts
get cart for customer:
GET webserver/api/carts?filter[id_customer]=1
get the most recent:
GET webserver/api/carts?filter[id_customer]=1&sort=[id_DESC]&limit=1
for a pretty print, you can also add params:
display=full&output_format=JSON
You can do this in php, I have not tested if the syntax is correct, but based on documentation it looks something like this:
$opt = array(
'resource' => 'carts',
'filter[id_customer]' => '[1]',
'sort' => '[id_DESC]',
'limit' => '1'
);
$xml = $webService->get($opt);
I have 4 columns in a datagrid. The manuals give examples on how to sort on a column derived from the database using the array('OrderByClause' => QQ::OrderBy(QQN::Pubs()->Name)
however, I want to sort on a calculated results $_FORM->getDistance($_ITEM)
What I have so far is this:
$this->dtgPersons->AddColumn(new QDataGridColumn('Row Number', 'CurrentRowIndex + 1) ?>'));
$this->dtgPersons->AddColumn(new QDataGridColumn('Pub Name', 'Name ?>', 'Width=200', //));
array('OrderByClause' => QQ::OrderBy(QQN::Pubs()->Name), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Pubs()->Name, false))));
$this->dtgPersons->AddColumn(new QDataGridColumn('Street', 'Address1 ?>', 'Width=200',
array('OrderByClause' => QQ::OrderBy(QQN::Pubs()->Address1), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Pubs()->Address1,
false))));
$this->dtgPersons->AddColumn(new QDataGridColumn('Distance from
Location', 'getDistance($_ITEM) ?>', 'Width=300'));
This following line works on columns that have a sort on them
$this->dtgPersons->SortColumnIndex = 2;
I am unsure about this. Try asking at the github page - http://github.com/qcubed/framework.