overbags Posted March 11 Posted March 11 ciao ho prestashop 1.6.1.24 vorrei cambiare il testo del pulsante "aggiungi al carrello" con "prenota" quando un prodotto o un attributo non è disponibile. pensavo di creare un if nello <span> del <button> "add to cart" tipo if $product->quantity <= 0 prenota else aggiungi al carrello / if ma con $product->quantity mi da la somma totale degli attributi di un prodotto e non la quantità del singolo attributo avete una soluzione ? Share this post Link to post Share on other sites More sharing options...
codencode Posted March 24 Posted March 24 Puoi reperire la quantità di una certa combinazione mediante il seguente metodo statico della classe Product: Product::getQuantity(id_product, $id_product_attribute) Il metodo accetta come parametri l'id dell'articolo e l'id della combinazione. 1 Share this post Link to post Share on other sites More sharing options...
overbags Posted March 24 Posted March 24 (edited) ottimo grazie una domanda se invece che la quantità vorrei recuperare un campo personalizzato come potrei fare ? Edited March 24 by overbags (see edit history) Share this post Link to post Share on other sites More sharing options...
codencode Posted March 24 Posted March 24 Cosa intendi per campo personalizzato? Share this post Link to post Share on other sites More sharing options...
overbags Posted March 24 Posted March 24 nella tabella ps_product_attribute ho due campi personalizzati "reference_uni" e "reference_uni_conf" dovrei recuperarne i dati in questo script ma non riesco a farlo if (!$depends_on_stock) { $id_stock_available = (int)StockAvailable::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop); if ($id_stock_available) { $stock_available = new StockAvailable($id_stock_available); $stock_available->quantity = (int)$quantity; $stock_available->reference_uni = "test1"; $stock_available->reference_uni_conf = "test2"; $stock_available->update(); } else { $out_of_stock = StockAvailable::outOfStock($id_product, $id_shop); $stock_available = new StockAvailable(); $stock_available->out_of_stock = (int)$out_of_stock; $stock_available->id_product = (int)$id_product; $stock_available->id_product_attribute = (int)$id_product_attribute; $stock_available->quantity = (int)$quantity; $stock_available->reference_uni = "test3"; $stock_available->reference_uni_conf = "test4"; Share this post Link to post Share on other sites More sharing options...
codencode Posted March 24 Posted March 24 Quelli non sono campi standard, li avrai aggiunti tu e probabilmente non li hai aggiunti correttamente. Devi assicurarti di aver creato gli attributi nell'entità e di aver aggiunto gli stessi nell'attributo statico $definition dell'entità. Share this post Link to post Share on other sites More sharing options...
overbags Posted March 24 Posted March 24 ho aggiunto e modificato uno script preso online e funziona però mi sa che non è un lavoro ben fatto hai suggerimenti ?// REFERENCE_UNI REFERENCE_UNI_CONF $query_ebay = 'SELECT reference_uni, reference_uni_conf FROM `' . _DB_PREFIX_ . 'product_attribute` WHERE `id_product` = '.(int)$id_product.' AND `id_product_attribute` = '.(int)$id_product_attribute; $ebaym = Db::getInstance()->executeS($query_ebay); $ebayKeys = array_keys($ebaym); $lastebayKey = array_pop($ebayKeys); $reference_uni = ''; $reference_uni_conf = ''; foreach ($ebaym as $eba_k => $ebay) { $reference_uni .= $ebay['reference_uni']; $reference_uni_conf .= $ebay['reference_uni_conf']; if ($eba_k != $lastebayKey) { $reference_uni .= ' | '; $reference_uni_conf .= ' | '; } } if (!$depends_on_stock) { $id_stock_available = (int)StockAvailable::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop); if ($id_stock_available) { $stock_available = new StockAvailable($id_stock_available); $stock_available->quantity = (int)$quantity; $stock_available->reference_uni = $reference_uni; $stock_available->reference_uni_conf = $reference_uni_conf; $stock_available->update(); } else { $out_of_stock = StockAvailable::outOfStock($id_product, $id_shop); $stock_available = new StockAvailable(); $stock_available->out_of_stock = (int)$out_of_stock; $stock_available->id_product = (int)$id_product; $stock_available->id_product_attribute = (int)$id_product_attribute; $stock_available->quantity = (int)$quantity; $stock_available->reference_uni = $reference_uni; $stock_available->reference_uni_conf = $reference_uni_conf; Share this post Link to post Share on other sites More sharing options...
codencode Posted March 24 Posted March 24 Aggiungere campi ad una classe che estende l'ObjectModel, non è facile se non ne conosci il funzionamento. Puoi partire dalla documentazione ufficiale https://devdocs.prestashop.com/1.7/development/components/database/objectmodel/ Comunque in generale non è una buona cosa aggiungere campi alle Entità base di Prestashop, converrebbe creare tabelle ad hoc. 1 Share this post Link to post Share on other sites More sharing options...
overbags Posted March 24 Posted March 24 ok grazie mille dei consigli Share this post Link to post Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now