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/>';
}
?>
Related
I'm trying to verify the file number whether it exist in Database or not if it exists it give success message, if not then show invalid number. My Tab has only one col i.e fileNumber. This is the code I have tried to put in the child theme in functions.php. when I enter the file number in the name field this code only show the statement after else statement ($ajax_handler->add_error( $field['id'], 'Invalid number' );). is there any other way to do this?
here is the code
add_action( 'elementor_pro/forms/validation', function ( $record, $ajax_handler ) {
$fields = $record->get_field( ['id' => 'name1',] );
if ( empty( $fields ) ) {
echo "enter the file number";
}
$field = current( $fields );
global $wpdb;
if($wpdb->connect_error){
echo 'Connection Failed: ';
}
$sql = $wpdb->get_results( "select fileNumber from wpbd_FileNumbers where fileNumber like '%$field%'");
/* $sql="select * from $wpdb->wp_FileNumbers where fileNumber like '%$field%'";*/
if($sql == $field){
$ajax_handler->add_response_data( true, $output );
}
else
$ajax_handler->add_error( $field['id'], 'Invalid number' );
}, 10, 2);
I'm trying to select a specific row from the SQL database connected to flutter but I want value of the row ID to be supplied remotely from flutter app
<?php
require_once('database.php');
$query = 'SELECT * FROM books WHERE book_id = (this value will be a variable supplied by what the users selects in the app)';
$stm = $db->prepare($query);
$stm->execute();
$array = array();
while ($resultsFrom = $stm -> fetch()){
array_push(
$array,array(
'book_description' => $resultsFrom['description'],
'price' => $resultsFrom['initial_price'],
)
);
}
echo json_encode($array);
?>
I created my payment module. During module's instalation i'm creating new table ps_mymodule_card with id, customer_id and card_number fields.
In register page I added new text input (card_nubmer) in account register page using hookCreateAccountForm() in module. It displays proper but how to get customer id in function hookCreateAccount($params) inside my payment module? I want to add own post data to database during (or just after) user register .
modules/mypaymentmodule/mypaymentmodule.php
public function hookCreateAccountForm()
{
return '<!--new field in form-->'
. '<div class="form-group">'
. '<label for="card_number">'
. 'Card number:'
. '</label>'
. '<input class="form-control" id="card_number" type="text" name="card_number">'
. '</div>'
. '<!--new field in form-->';
}
public function hookCreateAccount($params)
{
[here put some validation of data]
$cadrNumber = $params['_POST']['card_number'];
$customer = $params['newCustomer'];
$db = Db::getInstance();
$query = 'INSERT INTO `'._DB_PREFIX_.'mymodule_card`
(`customer_id`, `card_number`)
VALUES
("'.intval($customer->id).'", "'. intval($cadrNumber).'")';
$db->Execute($query);
}
function below is calling of course during module instalation!
private function _createMymoduleCardTbl()
{
$db = Db::getInstance();
$query = "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."mymodule_card` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`customer_id` INT NOT NULL ,
`card_number` TEXT NOT NULL
) ENGINE = MYISAM ";
$db->Execute($query);
return TRUE;
}
do not forget about hooks registering in install method!!
$this->registerHook('createAccountForm')
$this->registerHook('createAccount')
The following function gives all the related data except artist_id, when run I have checked all elements in the database and ok.
If I change the artist_id to an actual 'id' it shows in the result of the function as WHERE artist_id = 4 AND........
Confess I do not understand what is causing this.
Result of the function:
SELECT `image_album_id`, `member_id`, `artist_id`, `albumname`, `ext`, `timestamp`
FROM album_images WHERE artist_id = AND member_id = 1 AND
image_album_id = 160
<?php
function get_data_nxtprv($fields, $where) {
$return = FALSE;
// Template
$template = "SELECT %s "
. "FROM album_images "
. "WHERE artist_id = " . $artist_id. "
AND member_id = ".$_SESSION['member_id']." %s";
// Current record
$sql = sprintf($template, $fields, $where);
$query = mysql_query($sql);
$query_result = mysql_fetch_assoc($query);
//print_r($sql);
// If data has been found
if ($query_result)
{
$return = $query_result;
}
return $return;
?>
I am not entirely sure I understand your question. But I noticed that your function uses three input variables:
$artist_id, $fields, $where
But $artist_id is not getting passed as an argument.
You would need to modify the function call:
function get_data_nxtprv($artist_id, $fields, $where)
There is an error in your SQL
SELECT `image_album_id`, `member_id`, `artist_id`, `albumname`, `ext`, `timestamp`
FROM album_images WHERE artist_id = AND member_id = 1 AND
image_album_id = 160
should it not be
SELECT `image_album_id`, `member_id`, `artist_id`, `albumname`, `ext`, `timestamp`
FROM album_images WHERE member_id = 1 AND
image_album_id = 160
if artist_id is one of the fields you're looking for?
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