I get timeout when i try to change orderstatus in prestashop not sure what is missing.
<?php
$sts_id = $_POST['status_id'];
$order_box = $_POST['orderBox'];
$selected_orders = implode(",", $order_box);
$get_orders = 'SELECT id_order FROM `' . _DB_PREFIX_ . 'orders` WHERE id_order in (' . $selected_orders . ') and current_state !=' . $sts_id;
$get_order_id = Db::getInstance()->ExecuteS($get_orders);
if (count($get_order_id) > 0) {
$order_to_convert = array_column($get_order_id, 'id_order');
foreach ($order_to_convert as $odr_id) {
$objOrder = new Order($odr_id);
$history = new OrderHistory();
$history->id_order = (int) $objOrder->id;
$history->changeIdOrderState($sts_id, (int) ($objOrder->id));
}
}
Any thoughts on this ?
Related
I have imported 16 000 products, and now I have 57 000 products.
Can any one help me please to delete all duplicated products as you see in picture.
Product with different id and same reference.
Image backoffice:
Image front:
You can try something like that, you can test it in development environment, you should create a php file in your root project.
require_once('config/config.inc.php');
require_once('init.php');
$query = "select id_product,reference from " . _DB_PREFIX_ . "product where active=1";
$res = Db::getInstance()->ExecuteS($query);
foreach($res as $prod){
$query = "select id_product from " . _DB_PREFIX_ . "product where reference=$prod['reference']";
$res = Db::getInstance()->ExecuteS($query);
$count = count($res);
if($count){
foreach ($res as $key => $p) {
if (--$count <= 0) {
// to not delete the last occurrence for a given reference
break;
}
$id_product = $p['id_product'];
$product = new Product((int)$id_product);
if($product->delete())
echo 'product '.$id_product.' is deleted';
}
}
}
I try to combine a SELECT and an AVG query into one. My query is working but the AVG result is not shown as expected. Error is:
Undefined index
I thought I can combine AVG and SELECT like this?
the result will be a list and should also show an average progress value. If I put this AVG query separately and inside the "fetch" it works but shows only the first result. So it is not a solution for me because I will have much more rows.
I hope someone can help me to rebuild this miracle :)
<?php
$statement = $pdo->prepare("
SELECT
audit.id as audit_id,
audit.uid,
audit.assigned_auditor,
audit.audit_req_comment,
audit.audit_req_date,
audit.audit_date_start,
audit.general_audit_status,
audit.audit_request_date,
audit.audit_type,
audit.audit_date_start,
questionaire.quest_name,
users.nachname,
suppliers.supplier_name,
suppliers.supplier_city,
suppliers.supplier_country,
(SELECT AVG(progress) AS progress FROM answers WHERE relevant = '1' AND audit_id = :audit_id AND rating != required_answer)
FROM audit
JOIN users ON audit.uid = users.id
JOIN suppliers ON audit.supplier_id = suppliers.id
JOIN questionaire ON audit.questionaire_id = questionaire.id
WHERE
audit.cid = :cid
AND audit.general_audit_status = 'Maßnahmenplan'
AND audit.assigned_auditor = :assigned_auditor"
);
$result = $statement->execute(array(':cid' => $cid, ':assigned_auditor' => $user['id'], ':audit_id' => 4));
$count = 1;
while ($row = $statement->fetch()) {
// Datum umwandeln
$original_date = $row['audit_date_start'];
// Creating timestamp from given date
$timestamp = strtotime($original_date);
// Creating new date format from that timestamp
$new_date = date("d.m.Y", $timestamp);
// Audit Typ Namensgebung
if ($row['audit_type'] == "AR") {
$audit_type = "Externes Audit";
}
if ($row['audit_type'] == "RA") {
$audit_type = "Remote Audit";
}
if ($row['audit_type'] == "IA") {
$audit_type = "Internes Audit";
}
if ($row['audit_type'] == "SAA") {
$audit_type = "Self Assessment Audit";
}
//Berechne die durchschnittliche Abarbeitung aller Maßnahmen dieses Audits
//$statement = $pdo->prepare("SELECT AVG(progress) AS progress FROM answers WHERE relevant = '1' AND audit_id = :audit_id AND rating != required_answer");
//$statement->execute(array(':audit_id' => $row['audit_id']));
//$total_progress = $statement->fetch();
echo "<tr>";
echo "<td>" . $row['audit_id'] . "</td>";
echo "<td>" . $new_date . "</td>";
echo "<td>" . $row['supplier_name'] . "</td>";
echo "<td>" . $row['supplier_city'] . " (" . $row['supplier_country'] . ")</td>";
echo "<td>" . $row['quest_name'] . "</td>";
echo "<td>" . $audit_type . "</td>";
echo "<td>" . round($row['progress'], 0) . " %</td>";
echo '<td align="center"><i class="fas fa-edit"></i></td>';
echo "</tr>";
}
?>
As I understand your question, you just need to alias the results of the subquery in the outer query (rather than in the inner query itself):
SELECT
audit.id as audit_id,
audit.uid,
audit.assigned_auditor,
audit.audit_req_comment,
audit.audit_req_date,
audit.audit_date_start,
audit.general_audit_status,
audit.audit_request_date,
audit.audit_type,
audit.audit_date_start,
questionaire.quest_name,
users.nachname,
suppliers.supplier_name,
suppliers.supplier_city,
suppliers.supplier_country,
(
SELECT AVG(progress)
FROM answers
WHERE relevant = 1 AND audit_id = :audit_id AND rating != required_answer
) AS progress --> here
FROM audit
JOIN users ON audit.uid = users.id
JOIN suppliers ON audit.supplier_id = suppliers.id
JOIN questionaire ON audit.questionaire_id = questionaire.id
WHERE
audit.cid = :cid
AND audit.general_audit_status = 'Maßnahmenplan'
AND audit.assigned_auditor = :assigned_auditor"
How do I get Direct access through the database query to product name , product price ,permalink , and image url of product in WordPress WooCommerce ?!
what's the sql query ?
global $wpdb;
$metas = array(
'_thumbnail_id', '_regular_price'
);
foreach ($metas as $i=>$meta_key) {
$meta_fields[] = 'm' . $i . '.meta_value as ' . $meta_key;
$meta_joins[] = ' left join ' . $wpdb->postmeta . ' as m' . $i . ' on m' . $i . '.post_id=' . $wpdb->posts . '.ID and m' . $i . '.meta_key="' . $meta_key . '"';
}
$request = "SELECT ID, post_title, " . join(',', $meta_fields) . " FROM $wpdb->posts ";
$request .= join(' ', $meta_joins);
$request .= " WHERE post_status='publish' AND post_type='product' AND $wpdb->posts.post_title like '%sample%'";
$product_details = $wpdb->get_row($request, OBJECT);
if(!empty($product_details)){
$qry = "SELECT guid FROM $wpdb->posts WHERE ID=" . $product_details->_thumbnail_id;
$uri_obj = $wpdb->get_row($qry, OBJECT);
$product_details->_thumbnail_id = $uri_obj->guid;
}
echo '<pre>';print_r($product_details);exit;
I am migrating my site from osc to prestashop but module importerosc is showing error.
Except category everything else is imported successfully . But when I select category module showing Technical Error.
Category class is extends objectmodel and object model showing unsignedint for date_add field . But ImportererOSC module not fetching date_add value from oscommerce database and nothing change if I change the query.
TECHNICAL ERROR
Details:
Fatal error: Uncaught exception 'PrestaShopException' with message 'Property Category->date_add is not valid' in /home/xxxxxx/public_html/shop/classes/ObjectModel.php:790 Stack trace: #0 /home/xxxxx/public_html/shop/classes/ObjectModel.php(265): ObjectModelCore->validateFields() #1 /home/xxxxxx/public_html/shop/classes/ObjectModel.php(551): ObjectModelCore->getFields() #2 /home/xxxxxx/public_html/shop/classes/Category.php(210): ObjectModelCore->update(false) #3 /home/xxxxxx/public_html/shop/modules/shopimporter/shopimporter.php(971): CategoryCore->update() #4 /home/xxxxxx/public_html/shop/modules/shopimporter/shopimporter.php(533): shopimporter->updateCat() #5 /home/xxxxxx/public_html/shop/modules/shopimporter/ajax.php(148): shopimporter->genericImport('Category', Array, true) #6 {main} thrown in /home/xxxxxx/public_html/shop/classes/ObjectModel.php on line 790
This problem can be caused by the fact that the iso code in the database oscommerce is not correct. You can also try to go this way
Regards
$server = 'localhost'; // DATABASE SERVER
$db_user = ''; // DATABASE SERVER USER NAME
$db_password = ''; // DATABASE SERVER USER PASSWORD
$database = ''; // OLD OSCOMMERCE DATABASE
$databasenew = ''; // NEW PRESTASHOP DATABASE
// CONNECT TO DATABASE SERVER
$con = mysql_connect($server,$db_user,$db_password);
if (!$con)
{
die('COULD NOT CONNECT TO DATABASE SERVER: ' . mysql_error());
}
$db1 = mysql_select_db($database, $con);
if (!$db1) {
die ('COULD NOT SELECT OSCOMMERCE DATABASE: ' . mysql_error());
}
$result = mysql_query("SELECT * FROM customers");
echo '<h4>OSCOMMERCE > PRESTASHOP CUSTOMER IMPORT</h4>';
while($row = mysql_fetch_array($result)){
// PREPARE ADDITIONAL FIELDS
$date = date("Y-m-d H:m:s)");
// random key for user
$key = md5(uniqid(rand(), true));
// customer newsletter y/n
if($row['customers_newsletter'] == "1"){
$newsletter = "1";
} else {
$newsletter = "0";
}
// SELECT NEW DATABASE
$db2 = mysql_select_db($databasenew, $con);
if (!$db1) {
die ('COULD NOT SELECT PRESTASHOP DATABASE: ' . mysql_error());
}
$result1 = mysql_query("INSERT INTO `ps_customer` (
`id_customer` ,
`id_gender` ,
`id_default_group` ,
`firstname` ,
`lastname` ,
`email` ,
`passwd` ,
`last_passwd_gen` ,
`birthday` ,
`newsletter` ,
`ip_registration_newsletter` ,
`newsletter_date_add` ,
`optin` ,
`secure_key` ,
`note` ,
`active` ,
`is_guest` ,
`deleted` ,
`date_add` ,
`date_upd`
)
VALUES (
NULL , '1', '1', '".$row['customers_firstname']."', '".$row['customers_lastname']."', '".$row['customers_email_address']."', '1', '2000-05-27 15:53:08', NULL , '".$newsletter."', NULL , '".$date."' , '0', '".$key."', NULL , '1', '0', '0', '".$date."', '".$date."'
)");
// ADD USER TO GROUP - ( Default 1 )
$userid = mysql_insert_id();
$result2 = mysql_query("INSERT INTO `ps_customer_group` (`id_customer` ,`id_group`)
VALUES ('".$userid."', '1')");
echo "SUCCESS!: " . $row['customers_firstname'] . " " . $row['customers_lastname'].'<br/>';
}
?>
I'm building a plugin, and I want to have a Subtable, so that my users can click on the overview data, and display the data from there.
Following the code that I've been able to glean:
public function getCompanyList($idSite, $period, $date )
{
$dataTable = new Piwik_DataTable();
$query = Piwik_Query("SELECT cl.id, cl.company_name name, sf.id sf_id FROM sitedb.company_lookup cl INNER JOIN sitedb.storefronts sf ON cl.id = sf.company_id");
while ($row = $query->fetch()) {
$piwik_row = new Piwik_DataTable_Row;
$piwik_row->setSubTable( $this->getProductsForCompany($idSite, $period, $date, $row['id']) );
$piwik_row->setColumns( array('id' => $row['id'], 'Company Name' => $row['name']) );
$dataTable->addRow($piwik_row);
}
return $dataTable;
}
public function getProductsForCompany($idSite, $period, $date, $company_id )
{
if (!defined('PIWIK_ENABLE_DISPATCH')) define('PIWIK_ENABLE_DISPATCH', false);
if (!defined('PIWIK_ENABLE_ERROR_HANDLER')) define('PIWIK_ENABLE_ERROR_HANDLER', false);
require_once PIWIK_INCLUDE_PATH . "/index.php";
require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php";
Piwik_FrontController::getInstance()->init();
$request = new Piwik_API_Request('
method=Actions.getActions
&idSite=' . $idSite . '
&date=' . $date . '
&period=' . $period . '
&format=PHP
&filter_column=label
&filter_pattern=product.php
&filter_sort_column=nb_visits
&filter_sort_order=desc
&token_auth=anonymous
');
$result = $request->process();
// contains an array of visits to storefront.php
$result = unserialize($result);
$query = Piwik_Query("SELECT sp.product_id id, sp.name, sp.storefront_id sf_id, cl.company_name FROM sitedb.storefront_products sp INNER JOIN sitedb.storefronts sf ON sp.storefront_id = sf.id INNER JOIN sitedb.company_lookup cl ON sf.company_id = cl.id WHERE cl.id = {$company_id}");
$dataTable = new Piwik_DataTable();
while ($row = $query->fetch()) {
// piwik returns & escaped to & -- make sure that's what you use to search!
$this->array_search_in_level("/product.php?id=" . $row['id'] . "&sf_id=" . $row['sf_id'], $result, 'label', $storefront_array, 1);
if (is_array($storefront_array) && array_key_exists('nb_visits', $storefront_array)) {
$piwik_row = new Piwik_DataTable_Row;
$piwik_row->setColumns( array('id' => $row['id'], 'Product Name' => $row['name'], 'Page Views' => $storefront_array['nb_visits']) );
$dataTable->addRow($piwik_row);
}
}
return $dataTable;
}
However, the subTable never shows up. Am I doing something wrong?
Maybe you need to add the 'expanded=1' parameter to your API request?
http://piwik.org/docs/analytics-api/reference/#toc-optional-api-parameters
If you are looking for example code on how to use the piwik framework to plot custom data in plugins, it looks like they have a bit of doc: Piwik plugins docs