How to disable products by default in Prestashop? - prestashop

When Adding new product in Prestashop, you have to be careful to disable it if it's information not completed.
I tried to find a key in ps_configuration table, but there was nothing related to it, or at least I couldn't find it.
Now the question is how to disable product in Prestashop by default?

If you are using v1.7, there is the option "Default activation status" in Shop Parameters -> Product Settings.
If you are using an older version (1.6.x), try this override:
public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
{
parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
if($id_product == null)
$this->active = false;
}
When you add a new product the id_product is only set when saving.
EDIT: The above override doesn't always work because in the tpl, it checks if its associated to the current shop context, and it will always return false, because the product is not yet saved.
Instead, you can change/override the admin template file /admin/themes/default/template/controllers/products where the active switch is set (about line 196) change to:
<span class="switch prestashop-switch fixed-width-lg">
<input onclick="toggleDraftWarning(false);showOptions(true);showRedirectProductOptions(false);" type="radio" name="active" id="active_on" value="1" {if $product->id != null && ( $product->active || !$product->isAssociatedToShop())}checked="checked" {/if} />
<label for="active_on" class="radioCheck">
{l s='Yes'}
</label>
<input onclick="toggleDraftWarning(true);showOptions(false);showRedirectProductOptions(true);" type="radio" name="active" id="active_off" value="0" {if $product->id == null || (!$product->active && $product->isAssociatedToShop())}checked="checked"{/if} />
<label for="active_off" class="radioCheck">
{l s='No'}
</label>
<a class="slide-button btn"></a>
</span>
Adding the check for the $product->id.

Related

Select Option (for dropdown) Laravel

I make a dropdown for a form, I will show the code below. However, when I click the submit button, there is an error saying,
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'brand' cannot be null (SQL: insert into supplier_details.
The data that I chose from the dropdown is actually null. Actually, I'm new to Laravel.
I don't want to make a dropdown list from a database, I just want to display the option and the option will be inserted into the database when the user clicks the submit button after filling in the form.
<div class="form-group row">
<label style="font-size: 16px;" for="id" class = "col-sm-2">Item Brand </label>
<label for="supp_name" class = "col-sm-1">:</label>
<div class="col-sm-7">
<select name="brand" class="form-control js-example-basic-single" required>
<option >Please select item brand</option>
<option value="machine1"> Item Brand 1 </option>
<option value="machine1"> Item Brand 2 </option>
<option value="machine1"> Tem Brand 3 </option>
</select>
</div>
</div>
Controller
public function createsupplierdetails()
{
return view ('frontend.praiBarcode.getweight');
}
public function supplierdetails(Request $r)
{
$details = new SupplierDetail;
$getuserPO = Supplier::where('PO',$r->PO)->first();
$details->brand = $getuserPO->brand;
$details->container_no = $getuserPO->container_no;
$details->date_received = $getuserPO->date_received;
$details->gross_weight = $getuserPO->gross_weight;
$details->tare_weight = $getuserPO->tare_weight;
$details->net_weight = $getuserPO->net_weight;
$details->save();
return view ('frontend.praiBarcode.viewsupplierdetails')
->with('details',$details);
}
This to check to verify if it is working:
Make sure you are submitting the correct form.
Try doing dd on your controller dd($request->all())
If data is reaching the controller and not inserted into the database, check on your model, if it is added to fillable or if there is only id in the guarded array. You can know about more here in https://laravel.com/docs/9.x/eloquent#mass-assignment
Error should be fixed, as soon as you fix it.
Controller
use Validator;
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'brand' => 'required',
]);
if ($validator->fails()) {
return redirect()->back()->with('error', $validator->errors()->first());
}
$details = new SupplierDetail();
$details->brand = $request->brand;
$details->container_no = $request->container_no;
$details->date_received = $request->date_received;
$details->gross_weight = $request->gross_weight;
$details->tare_weight = $request->tare_weight;
$details->net_weight = $request->net_weight;
$details->save();
if ($trending) {
return redirect(route('details.index'))->with('success', 'Field added successfully');
} else {
return redirect()->back()->with('error', 'Field has been not added successfully');
}
}

Force single select with Razor Select Tag Helper

I'm Struggeling to find a solution to the following Problem:
My Razor-Page has a form with two select-elements, only one of which will be active (not disabled) at a time. Their values are associated to the same Property in my model.
I had to make my Property an Array, so I could access the value of both selects, despite one of them always being "null".
This has lead to my select being rendered with the "multiple" attribute in HTML. How can I get rid of this? I want it to be single select.
My selects:
<select asp-for=TätigkeitIds required onchange="this.form.submit()" disabled=#(Model.Erfassung.TätigkeitNavigation != null && Boolean.Equals(Model.Erfassung.TätigkeitNavigation.Abzurechnen, true))>
#{
<option selected=#(Model.Erfassung.TätigkeitNavigation == null) value="">Bitte eine nicht abzurechnende Tätigkeit wählen</option>
foreach(StammdatenTätigkeit Tätigkeit in await Model.GetTätigkeitenAsync(false))
{
<option selected="#(Model.Erfassung.TätigkeitNavigation != null && String.Equals(Tätigkeit.Id, Model.Erfassung.TätigkeitNavigation.Id))" value=#Tätigkeit.Id>#Tätigkeit.Name</option>
}
}
</select>
<select asp-for=TätigkeitIds required onchange="this.form.submit()" disabled=#(Model.Erfassung.TätigkeitNavigation != null && Boolean.Equals(Model.Erfassung.TätigkeitNavigation.Abzurechnen, false))>
#{
<option selected=#(Model.Erfassung.TätigkeitNavigation == null || Boolean.Equals(Model.Erfassung.TätigkeitNavigation.Abzurechnen, false)) value="">nicht abrech. Std.</option>
foreach(StammdatenTätigkeit Tätigkeit in await Model.GetTätigkeitenAsync(true))
{
<option selected="#(Model.Erfassung.TätigkeitNavigation != null && String.Equals(Tätigkeit.Id, Model.Erfassung.TätigkeitNavigation.Id))" value=#Tätigkeit.Id>#Tätigkeit.Name</option>
}
}
</select>
The Property:
[BindProperty(SupportsGet = false)]
public String[] TätigkeitIds { get; set; }
The rendered HTML:
<select required onchange="this.form.submit()" id="T_tigkeitIds" multiple="multiple" name="TätigkeitIds">
<option value="" selected="selected">Bitte eine nicht abzurechnende Tätigkeit wählen</option>
<option selected="selected" value="d58559ac-6601-4871-aff2-aa72982fd5cc">Schulung</option>
</select>
<select required onchange="this.form.submit()" disabled="disabled" id="T_tigkeitIds" multiple="multiple" name="TätigkeitIds">
<option selected="selected" value="">nicht abrech. Std.</option>
<option value="c2b8fd29-c85b-49c1-a2db-35b9fa9d11a0">PJ-Bearbeitung</option>
</select>
Essentially, I am looking for a way to either force the HTML-Select to appear without the multiple-attribute or to make my Property a normal String again and tell the framework to fill it with whichever input isn't null.
Based on the comment from Mike Brind, I was able to solve my problem by simply deactivating the tag helpers for my two select-Tags like so:
<!select name="TätigkeitIds" required onchange="this.form.submit()" #(Model.Erfassung.TätigkeitNavigation != null && Boolean.Equals(Model.Erfassung.TätigkeitNavigation.Abzurechnen, false) ? "disabled" : "")>
#{
<option selected=#(Model.Erfassung.TätigkeitNavigation == null || Boolean.Equals(Model.Erfassung.TätigkeitNavigation.Abzurechnen, false)) value="">nicht abrech. Std.</option>
foreach(StammdatenTätigkeit Tätigkeit in await Model.GetTätigkeitenAsync(true))
{
<option selected="#(Model.Erfassung.TätigkeitNavigation != null && String.Equals(Tätigkeit.Id, Model.Erfassung.TätigkeitNavigation.Id))" value=#Tätigkeit.Id>#Tätigkeit.Name</option>
}
}
</!select>

call function since product-variants.tpl Prestashop

I'm creating a web in Prestashop and my problem is the next:
I has created a new table in db (mysql) called 'tallas' and I have the size's preferences of the users. Now, I need call this table since the page product-variants.tpl because I would like to put cheeked for default the option select by the customer.
I create this function in classes/Product.php
public function getTalla($id_customer){
$result = Db::getInstance()->ExecuteS('
SELECT `talla1`
FROM `tallas`
WHERE `cliente` = `$id_customer`');
return $result;
}
ok, I would like to receive for parameters the user id (I don't know how to do that yet) and I would like to receive the value of talla1 and then I would like put cheeked the option selected by the customer here in the themes/asmart/templates/catalog/_partials/product-variants.tpl in the radio.
<li class="float-xs-left input-container">
<label>
<input class="input-color" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span
{if $group_attribute.html_color_code}class="color" style="background-color: {$group_attribute.html_color_code}" {/if}
{if $group_attribute.texture}class="color texture" style="background-image: url({$group_attribute.texture})" {/if}
><span class="sr-only">{$group_attribute.name}</span></span>
</label>
</li>
Sincerely I don't know any idea to how to do that, can someone help me?
UPDATE: The problem is solved!
The problem is solved. I do that:
in classes/Product.php
public function getTalla(){
$variable = Context::getContext()->customer->id;
$result = Db::getInstance()->ExecuteS('SELECT * FROM `tallas` WHERE `cliente` = `$variable`');
return $result;
}
in ProductController.php
$this->context->smarty->assign('images_ex',$this->product->getTalla());
in product-variants.tpl
{if $images_ex[0]['talla1'] == $group_attribute.name} checked="checked"{/if}
I hope this can help someone in the future.

prestashop 1.7 new module

I have a problem in prestashop 1.7, when I load the form.tpl in my module I can not do a setAction. What I need is that when I continue in the payment I open a new sale with a payment platform and in prestashop in platform carge the validation I leave the code. help please
main file of the prestashop module
public function hookPaymentOptions($params) {
if (!$this->active) {
return;
}
$this->smarty->assign(
$this->getPaymentApiVars()
);
$apiPayement = new PaymentOption();
$apiPayement->setModuleName($this->name)
->setLogo($this->context->link->getBaseLink().'/modules/hhpayment/views/img/pago.jpg')
// ->setCallToActionText($this->l(''))
//Définition d'un formulaire personnalisé
->setForm($this->fetch('module:hhpayment/views/templates/hook/payment_api_form.tpl'))
->setAdditionalInformation($this->fetch('module:hhpayment/views/templates/hook/displayPaymentApi.tpl'))
->setAction($this->context->link->getModuleLink($this->name, 'validation', array(), true));
return [$apiPayement];
}
this is the form.tpl that I charge this without the method but it is by tests
<form action="{$payment_url}" target="_blank" >
<div class="form-group">
{* choix du mode de carte *}
{l s='please choose your card type' mod='hhpayment'}
<div class="radio">
<label>
<input type="radio" name="cb_type" value="mastercard" id="cb_type1" checked="checked" /> Pago internacional
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="cb_type" id="cb_type2" value="visa"/> Pago Nacional
</label>
</div>
</div>
{* Informations pour l'api *}
<input type="hidden" name="success_url" value="{$success_url}" />
<input type="hidden" name="error_url" value="{$error_url}" />
<input type="hidden" name="id_cart" value="{$id_cart}" />
<input type="hidden" name="cart_total" value="{$cart_total}" />
<input type="hidden" name="id_customer" value="{$id_customer}" />
</form>
and this is the validation file
class hhpaymentvalidationModuleFrontController extends ModuleFrontController
{
/**
* Validation du paiement standard
* Puis redirection vers la page de succès de commande
*/
public function postProcess()
{
$cart = $this->context->cart;
$this->abrir("http://davivienda.com");
if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) {
Tools::redirect('index.php?controller=order&step=1');
}
$customer = new Customer($cart->id_customer);
if (!Validate::isLoadedObject($customer)) {
Tools::redirect('index.php?controller=order&step=1');
}
$currency = $this->context->currency;
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
//La command passe directement en statut payé
$this->module->validateOrder((int)$cart->id, Configuration::get('PS_OS_PAYMENT'), $total, $this->module->displayName, null, array(), (int)$currency->id, false, $customer->secure_key);
Tools::redirect('index.php?controller=order-confirmation&id_cart='.(int)$cart->id.'&id_module='.(int)$this->module->id.'&id_order='.$this->module->currentOrder.'&key='.$customer->secure_key);
}
public function abrir($param)
{
echo" <script> window.open(URL,'ventana1,'width=300,height=300,scrollbars=NO')</script> ";
}
}
I was able to find a solution to this problem, I don't know if it is the correct one, but it already works for me:
The postProcess method passes it to the main and the validation.php file passes it to the same folder where the main file is.
Then it is time to modify the validation.php file which was changed to the same directory as main, this file should be as follows.
It should be imported
require_once dirname(__FILE__) . '/config/config.inc.php';
require_once dirname(__FILE__) . '/main.php';
Then to avoid a kernel error the following code snippet must be implemented
global $kernel;
if(!$kernel){
require_once _PS_ROOT_DIR_.'/app/AppKernel.php';
$kernel = new \AppKernel('prod', false);
$kernel->boot();
}
After this, it is necessary to implement the logic and receive the parameters by get that the payment screen will return to us after the payment is made, once this data is received, the cart must be recovered and the data sent to the function that was migrated to the main file
ob_start();
$context = Context::getContext();
if (is_null($context->cart)) {
$context->cart = new Cart($context->cookie->id_cart);
}
if (is_null($context->cart->id_currency)) {
$context->cart->id_currency = $context->cookie->id_currency;
}
$cart = $context->cart;
$customer = new Customer($cart->id_customer);
$currency = $cart->id_currency;
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
$object = new filemain();
$order = $object->methodCreateInMain($cart->id, Configuration::get('PS_OS_PAYMENT'), $total, $currency, $customer->secure_key);
Basically the previous code in validation.php retrieves the cart data and sends it by parameter to the function that was passed to main, where the order will be validated and created.
It should be noted that the return url after payment must be ulrCommerce/module/validation.php
The above worked perfectly for me and is a solution based on various blogs and forums viewed

vBulletin 4.x External Page Login and Variables

I've been searching around and experimenting with this for hours, with no success.
I'm trying to login to vBulletin from an external page. I've managed to get this to work. However what I can't get to work is showing the username and any of the $vbulletin variables.
I've included global.php chdir() to the forum etc etc, but I just can't get it to work.
Does anyone know how to go about this?
This is working example i'm using it. Its working fine. Its show user name and logout button on External page.
I don't know why -vote it.
<?php
$curdir = getcwd();
#Add your root dir below where it says "ADD ROOT" Example: /home/server/public_html/mainsite/forums
#Do not end with a "/" leave it open like above example.
chdir('ADD ROOT');
require_once('ADD ROOT/global.php');
chdir($curdir);
if ($vbulletin->userinfo['userid'] == 0) {
#Form Display Code, You can edit the way the Form is layed out here.
echo "<form id=\"login\" action=\"/forums/login.php?do=login\" method=\"post\" onsubmit=\"md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)\">
<script type=\"text/javascript\" src=\"clientscript/vbulletin_md5.js?v=364\"></script>
Register
<label for=\"navbar_username\">Username</label>
<input type=\"text\" class=\"bginput\" style=\"font-size: 11px\" name=\"vb_login_username\" id=\"navbar_username\" size=\"10\" accesskey=\"u\" tabindex=\"101\" onfocus=\"if (this.value == 'User Name') this.value = '';\" />
<label for=\"navbar_password\">Password</label>
<input type=\"password\" class=\"bginput\" style=\"font-size: 11px\" name=\"vb_login_password\" id=\"navbar_password\" size=\"10\" tabindex=\"102\" />
<label for=\"cb_cookieuser_navbar\"><input type=\"checkbox\" name=\"cookieuser\" value=\"1\" tabindex=\"103\" id=\"cb_cookieuser_navbar\" accesskey=\"c\" />Remember Me?</label>
<input type=\"submit\" class=\"button\" value=\"Login\" tabindex=\"104\" title=\"Enter your username and password in the boxes provided to login, or click the 'register' button to create a profile for yourself.\" accesskey=\"s\" />
<input type=\"hidden\" name=\"s\" value=\"\" />
<input type=\"hidden\" name=\"do\" value=\"login\" />
<input type=\"hidden\" name=\"vb_login_md5password\" />
<input type=\"hidden\" name=\"vb_login_md5password_utf\" />
</form>";
#End Form Display Code
} else {
#Display after login completed
echo "Welcome Back, <b>".$vbulletin->userinfo['username']."</b>";
if ($vbulletin->userinfo['usergroupid'] == '6' ) {
echo " | My Profile";
echo " | AdminCP";
echo " | ModCP";
}
}
?>