Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Prestashop Dodawanie produktów - dodatkowa opcja
qbas-s
post
Post #1





Grupa: Zarejestrowani
Postów: 304
Pomógł: 1
Dołączył: 28.06.2009

Ostrzeżenie: (0%)
-----


Potrzebuję dodać dodatkową opcję podczas dodawania produktu.


w .tpl dodałem co trzeba i od strony widoku jest wszystko ok.
do tpl dodałem to


  1.  
  2. <div class="checkbox">
  3. <label for="discontinued">
  4. <input type="checkbox" name="discontinued" id="discontinued" value="1" {if $product->discontinued}checked="checked"{/if} >
  5. Produkt wycofany z produkcji - zostaną pokazane zamienniki</label>
  6. </ div>







W AdminProductsController
w metodzie copyFromPost()




dokonałem aktualizacji tego
  1.  
  2. if ($this->isTabSubmitted('Informations')) {
  3.  
  4.  
  5. $object->available_for_order = (int) Tools::getValue('available_for_order');
  6. $object->show_price = $object->available_for_order ? 1 : (int) Tools::getValue('show_price');
  7. $object->online_only = (int) Tools::getValue('online_only');
  8. }



na to

  1.  
  2. if ($this->isTabSubmitted('Informations')) {
  3.  
  4. $object->discontinued = (int) Tools::getValue('discontinued');
  5. $object->available_for_order = (int) Tools::getValue('available_for_order');
  6. $object->show_price = $object->available_for_order ? 1 : (int) Tools::getValue('show_price');
  7. $object->online_only = (int) Tools::getValue('online_only');
  8. }



dodatkowo w metodzie initFormInformations()
zmieniłem


  1.  
  2. array_push($product_props, 'reference', 'ean13', 'upc', 'available_for_order', 'show_price', 'online_only', 'id_manufacturer'
  3. );

na to

  1.  
  2.  
  3. array_push($product_props, 'reference', 'ean13', 'upc', 'available_for_order','discontinued', 'show_price', 'online_only', 'id_manufacturer'
  4. );



do tabeli _product dodałem oczywiście kolumnę discontinued tinyint(1) default 0

Po zapisaniu produktu nic się nie aktualizuje. O czym jeszcze zapomniałem?
Teraz modyfikuję główne pliki presty. Wiadomo co się stanie po aktualizacji. W związku z tym jak w presta powinno się dokonywać tego typu modyfikacji?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
gorny
post
Post #2





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 15.04.2013

Ostrzeżenie: (0%)
-----


Powinieneś to zrobić w katlogu override

override/classes/Product.php

  1. <?php
  2.  
  3. Class Product extends ProductCore {
  4.  
  5. public $discontinued = false;
  6.  
  7. public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null) {
  8. self::$definition['fields']['discontinued'] = array('type' => self::TYPE_BOOL, 'validate' => 'isBool');
  9. parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
  10. }
  11.  
  12. }


i jeśli nowym polem jest checkbox, to aby go poprawnie zapisać musisz jeszcze jedną klasę nadpisać

override/controllers/admin/AdminProductsController.php

  1. class AdminProductsController extends AdminProductsControllerCore {
  2.  
  3. protected function copyFromPost(&$object, $table) {
  4. parent::copyFromPost($object, $table);
  5. if (get_class($object) != 'Product')
  6. return;
  7.  
  8. $object->discontinued = (int) Tools::getValue('discontinued');
  9. }
  10.  
  11. }


nowy widok też powinieneś zrobić w katalogu override, skopiuj plik informtions.tpl do override/controllers/admin/templates/products/informations.tpl i tam wstaw sobie html z inputem

Ten post edytował gorny 13.04.2015, 17:36:53
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 11.10.2025 - 12:48