I want to insert into "invoicesout" not "invoice".
The problem is when I execute the line is added in the table invoice
I want to now where can i find the file who speak with mysql
InvoiceOutController.php
public function create()
{
$invoiceSettings = InvoiceSetting::find(1);
$data = array(
'clients' => Project::all(),
'products' => Product::where('status', 1)->get(),
'currencies' => Currency::all(),
'taxes' => Tax::orderBy('value', 'asc')->get(),
'invoiceCode' => isset($invoiceSettings->code)
$invoiceSettings->code : false,
'invoiceNumber' => isset($invoiceSettings->number) ?
$invoiceSettings->number + 1 : false
);
return View::make('user.invoiceout.create', $data);
}
public function store()
{
if ( Auth::user()->role_id != 1 )
{
return Redirect::to('dashboard')->with('error', trans('translate.permissions_denied'));
}
$rules = array(
'client_id' => 'required',
'number' => 'required',
'start_date' => 'required|date|date_format:"Y-m-d"',
'due_date' => 'required|date|date_format:"Y-m-d"',
'currency_id' => 'required'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->passes())
{
$invoiceSettings = InvoiceSetting::first();
if (isset($invoiceSettings->number))
{
$invoiceNumber = $invoiceSettings->number + 1;
$invoiceSettings->number = $invoiceNumber;
$invoiceSettings->save();
}
$store = new Invoiceout;
$store->number = isset($invoiceSettings->number) ? $invoiceNumber : Input::get('number');
$store->status_id = 2;
$store->discount = Input::get('invoiceDiscount') ? Input::get('invoiceDiscount') : 0;
$store->type = Input::get('invoiceDiscountType') ? Input::get('invoiceDiscountType') : 0;
$store->amount = $store->calculateInvoice(Input::get('qty'), Input::get('price'), Input::get('taxes'), Input::get('discount'), Input::get('discountType'), Input::get('invoiceDiscount'), Input::get('invoiceDiscountType'));
$store->fill(Input::all());
$store->save();
$products = Input::get('products');
foreach ($products as $k => $v)
{
$product = new InvoiceProduct;
$product->invoice_id = $store->id;
$product->product_id = $v;
$product->quantity = Input::get('qty')[$k];
$product->price = Input::get('price')[$k];
$product->tax = Input::get('taxes')[$k];
$product->discount = Input::get('discount')[$k] ? Input::get('discount')[$k] : 0;
$product->discount_type = Input::get('discountType')[$k] ? Input::get('discountType')[$k] : 0;
$product->discount_value = $store->calculateProductPrice(1, Input::get('qty')[$k], Input::get('price')[$k], Input::get('taxes')[$k], Input::get('discount')[$k], Input::get('discountType')[$k]);
$product->amount = $store->calculateProductPrice(2, Input::get('qty')[$k], Input::get('price')[$k], Input::get('taxes')[$k], Input::get('discount')[$k], Input::get('discountType')[$k]);
$product->save();
App::make('ProductController')->manageQuantity($v, Input::get('qty')[$k], Input::get('price')[$k]);
}
$invoiceout = new Invoiceout;
$invoiceout->invoiceStatus();
}
else
{
$invoiceSettings = InvoiceSetting::find(1);
$data = array(
'clients' => Project::all(),
'products' => Product::where('status', 1)->get(),
'currencies' => Currency::all(),
'taxes' => Tax::all(),
'invoiceCode' => isset($invoiceSettings->code) ? $invoiceSettings->code : false,
'invoiceNumber' => isset($invoiceSettings-
>number) ? $invoiceSettings->number + 1 : false,
'errors' => $validator->errors(),
'inputs' => Input::all()
);
return View::make('user.invoiceout.create', $data);
}
return $this->loadDataTable();
}
Related
Hello stackoverflow please help me. I am trying to insert a from post on db, I do have two tables posts and tags tables. When I insert the create the post I want to be able to insert the data from the form in those two different tables.
controller.php;
public function save(Request $request){
if($this->user != '' || $this->userlong != ''){
$request->validate([
'fileNmOriFoto' => 'required',
'fileNmOriFoto.*' => 'mimes:doc,docx,PDF,pdf,jpg,jpeg,png|max:2000',
'fileNmOriKTP' => 'required',
'fileNmOriKTP.*' => 'mimes:doc,docx,PDF,pdf,jpg,jpeg,png|max:2000',
'fileNmOriBukti' => 'required',
'fileNmOriBukti.*' => 'mimes:doc,docx,PDF,pdf,jpg,jpeg,png|max:2000',
'fileNmOriDenah' => 'required',
'fileNmOriDenah' => 'mimes:doc,docx,PDF,pdf,jpg,jpeg,png|max:2000',
'fileNmOriKuasa' => '',
'fileNmOriKuasa' => 'mimes:doc,docx,PDF,pdf,jpg,jpeg,png|max:2000',
'fileNmOriLain' => '',
'fileNmOriLain' => 'mimes:doc,docx,PDF,pdf,jpg,jpeg,png|max:2000',
'krkNoUrut' => 'required',
'krkNama' => 'required',
'krkTglLahir' => 'required',
'krkNoHP' => 'required',
'krkPekerjaan' => 'required',
'krkAlamat' => 'required',
'krkNamaTanah' => 'required',
'krkLuasTanah' => 'required',
'krkNomorPersil' => 'required',
'krkTanahKel' => 'required',
'krkTanahKec' => 'required',
'krkTanahKab' => 'required',
'krkTanahProv' => 'required',
'krkStatusTanah' => 'required',
'krkRencanaFor' => 'required'
]);
$krk = new Krk();
$krk->krkNoUrut = $request->input('krkNoUrut');
$krk->krkNama = $request->input('krkNama');
$krk->krkTglLahir = $request->input('krkTglLahir');
$krk->krkNoHP = $request->input('krkNoHP');
$krk->krkPekerjaan = $request->input('krkPekerjaan');
$krk->krkAlamat = $request->input('krkAlamat');
$krk->krkNamaTanah = $request->input('krkNamaTanah');
$krk->krkLuasTanah = $request->input('krkLuasTanah');
$krk->krkNomorPersil = $request->input('krkNomorPersil');
$krk->krkTanahKel = $request->input('krkTanahKel');
$krk->krkTanahKec = $request->input('krkTanahKec');
$krk->krkTanahKab = $request->input('krkTanahKab');
$krk->krkTanahProv = $request->input('krkTanahProv');
$krk->krkStatusTanah = $request->input('krkStatusTanah');
$krk->krkRencanaFor = $request->input('krkRencanaFor');
$krk->save();
$krkId = Krk::select('krkId')->orderby('krkId', 'desc')->first();
if ($request->hasfile('fileNmOriFoto')) {
$files = [];
foreach ($request->file('fileNmOriFoto') as $file) {
if ($file->isValid()) {
$fileNmOriFoto = round(microtime(true) * 1000).'-'.str_replace(' ','-',$file->getClientOriginalName());
$file->move(public_path('images'), $fileNmOriFoto);
$files[] = [
'fileNmOriFoto' => $fileNmOriFoto,
'fileKd' => $krkId->krkId,
];
}
}
Krkfile::insert($files);
echo'Success';
}if($request->hasfile('fileNmOriKTP')){
$files2 = [];
foreach ($request->file('fileNmOriKTP') as $file2) {
if ($file2->isValid()) {
$fileNmOriKTP = round(microtime(true) * 1000).'-'.str_replace(' ','-',$file2->getClientOriginalName());
$file2->move(public_path('images'), $fileNmOriKTP);
$files2[] = [
'fileNmOriKTP' => $fileNmOriKTP,
'fileKd' => $krkId->krkId,
];
}
}
Krkfile::insert($files2);
echo'Success';
}if($request->hasfile('fileNmOriBukti')){
$files3 = [];
foreach ($request->file('fileNmOriBukti') as $file3) {
if ($file3->isValid()) {
$fileNmOriBukti = round(microtime(true) * 1000).'-'.str_replace(' ','-',$file3->getClientOriginalName());
$file3->move(public_path('images'), $fileNmOriBukti);
$files3[] = [
'fileNmOriBukti' => $fileNmOriBukti,
'fileKd' => $krkId->krkId,
];
}
}
Krkfile::insert($files3);
echo'Success';
}if($request->hasfile('fileNmOriBukti')){
$files4 = [];
foreach ($request->file('fileNmOriBukti') as $file4) {
if ($file4->isValid()) {
$fileNmOriBukti = round(microtime(true) * 1000).'-'.str_replace(' ','-',$file4->getClientOriginalName());
$file4->move(public_path('images'), $fileNmOriBukti);
$files4[] = [
'fileNmOriBukti' => $fileNmOriBukti,
'fileKd' => $krkId->krkId,
];
}
}
Krkfile::insert($files4);
echo'Success';
}if($request->hasfile('fileNmOriDenah')){
$files5 = [];
foreach ($request->file('fileNmOriDenah') as $file5) {
if ($file5->isValid()) {
$fileNmOriDenah = round(microtime(true) * 1000).'-'.str_replace(' ','-',$file5->getClientOriginalName());
$file5->move(public_path('images'), $fileNmOriDenah);
$files5[] = [
'fileNmOriDenah' => $fileNmOriDenah,
'fileKd' => $krkId->krkId,
];
}
}
Krkfile::insert($files5);
echo'Success';
}if($request->hasfile('fileNmOriKuasa')){
$files6 = [];
foreach ($request->file('fileNmOriKuasa') as $file6) {
if ($file6->isValid()) {
$fileNmOriKuasa = round(microtime(true) * 1000).'-'.str_replace(' ','-',$file6->getClientOriginalName());
$file6->move(public_path('images'), $fileNmOriKuasa);
$files6[] = [
'fileNmOriKuasa' => $fileNmOriKuasa,
'fileKd' => $krkId->krkId,
];
}
}
Krkfile::insert($files6);
echo'Success';
}if($request->hasfile('fileNmOriLain')){
$files7 = [];
foreach ($request->file('fileNmOriLain') as $file7) {
if ($file7->isValid()) {
$fileNmOriLain = round(microtime(true) * 1000).'-'.str_replace(' ','-',$file7->getClientOriginalName());
$file7->move(public_path('images'), $fileNmOriLain);
$files7[] = [
'fileNmOriLain' => $fileNmOriLain,
'fileKd' => $krkId->krkId,
];
}
}
Krkfile::insert($files7);
echo'Success';
}else{
echo'Gagal';
}
}else{
$wallidx = rand(1, 7);
$data = array(
'wallidx' => $wallidx,
'message' => 'Session Habis',
);
}
}
i get error "Type error: Too few arguments to function Krk\AdmkrkController::save(), 0 passed and exactly 1 expected"
my error
please help me to fix it.
(edited)
this is my route
Route::post('admsavekrk','Krk\AdmkrkController#save');
I save it using the post method on the form.
How to save two array list in a single row in table?
I have try to foreach every array but I just want to know how to save the array in single row in table just see the picture below. i don't want to have an null value. because this function is like single file that reference in job_orders.
$date = $request->get('date');
$client_name = $request->get('client_name');
$address = $request->get('address');
$service_date = $request->get('service_date');
$service_time = $request->get('service_time');
$contact_person = $request->get('contact_person');
$vehicle = $request->get('vehicles');
$services = $request->input('services');
$supplies = $request->input('supplies');
$accessories = $request->input('accessories');
$miscellaneous = $request->input('miscellaneous');
DB::begintransaction();
try{
$data = [
'vehicle_id' => $request->get('vehicle_id'),
'service_date' => $request->get('service_date'),
'service_time' => $request->get('service_time'),
'discount' => $request->get('discount'),
'total' => $request->get('total'),
'technician' => $request->get('technician'),
'assistant' => $request->get('assistant'),
];
$joborders = $this->joborders->create($data);
if($services !== null){
foreach($services as $service) {
$data = [
'job_order_id' => $joborders->id,
'service_name' => $service['service_name'],
'service_qty' => $service['service_qty'],
'service_cost' => $service['service_cost'],
];
$this->items->create($data);
}
}
if($supplies !== null ){
foreach($supplies as $supply){
$data = [
'job_order_id' => $joborders->id,
'supply_name' => $supply['supply_name'],
'supply_qty' => $supply['supply_qty'],
'supply_cost' => $supply['supply_cost'],
];
$this->items->create($data);
}
}
if($accessories !== null){
foreach($accessories as $accessory){
$data = [
'job_order_id' => $joborders->id,
'accessory_name' => $accessory['accessory_name'],
'accessory_qty' => $accessory['accessory_qty'],
'accessory_cost' => $accessory['accessory_cost'],
];
$this->items->create($data);
}
}
if($miscellaneous !== null)
{
foreach($miscellaneous as $misc){
$data = [
'job_order_id' => $joborders->id,
'misc_name' => $misc['miscellaneous_name'],
'misc_qty' => $misc['miscellaneous_qty'],
'misc_cost' => $misc['miscellaneous_cost'],
];
$this->items->create($data);
}
}
I want to update my product with product image but it is not updated. I am using woocommerce rest API for adding a product.
I am following these step for update product:
Create a view file for display all the product list
Create edit function in the controller for getting all product data
when uploading a new image from edit form it gives an error
Here is my code:
if($request->hasfile('filename'))
{
foreach($request->file('filename') as $image)
{
$name=$image->getClientOriginalName();
$image->move('C:/xampp/htdocs/New-flex/wp-content/uploads/backend-product-image', $name);
$productimg_path_store_db = "http://localhost/New-flex/wp-content/uploads/backend-product-image/";
$productimg_allimg[] = $productimg_path_store_db.$name;
}
}
$AddContentText = $request->get('AddContentText');
if (!empty($AddContentText)) {
/* For List All product qnumber check in array */
$newallproducts_data = $woocommerce->get('products',array('per_page' => 100));
$array = json_decode(json_encode($newallproducts_data), True);
$partssku = array();
$partid = array();
$parturl = array();
foreach ($array as $key ) {
$partssku[] = $key['sku'];
$partid[] = $key['id'];
$parturl[] = $key['permalink'];
}
/* Create associative array product id and sku for compare */
$comb = array_combine($partssku,$partid);
/* Combine content QNUMBER and QTY in array */
$chunks = array_chunk(preg_split('/(;|,)/', $AddContentText), 2);
$result = array_combine(array_column($chunks, 0), array_column($chunks, 1));
/*Product qnumber allready avilabale array*/
$diff = array_intersect_key($result,$comb);
/*NEW PRODUCT array*/
$newproduct = array_diff($result, $diff);
/* Qnumber insert in database */
$parts_name = implode(',', array_keys($result));
/* count insert in database */
$noofpartsuse = implode(',', array_values($result));
/*echo "<pre>";
echo "main data";
print_r($result);
echo "allproduct array";
print_r($comb);
echo "Product qnumber allready avilabale";
print_r($diff);
echo "NEW PRODUCT";
print_r($newproduct);
echo "</pre>";*/
// print_r($newproduct_data);
//print_r($woocommerce->post('products', $data));
}
else{
$parts_name = '';
$noofpartsuse = '';
}
$productactive = $request->get('productactive');
if(!empty($productactive))
{
$productactive = "publish";
}
else{
$productactive = "draft";
}
$ProductListOrder = $request->get('ProductListOrder');
$producttype = $request->get('producttype');
$ProductQNumber = $request->get('ProductQNumber');
$ProductName = $request->get('name');
$ProductWidthMM = $request->get('ProductWidthMM');
$ProductLengthMM = $request->get('ProductLengthMM');
$ProductWidthInch = $request->get('ProductWidthInch');
$ProductLengthInch = $request->get('ProductLengthInch');
$Productinfotext = $request->get('Productinfotext');
$Producttechnocaldesc = $request->get('Producttechnocaldesc');
$metadescription = $request->get('metadescription');
$proimgalt = $request->get('proimg-alt');
$proyoutubelink = $request->get('proyoutubelink');
$proyoutubelinkalt = $request->get('proyoutubelink-alt');
$provimeolink = $request->get('provimeolink');
$provimeolinkalt = $request->get('provimeolink-alt');
$onshapelink = $request->get('onshapelink');
$onshapelinkalt = $request->get('onshapelink-alt');
$data = [
'name' => $ProductName,
'type' => $producttype,
'status' => $productactive,
'regular_price' => '',
'description' => $Productinfotext,
'short_description' => $Producttechnocaldesc,
'sku' => $ProductQNumber,
'categories' =>array (),
'meta_data' => [
[
'key' => 'list_order',
'value' => $ProductListOrder
],
[
'key' => 'ProductWidthMM',
'value' => $ProductWidthMM
],
[
'key' => 'ProductLengthMM',
'value' => $ProductLengthMM
],
[
'key' => 'ProductWidthInch',
'value' => $ProductWidthInch
],
[
'key' => 'ProductLengthInch',
'value' => $ProductLengthInch
],
[
'key' => 'proyoutubelink',
'value' => $proyoutubelink
],
[
'key' => 'proyoutubelink-alt',
'value' => $proyoutubelinkalt
],
[
'key' => 'provimeolink',
'value' => $provimeolink
],
[
'key' => 'provimeolink-alt',
'value' => $provimeolinkalt
],
[
'key' => 'onshapelink',
'value' => $onshapelink
],
[
'key' => 'onshapelink-alt',
'value' => $onshapelinkalt
],
[
'key' => 'UseParts-link',
'value' => $parts_name
],
[
'key' => 'Noofparts-use',
'value' => $noofpartsuse
]
],
'images' => array ()
];
/* image array for store image */
if(!empty($productimg_allimg)){
$images = &$data['images'];
$n = 0;
foreach($productimg_allimg as $id)
{
$images[] = array( //this array must be created dynamic
'src' => $id,
'position' => $n++
);
}
unset($images);
}
if(!empty($_POST['categories'])){
/* Producta category array */
$categories = &$data['categories'];
foreach($_POST['categories'] as $cat)
{
$categories[] = array( //this array must be created dynamic
'id' => $cat
);
}
unset($categories);
}
$data_insert = $woocommerce->post('products', $data);
if($data_insert){
foreach ($newproduct as $key => $value) {
$newproduct_data = [
'name' => $key,
'sku' => $key
];
$woocommerce->post('products', $newproduct_data);
}
}
return redirect('products')->with('success', 'Product has been Added');
Above code written in laravel
Prestashop v1.6.1.6, Homefeatured module v1.8.1
Prestashop on homepage in homefeatured module in standard didn't display attribute color like in category page, in product-list.tpl it is this smarty code: {$product.color_list} When I dump it on home page it give me NULL. I start search in controllers to find it and in FrontController.php I was find this:
if (!in_array($product['id_product'], $products_need_cache) || isset($colors[$product['id_product']])) {
$product['color_list'] = $tpl->fetch(_PS_THEME_DIR_.'product-list-colors.tpl', $this->getColorsListCacheId($product['id_product']));
} else {
$product['color_list'] = '';
}
I think this is what I need but I am not sure how I can put it to homefeatured.php
This is code in homefeatured:
class HomeFeatured extends Module {
protected static $cache_products;
public function __construct()
{
$this->name = 'homefeatured';
$this->tab = 'front_office_features';
$this->version = '1.8.1';
$this->author = 'PrestaShop';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Featured products on the homepage');
$this->description = $this->l('Displays featured products in the central column of your homepage.');
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => '1.6.99.99');
}
public function install()
{
$this->_clearCache('*');
Configuration::updateValue('HOME_FEATURED_NBR', 8);
Configuration::updateValue('HOME_FEATURED_CAT', (int)Context::getContext()->shop->getCategory());
Configuration::updateValue('HOME_FEATURED_RANDOMIZE', false);
if (!parent::install()
|| !$this->registerHook('header')
|| !$this->registerHook('addproduct')
|| !$this->registerHook('updateproduct')
|| !$this->registerHook('deleteproduct')
|| !$this->registerHook('categoryUpdate')
|| !$this->registerHook('displayHomeTab')
|| !$this->registerHook('displayHomeTabContent')
)
return false;
return true;
}
public function uninstall()
{
$this->_clearCache('*');
return parent::uninstall();
}
public function getContent()
{
$output = '';
$errors = array();
if (Tools::isSubmit('submitHomeFeatured'))
{
$nbr = Tools::getValue('HOME_FEATURED_NBR');
if (!Validate::isInt($nbr) || $nbr <= 0)
$errors[] = $this->l('The number of products is invalid. Please enter a positive number.');
$cat = Tools::getValue('HOME_FEATURED_CAT');
if (!Validate::isInt($cat) || $cat <= 0)
$errors[] = $this->l('The category ID is invalid. Please choose an existing category ID.');
$rand = Tools::getValue('HOME_FEATURED_RANDOMIZE');
if (!Validate::isBool($rand))
$errors[] = $this->l('Invalid value for the "randomize" flag.');
if (isset($errors) && count($errors))
$output = $this->displayError(implode('<br />', $errors));
else
{
Configuration::updateValue('HOME_FEATURED_NBR', (int)$nbr);
Configuration::updateValue('HOME_FEATURED_CAT', (int)$cat);
Configuration::updateValue('HOME_FEATURED_RANDOMIZE', (bool)$rand);
Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('homefeatured.tpl'));
$output = $this->displayConfirmation($this->l('Your settings have been updated.'));
}
}
return $output.$this->renderForm();
}
public function hookDisplayHeader($params)
{
$this->hookHeader($params);
}
public function hookHeader($params)
{
if (isset($this->context->controller->php_self) && $this->context->controller->php_self == 'index')
$this->context->controller->addCSS(_THEME_CSS_DIR_.'product_list.css');
$this->context->controller->addCSS(($this->_path).'css/homefeatured.css', 'all');
}
public function _cacheProducts()
{
if (!isset(HomeFeatured::$cache_products))
{
$category = new Category((int)Configuration::get('HOME_FEATURED_CAT'), (int)Context::getContext()->language->id);
$nb = (int)Configuration::get('HOME_FEATURED_NBR');
if (Configuration::get('HOME_FEATURED_RANDOMIZE'))
HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), null, null, false, true, true, ($nb ? $nb : 8));
else
HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position');
}
if (HomeFeatured::$cache_products === false || empty(HomeFeatured::$cache_products))
return false;
}
public function hookDisplayHomeTab($params)
{
if (!$this->isCached('tab.tpl', $this->getCacheId('homefeatured-tab')))
$this->_cacheProducts();
return $this->display(__FILE__, 'tab.tpl', $this->getCacheId('homefeatured-tab'));
}
public function hookDisplayHome($params)
{
if (!$this->isCached('homefeatured.tpl', $this->getCacheId()))
{
$this->_cacheProducts();
$this->smarty->assign(
array(
'products' => HomeFeatured::$cache_products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
)
);
}
return $this->display(__FILE__, 'homefeatured.tpl', $this->getCacheId());
}
public function hookDisplayHomeTabContent($params)
{
return $this->hookDisplayHome($params);
}
public function hookAddProduct($params)
{
$this->_clearCache('*');
}
public function hookUpdateProduct($params)
{
$this->_clearCache('*');
}
public function hookDeleteProduct($params)
{
$this->_clearCache('*');
}
public function hookCategoryUpdate($params)
{
$this->_clearCache('*');
}
public function _clearCache($template, $cache_id = NULL, $compile_id = NULL)
{
parent::_clearCache('homefeatured.tpl');
parent::_clearCache('tab.tpl', 'homefeatured-tab');
}
public function renderForm()
{
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
'icon' => 'icon-cogs'
),
'description' => $this->l('To add products to your homepage, simply add them to the corresponding product category (default: "Home").'),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Number of products to be displayed'),
'name' => 'HOME_FEATURED_NBR',
'class' => 'fixed-width-xs',
'desc' => $this->l('Set the number of products that you would like to display on homepage (default: 8).'),
),
array(
'type' => 'text',
'label' => $this->l('Category from which to pick products to be displayed'),
'name' => 'HOME_FEATURED_CAT',
'class' => 'fixed-width-xs',
'desc' => $this->l('Choose the category ID of the products that you would like to display on homepage (default: 2 for "Home").'),
),
array(
'type' => 'switch',
'label' => $this->l('Randomly display featured products'),
'name' => 'HOME_FEATURED_RANDOMIZE',
'class' => 'fixed-width-xs',
'desc' => $this->l('Enable if you wish the products to be displayed randomly (default: no).'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('No')
)
),
),
),
'submit' => array(
'title' => $this->l('Save'),
)
),
);
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$this->fields_form = array();
$helper->id = (int)Tools::getValue('id_carrier');
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitHomeFeatured';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFieldsValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
return $helper->generateForm(array($fields_form));
}
public function getConfigFieldsValues()
{
return array(
'HOME_FEATURED_NBR' => Tools::getValue('HOME_FEATURED_NBR', (int)Configuration::get('HOME_FEATURED_NBR')),
'HOME_FEATURED_CAT' => Tools::getValue('HOME_FEATURED_CAT', (int)Configuration::get('HOME_FEATURED_CAT')),
'HOME_FEATURED_RANDOMIZE' => Tools::getValue('HOME_FEATURED_RANDOMIZE', (bool)Configuration::get('HOME_FEATURED_RANDOMIZE')),
);
}
}
Only add this in this part
public function _cacheProducts()
{
if (!isset(HomeFeatured::$cache_products))
{
$category = new Category((int)Configuration::get('HOME_FEATURED_CAT'), (int)Context::getContext()->language->id);
$nb = (int)Configuration::get('HOME_FEATURED_NBR');
if (Configuration::get('HOME_FEATURED_RANDOMIZE'))
HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), null, null, false, true, true, ($nb ? $nb : 8));
else
HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position');
}
// PRODUCT COLOR LIST ADDON
$this->context->controller->addColorsToProductList(HomeFeatured::$cache_products);
if (HomeFeatured::$cache_products === false || empty(HomeFeatured::$cache_products))
return false;
}
I currently writing an sms system for the end user. however, When I do the testing on the function i encounter sms credit deduction error.
There are three table in this function which are company, user and transaction.
I did many testing on this function. just cant get the credit deduction correctly.
for example there are 1000 credit in each table.
Initial value
company.sms_bal = 1000
user.user_credit_bal= 1000
transaction.transaction_balance = 1000
testing #1
deduct 1 credit on each table. it deducts correctly.
company.sms_bal = 999
user.user_credit_bal= 999
transaction.transaction_balance = 999
testing #2
deduct 2 credit on each table. it deducts incorrectly,
company.sms_bal = 997
user.user_credit_bal= 997
transaction.transaction_balance = 998 suppose to be 997.
P/S it does not always deduct incorrectly, just sometimes. Please kindly advice me. However if you are unsure my question just let me know I am willing to assist you.
Below is the function for your reference
function process_send_sms($data){
global $CONF, $Q, $OUT, $DB, $DBSH, $CODE, $LANG;
//
// check credit
//
$check_credit = check_credit($data);
if($check_credit['status'] == '100'){
//
// check credit and update credit and update track
//
// get $company_credit_bal
$DBSH->u_select('company', $company_data, array(
'company_id' => $company_id,
));
$company_credit_bal = $company_data['sms_bal'];
// get $user_credit_bal
$DBSH->u_select('user', $user_data, array(
'user_id' => $user_id,
));
$user_credit_bal = trim($user_data['user_credit_bal']);
$number_bulk_mt = trim($total_credit);
//
// update company
//
$rows = $DBSH->update(array(
'table' => 'company',
'set' => array(array('sms_bal = ?', $company_credit_bal - $number_bulk_mt),),
'where' => array(array('company_id = ?', $company_id),),));
$rows = $DBSH->update(array(
'table' => 'user',
'set' => array(array('user_credit_bal = ?', $user_credit_bal - $number_bulk_mt),),
'where' => array(array('user_id = ?', $user_id),),));
}else{
$return_data['error'] = $check_credit['error'];
}
if($check_credit['status'] == '100'){
//
// insert to the track
//
$arr = debug_backtrace();
$function_name = $arr[0]["function"];
$data = array(
'no_phones' => $total_credit,
'company_id' => $company_id,
'user_id' => $user_id,
'msg_type' => $function_name,
'track_mt_create_time' => $timestr,
'track_mt_update_date' => $timestr,
);
$DBSH->u_insert('bulk_mt_log_track', $data);
$ref_id = $DBSH->u_lastid('bulk_mt_log_track');
if($sendsmscsv == 'Y'){
foreach($phone_tem as $k => $v){
$phone_no = $v['phone'];
$message = $v['message'];
$coding = 1;
if($v['lang'] == '2'){
$coding = 3;
}
$check_credit = $credit_class->check_per_credit($phone_no,$is_intern);
$send_c_code = $check_credit['c_code' ];
$per_credit = $check_credit['per_credit'];
if($phone_no){
do{
$msgid = session_get()."_".$user_id;
$check_valid === false;
$found = $DBSH->u_count('bulk_mt_log_data', array(
'msgid' => $msgid,
));
if(!$found){
$check_valid === true;
}
$found = $DBSH->u_count('bulk_mt_log', array(
'msgid' => $msgid,));
if(!$found){
$check_valid === true;
}
}while($check_valid === false);
//
// Perform merge sms
//
$message = process_message_merge($phone_no,$user_id,$message,$company_id);
if($coding == '3'){
$len = mb_strlen($message, 'UTF-8');
$arr = array();
for( $i=0; $i<$len; $i++){
$arr[] = mb_substr($message,$i,1,'UTF-8');;
}
$message2="";
foreach($arr as $k => $substr){
$message2 .= uniord($substr);
}
$message = $message2;
}
else{
$coding = 0;
}
$data = array(
'bulk_mt_log_id' => null,
'user_id' => $user_id,
'company_id' => $company_id,
'mt_to' => $phone_no,
'campaign' => $campaign_name,
'mt_status' => 'P',
'mt_text' => $message,
'coding' => $coding,
'msgid' => $msgid,
'is_intern' => $is_intern?$is_intern:'NOT',
'per_credit' => $per_credit ? $per_credit:'0',
'mt_from' => $mt_from?$mt_from:'',
'send_c_code' => $send_c_code,
'mt_create_date' => $timestr,
'mt_update_date' => $timestr,
'ref_id' => $ref_id,
'gateway_id' => $gateway_id,
);
$DBSH->u_insert('bulk_mt_log', $data);
$rows = $DBSH->select(array(
'field' => array('*'),
'table' => 'transaction',
'where' => array(array('company_id = ?', $company_id),
array('transaction_balance > ?', 0),
array('transaction_sms_expire_date > ?', $timestr),),
'order' => 'transaction_sms_expire_date ASC',
));
$data_transaction_id = array();
while($row = $DBSH->fetchRow(DB_FETCHMODE_ASSOC)){
$data_transaction_id[] = $row[transaction_id];
}
$transaction_id = $data_transaction_id[0];
if($transaction_id){
$rows = $DBSH->update(array(
'table' => 'transaction',
'set' => array(array('transaction_balance = transaction_balance - '.$per_credit),),
'where' => array(array('company_id = ?', $company_id),
array('transaction_id = ?', $transaction_id),),
));
}
}
}
}else{
if ($phone){
foreach($phone as $k => $phone_no){
foreach($sms_message as $km => $message){
$check_credit = $credit_class->check_per_credit($phone_no,$is_intern);
$send_c_code = $check_credit['c_code' ];
$per_credit = $check_credit['per_credit'];
if($phone_no){
do{
$msgid = session_get()."_".$user_id;
$check_valid === false;
$found = $DBSH->u_count('bulk_mt_log_data', array(
'msgid' => $msgid,
));
if(!$found){
$check_valid === true;
}
$found = $DBSH->u_count('bulk_mt_log', array(
'msgid' => $msgid,));
if(!$found){
$check_valid === true;
}
}while($check_valid === false);
//
// Perform merge sms
//
$message = process_message_merge($phone_no,$user_id,$message,$company_id);
if($message_type == 'unicode'){
$coding = 3;
$len = mb_strlen($message, 'UTF-8');
$arr = array();
for( $i=0; $i<$len; $i++){
$arr[] = mb_substr($message,$i,1,'UTF-8');;
}
$message2="";
foreach($arr as $k => $substr){
$message2 .= uniord($substr);
}
$message = $message2;
}
else{
$coding = 0;
}
$data = array(
'bulk_mt_log_id' => null,
'user_id' => $user_id,
'company_id' => $company_id,
'mt_to' => $phone_no,
'campaign' => $campaign_name,
'mt_status' => 'P',
'mt_text' => $message,
'coding' => $coding,
'msgid' => $msgid,
'is_intern' => $is_intern?$is_intern:'NOT',
'per_credit' => $per_credit ? $per_credit:'0',
'send_c_code' => $send_c_code,
'mt_create_date' => $timestr,
'mt_update_date' => $timestr,
'ref_id' => $ref_id,
'mt_from' => $mt_from?$mt_from:'',
'gateway_id' => $gateway_id,
);
$DBSH->u_insert('bulk_mt_log', $data);
$rows = $DBSH->select(array(
'field' => array('*'),
'table' => 'transaction',
'where' => array(array('company_id = ?', $company_id),
array('transaction_balance > ?', 0),
array('transaction_sms_expire_date > ?', $timestr),
),
'order' => 'transaction_sms_expire_date ASC',
));
$data_transaction_id = array();
while($row = $DBSH->fetchRow(DB_FETCHMODE_ASSOC)){
$data_transaction_id[] = $row[transaction_id];
}
$transaction_id = $data_transaction_id[0];
if($transaction_id){
$rows = $DBSH->update(array(
'table' => 'transaction',
'set' => array(array('transaction_balance = transaction_balance - '.$per_credit),),
'where' => array(array('company_id = ?', $company_id),
array('transaction_id = ?', $transaction_id),),
));
}
}
}
}
}
}
}else{
$return_data['error'] = $check_credit['error'];
}
if($return_data){
$return_data['status'] ='102';
}else{
$return_data['status'] ='100';
}
return $return_data;
}