Jump to content

Clone function "on sale" for another use. [solved]


sm5k

Recommended Posts

Hi there Community,

 

today i need to double the original function "on Sale" from Prestashop.

 

I would need exactly the same code and working like the original but a second time with a second checkbox and another word spawning if checkbox is checked.

 

I guess i need to add a new column in ps_product in database.

 

Anyone of you have done that before? Would be great getting some tipps on how to clone that function

and which parts of the code are needed for doing that.

 

Thx a lot and enjoy your day.

 

Greetz

Sm5k

 

PS: Using Prestashop 1.5.5

 

Edited by sm5k (see edit history)
Link to comment
Share on other sites

Update and more informations.

 

I set up a new row in ps_product with same stats like on_sale called on_sale_nes

 

I doubled all functions using on_sale to on_sale_nes in the following files.

 

admin\themes\default\template\controllers\products\prices.tpl

\classes\Product.php

controllers\admin\AdminProductsController.php

\js\admin-products.js

\classes\Cart.php

 

To me it seems working great.

Checkbox is there. Checking sets values inside DB but saving product brings the following Error.

 

"Bei der Aktualisierung ist ein Fehler aufgetreten product ()"

 

Any Ideas would be apriciated :)

 

Thx a lot!!!

Link to comment
Share on other sites

  • 3 weeks later...

Hi again, [sOLVED]

I was going with your description.

 

And add a MY_FIELD field:

  1.  Created a new row in the ps_product nad also in the ps_prosuct_shop
  2.  admin\themes\default\template\controllers\products\prices.tpl

I  didn't copy whole  <div class="form-group">

 

only from the <div class="col-lg-1">......

 

​ <!-- HERE begins ONSALE -->
<div class="form-group">
<div class="col-lg-1"><span class="pull-right">{include file="controllers/products/multishop/checkbox.tpl" field="on_sale" type="default"}</span></div>
<label class="control-label col-lg-2" for="on_sale"> </label>
<div class="col-lg-9">
<div class="checkbox">
<label class="control-label" for="on_sale" >
<input type="checkbox" name="on_sale" id="on_sale" {if $product->on_sale}checked="checked"{/if} value="1" />
{l s='Display the "on sale" icon on the product page, and in the text found within the product listing.'}
</label>
</div>
</div>
<!-- here I deleted one </div> -->

<!-- HERE ENDS ONSALE -->
<!-- HERE BEGINS MY_FIELD-->


<div class="col-lg-1"><span class="pull-right">{include file="controllers/products/multishop/checkbox.tpl" field="MY_FIELD" type="default"}</span></div>
<label class="control-label col-lg-2" for="MY_FIELD"> </label>
<div class="col-lg-9">
<div class="checkbox">
<label class="control-label" for="MY_FIELD" >
<input type="checkbox" name="MY_FIELD" id="MY_FIELD" {if $product->MY_FIELD}checked="checked"{/if} value="1" />
{l s='Display the "action" icon on the product page, and in the text found within the product listing.'}
</label>
</div>
</div>
</div>
<!-- HERE ENDS MY_FIELD -->

 

 just changed the ON_SALE for MY_FIELD

 

     3. \classes\Product.php

 

copy this line 

possition is somthing around line90

/** @var boolean on_sale */
public $on_sale = false; 

/**@var boolean MY_FIELD */
public $MY_FIELD = false;

and this

somethig around line 270
'on_sale' => array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool'),
'MY_FIELD' => array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool'),

       4.  controllers\admin\AdminProductsController.php

 

around line 350

 

if ($this->isTabSubmitted('Prices'))
$object->on_sale = (int)Tools::getValue('on_sale');
$object->MY_FIELD = (int)Tools::getValue('MY_FIELD');

and around line 3760

array_push($product_props,
'price', 'wholesale_price', 'id_tax_rules_group', 'unit_price_ratio', 'on_sale', 'MY_FIELD',
'unity', 'minimum_quantity', 'additional_shipping_cost',
'available_now', 'available_later', 'available_date'
);

      5.   \js\admin-products.js

 

something around line 1810

ProductMultishop.checkField($('input[name=\'multishop_check[on_sale]\']').prop('checked'), 'on_sale');
ProductMultishop.checkField($('input[name=\'multishop_check[MY_FIELD]\']').prop('checked'), 'MY_FIELD');

     6.   \classes\Cart.php

somethig around line 440

$sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, pl.`name`, p.`is_virtual`,
pl.`description_short`, pl.`available_now`, pl.`available_later`, product_shop.`id_category_default`, p.`id_supplier`,
p.`id_manufacturer`, product_shop.`on_sale`, product_shop.`MY_FIELD`, product_shop.`ecotax`, product_shop.`additional_shipping_cost`,
product_shop.`available_for_order`, product_shop.`price`, product_shop.`active`, product_shop.`unity`, product_shop.`unit_price_ratio`,
stock.`quantity` AS quantity_available, p.`width`, p.`height`, p.`depth`, stock.`out_of_stock`, p.`weight`,
p.`date_add`, p.`date_upd`, IFNULL(stock.quantity, 0) as quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category,
CONCAT(LPAD(cp.`id_product`, 10, 0), LPAD(IFNULL(cp.`id_product_attribute`, 0), 10, 0), IFNULL(cp.`id_address_delivery`, 0)) AS unique_id, cp.id_address_delivery,
product_shop.advanced_stock_management, ps.product_supplier_reference supplier_reference, IFNULL(sp.`reduction_type`, 0) AS reduction_type');

And thats  IT !!!!

On my side it is working normally.

I think you maybe forgot to create the row in thr ps_product_shop table 

or you didn't edit the product.php correctly the bottom part around the line 270.

 

Hope it will fix this for you.

 

Edited by Mathew_MT (see edit history)
Link to comment
Share on other sites

Hey Mathew,

 

thanks for your answer and sorry i didn`t reply to your question. I unfortunatly didn`t see it.

I solved it long time ago, than forgot :D

 

You are right, the problem was the second table ps_product_shop table
in db that i didn`t mind. Once i got this and set up

the new column everything was fine.

 

I´ll mark that as solved now :D

All the followers will be impressed by your good explanaiton on how to do it :D

 

Greetz and have a great week!

SM5K

  • Like 2
Link to comment
Share on other sites

  • 5 months later...
  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...