Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by JuanTomas

  1. Turns out, it was a simple matter of order. The form element has to come before the javascript autocomplete ajax code. The fixed controller HTML output looks like this: <div class="input-group col-lg-12"> <span class="input-group-addon"><i class="icon-user"></i></span> <input type="hidden" id="id_customer" name="id_customer" value="0"> <input type="text" id="customerFilter" class="input-xlarge" name="customerFilter" value=""> <span class="input-group-addon"><i class="icon-search"></i></span> </div> <script type="text/javascript"> $('#customerFilter') .autocomplete( 'ajax-tab.php', { minChars: 2, max: 50, width: 500, selectFirst: false, scroll: false, dataType: 'json', formatItem: function(data, i, max, value, term) { return value; }, parse: function(data) { var mytab = new Array(); for (var i = 0; i < data.length; i++) mytab[mytab.length] = { data: data[i], value: data[i].cname + ' (' + data[i].email + ')' }; return mytab; }, extraParams: { controller: 'AdminCartRules', token: 'd8c1101c0170792c2fc6b21ffe851ea1', customerFilter: 1 } } ) .result(function(event, data, formatted) { $('#id_customer').val(data.id_customer); $('#customerFilter').val(data.cname + ' (' + data.email + ')'); }); </script> Original question follows: Using PS Update: I've tried using the Chrome AJAX debugger with this code. No AJAX call is ever triggered by typing in the box. What do I need to change, so customerFilter.autocomplete will execute when I type in two or more chars? I'm working on an Admin module where the employee has to look up/specify a customer. I want to make an input field like the autocomplete customer lookup field on the Cart Rules "Conditions" tab. For this input field, the javascript for the AJAX call is in admin/themes/default/template/controllers/cart_rules/form.js The AJAX handler is in function ajaxProcess() in AdminCartRulesController.php. In my controller, I call: $this->context->controller->addJqueryPlugin (array ('autocomplete', 'typewatch', 'jscroll')) ; Inspection of the HTML result shows that the corresponding libraries are being loaded. My controller outputs the following HTML for the autocomplete field. The javascript part is copied from the above-mentioned form.js The HTML part is from conditions.tpl The security token is got using Tools::getAdminTokenLite('AdminCartRules')); I've verified that it is the valid token for the AdminCartRules controller. <script type="text/javascript"> $('#customerFilter') .autocomplete( 'ajax-tab.php', { minChars: 2, max: 50, width: 500, selectFirst: false, scroll: false, dataType: 'json', formatItem: function(data, i, max, value, term) { return value; }, parse: function(data) { var mytab = new Array(); for (var i = 0; i < data.length; i++) mytab[mytab.length] = { data: data[i], value: data[i].cname + ' (' + data[i].email + ')' }; return mytab; }, extraParams: { controller: 'AdminCartRules', token: 'd8c1101c0170792c2fc6b21ffe851ea1', customerFilter: 1 } } ) .result(function(event, data, formatted) { $('#id_customer').val(data.id_customer); $('#customerFilter').val(data.cname + ' (' + data.email + ')'); }); </script><div class="input-group col-lg-12"> <span class="input-group-addon"><i class="icon-user"></i></span> <input type="hidden" id="id_customer" name="id_customer" value="0"> <input type="text" id="customerFilter" class="input-xlarge" name="customerFilter" value=""> <span class="input-group-addon"><i class="icon-search"></i></span> The form field appears correctly with its little icons. However, typing in the field does not trigger the autocomplete function. Is there some other setting/connection I need to make?
  2. Thanks razaro, that was the problem! Here's the updated code with two corrections commented: // ADDED THIS LINE SO FIELDS WILL BE SELECTED $this->_select .= ' orders.reference, jct.department ' ; $this->_join .= ' JOIN `'._DB_PREFIX_.'orders` AS orders ON (a.`id_order` = orders.`id_order`) JOIN `'._DB_PREFIX_.'job_card_tracking` AS jct ON (a.`id_job_card` = jct.`id_job_card`)' ; $this->fields_list = array( 'id_job_card' => array( 'title' => 'Job Card ID', 'width' => 50, 'filter_key' => 'id_job_card', ), 'id_order' => array( 'title' => 'Order ID', 'width' => 50, 'filter_key' => 'id_order', ), 'job_card_reference' => array( 'title' => $this->module->l('Job Card Reference'), 'width' => 130, 'filter_key' => 'job_card_reference', ), // CHANGED THIS ARRAY KEY TO reference SO IT CORRESPONDS TO THE FIELD NAME IN DB 'reference' => array( 'title' => $this->module->l('Order Reference'), 'width' => 130, 'filter_key' => 'orders!reference', ), 'department' => array( 'title' => $this->module->l('Department'), 'width' => 130, 'filter_key' => 'jct!department', ), 'delivery_date' => array( 'title' => $this->module->l('Delivery Date'), 'width' => 130, 'filter_key' => 'delivery_date' ) );
  3. (Using PS I've developed a module which creates Job Cards for tracking manufacture of ordered items. Here's a snippet from from the admin controller for the module (method __construct()), showing how I join and filter on a couple of tables other than the job_card table: $this->_join .= ' JOIN `'._DB_PREFIX_.'orders` AS orders ON (a.`id_order` = orders.`id_order`) JOIN `'._DB_PREFIX_.'job_card_tracking` AS jct ON (a.`id_job_card` = jct.`id_job_card`)' ; $this->fields_list = array( 'id_job_card' => array( 'title' => 'Job Card ID', 'width' => 50, 'filter_key' => 'id_job_card', ), 'id_order' => array( 'title' => 'Order ID', 'width' => 50, 'filter_key' => 'id_order', ), 'job_card_reference' => array( 'title' => $this->module->l('Job Card Reference'), 'width' => 130, 'filter_key' => 'job_card_reference', ), 'order_reference' => array( 'title' => $this->module->l('Order Reference'), 'width' => 130, 'filter_key' => 'orders!reference', ), 'department' => array( 'title' => $this->module->l('Department'), 'width' => 130, 'filter_key' => 'jct!department', ), 'delivery_date' => array( 'title' => $this->module->l('Delivery Date'), 'width' => 130, 'filter_key' => 'delivery_date' ) ); As you can see, I'm grabbing orders.reference and job_card_tracking.department. The list view shows these fields in the search bar. All search, filtering, and ordering works correctly. But the columns which correspond to the joined tables do not show the contents of those fields, just the double-hyphen placeholder --. I know for sure those fields aren't empty in the DB, and PS is using the data from those fields to filter and order results. Why are the contents of these columns not displayed in list view?
  4. Using PS On the front-office shipping page in checkout process, there's a fancybox alert that pops up if you try to Continue without checking the box for terms and conditions: "You must agree to the terms of service before continuing." The alert is modal and darkens the entire browser tab. Clicking anywhere on the page dismisses the alert. I need to make a similar alert appear, conditionally, on the payment page. Some of our products are sold internationally, subject to export license. In that case I want to force the customer to acknowledge the export license requirements before paying. I wrote a handler for displayPaymentTop hook. To display the alert, I copied some HTML from the shipping page. public function hookDisplayPaymentTop($params) { if (exportLicenseRequired()) { return('<div style="display: block; width: auto; height: auto;" class="fancybox-overlay fancybox-overlay-fixed"> <div style="opacity: 1; overflow: visible; height: auto; width: 394px; position: absolute; top: 312px; left: 756px;" class="fancybox-wrap fancybox-desktop fancybox-type-html fancybox-opened" tabindex="-1"> <div style="padding: 0px; width: auto; height: auto;" class="fancybox-skin"> <div class="fancybox-outer"> <div style="overflow: auto; width: 394px; height: auto;" class="fancybox-inner"> <p class="fancybox-error">My Export License Required Message!</p> </div> </div> <a title="Close" class="fancybox-item fancybox-close" href="javascript:;"></a> </div> </div> </div>') ; } } } The alert displays at the right time and looks mostly correct (I need to tweak a few style settings). THE PROBLEM: the alert can never be dismissed, and it's modal so it prevents all actions on the browser tab. I don't see where this alert has any provision for a click handler (don't know much about fancybox). My understanding is, href="javascript:;" means "do nothing". What do I have to add, to make this alert fancybox dismiss with a click? Thanks for any help!
  5. Found it! Here is the original HTML line with no dateFormat: <script>$(document).ready(function(){$('.customDatePicker').datepicker();});</script> Here's the same line with a dateFormat specified (note that "yy" means "four-digit year", not "two-digit year" in this context): <script>$(document).ready(function(){$('.customDatePicker').datepicker({dateFormat: "yy-mm-dd"});});</script> Original post follows: --------------------------------------------------------------------------------------------------------------- I have this in php: $this->addJqueryUi('ui.datepicker'); And this in HTML: Delivery Date: <input type="text" name="delivery_date" label="Delivery Date" class="customDatePicker" id="delivery_date" value="'.date('Y-m-d').'"> <script>$(document).ready(function(){$(\'.customDatePicker\').datepicker();});</script> And it works, EXCEPT the datepicker fills out the form field with the date in dd/mm/yyyy format. This breaks my postProcess, which expects to get the date in yyyy-mm-dd If I look in js/date.js I find: //Date.format = 'dd/mm/yyyy'; //Date.format = 'mm/dd/yyyy'; Date.format = 'yyyy-mm-dd'; //Date.format = 'dd mmm yy'; So that's not the problem. In my Dashboard, the date range controls display in yyyy-mm-dd In Orders, the date range pickers display in dd/mm/yyyy I could work around it in postProcess, of course. But I'd prefer employees to see the date in yyyy-mm-dd. How to control this date format? Thanks in advance!
  6. Solved by tuk66, the solution is to modify the top margin which is set in classes/pdf/PDFGenerator.php, function writepage(). Here the relevant line: $this->setMargins(10, 40, 10); The second argument (40) is the top margin for the main content. By increasing this margin, the main content is rendered lower down on the page so it doesn't overlap with the header. Original post follows: _______________________________________ Using PrestaShop I've added a "job card" feature to my PrestaShop, for internal use by the company. It's similar to an invoice but with different information. It renders as a PDF, just like the invoice. Override class is override/classes/pdf/HTMLTemplateJobCard.php (derived from classes/pdf/HTMLTemplateInvoice.php). The header template is this: <table style="width: 100%"> <tr> <td style="width: 50%"> {if $logo_path} <img src="{$logo_path}" style="width:{$width_logo}px; height:{$height_logo}px;" /> {/if} </td> <td style="width: 50%; text-align: left;"> <table style="width: 100%"> <tr> <td style="font-weight: bold; font-size: 14pt; color: #444; width: 100%;"><h1>Job Work Order</h1></td> </tr> <tr><td> </td></tr> <tr> <td style="font-weight: bold; font-size: 14pt; color: #444; width: 100%;">Reference: {$order_reference}</td> </tr> </table> </td> </tr> <tr> <td> <table> <tr><td style="width: 25%; text-align:left;">Order Date:</td><td style="width: 75%; text-align:left;">{$invoice_date}</td></tr> <tr><td style="width: 25%; text-align:left;">Due Date:</td><td style="width: 75%; text-align:left;">{$delivery_date}</td></tr> <tr><td style="width: 25%; text-align:left;">Send Bill To:</td><td style="width: 75%; text-align:left;">{$address_delivery}</td></tr> <tr><td style="width: 25%; text-align:left;">Ship To:</td><td style="width: 75%; text-align:left;">{$address_invoice}</td></tr> <tr><td style="width: 25%; text-align:left;">Phone:</td><td style="width: 75%; text-align:left;">{$phone}</td></tr> <tr><td style="width: 25%; text-align:left;">Email:</td><td style="width: 75%; text-align:left;">{$email}</td></tr> </table> </td> </tr> </table> The content template is this: <table width="100%" id="body" border="0" cellpadding="0" cellspacing="0" style="margin:0;"> <!-- Product --> <tr> <td colspan="2" align="center">Reference</td> <td colspan="1" align="center">Qty</td> <td colspan="1" align="center">Qty In Stock</td> <td colspan="6" align="center">Product</td> <td colspan="2" align="center">Unit Price</td> </tr> {foreach from=$details item=det} <tr> <td colspan="2">{$det.reference}</td> <td colspan="1">{$det.quantity}</td> <td colspan="1">{$det.quantity_in_stock}</td> <td colspan="6">{$det.product_name}</td> <td colspan="2" align="right">{$det.price}</td> </tr> <tr><td colspan=12> </td></tr> {/foreach} </table> There is no footer template (getFooter() returns empty string). Both the header and the content render correctly. Trouble is, they're superimposed: the top line of the content renders at the same place as "Ship To" in the header. Any insights will be greatly appreciated!
  7. Using Prestashop In classes/order/OrderDetail.php we have function create(...) which sets product reference seen on invoice: class OrderDetailCore extends ObjectModel { ... /** @var string */ public $product_reference; ... protected function create(Order $order, Cart $cart, $product, $id_order_state, $id_order_invoice, $use_taxes = true, $id_warehouse = 0) { ... $this->product_reference = empty($product['reference']) ? null : pSQL($product['reference']); ... } } I want to customize the behavior of the reference field on the invoice in override/classes/order/OrderDetail.php: class OrderDetail extends OrderDetailCore { protected function create(Order $order, Cart $cart, $product, $id_order_state, $id_order_invoice, $use_taxes = true, $id_warehouse = 0) { parent::create($order, $cart, $product, $id_order_state, $id_order_invoice, $use_taxes, $id_warehouse) ; ...some code which generates $my_custom_product_reference... // next line of code has no effect, the product_reference field doesn't actually get changed $this->product_reference = $my_custom_product_reference ; } } I'm a little unclear on OOP in php, but I can kind of see why this doesn't work. So I'm considering some options... Modify classes/order/OrderDetail.php (PS core mod, upgrade will break) Try to figure out how to get the instance of OrderDetailCore and set $product_reference directly (it's public). Develop a module and hook actionValidateOrder, then modify ps_order_detail.product_reference directly in the database. I'm not sure how the module can find out the order id or reference when the hook function is called. Override classes/order/OrderHistory.php and directly modify the database when an order's OrderState is set to FLAG_PAID Any insights or ideas will be much appreciated!
  8. Solution: To retrieve a template variable that has been assigned to smarty in the context, use smarty->getTemplateVars() get_template_vars() is deprecated and unknown. Original question follows: ========================================== (Using Prestashop 1.6) ProductControllerCore has this function I want to override: protected function assignAttributesGroups() { //...do lots and lots of processing, then assign the results to smarty... $this->context->smarty->assign(array( 'groups' => $groups, 'colors' => (count($colors)) ? $colors : false, 'combinations' => $combinations, 'combinationImages' => $combination_images )); } Now here's my override: protected function assignAttributesGroups() { parent::assignAttributesGroups() ; // this next line fails with "Call of unknown method" $combinations = $this->context->smarty->get_template_vars("combinations") ; // if I could get the $combinations array, I'd add some custom fields to it, and then... $this->context->smarty->assign(array( 'combinations' => $combinations )); } According to this, get_template_vars() is a legitimate smarty method: http://www.smarty.net/docsv2/en/api.get.template.vars.tpl But it's unknown here for some reason. My new assignment overrides the one in the parent class. But that just breaks stuff, because the original contents of the array are lost. Is there a way for me to get a copy of the $combinations array in this override?
  9. SOLVED: it turns out all the data for basic stock management is in the ps_stock_available table. The quantity fields in ps_product and ps_product_attribute are not used for basic stock management. Here's the funny part: I thought my database had no ps_stock_available table. Turns out it does, it's table number 251 in the database. My phpMyAdmin displays only 250 tables in a view. Here's how I found out: $ mysqldump --user=root --password=myrootpass --xml my_ps_db > before.xml ...make one change in back office... $ mysqldump --user=root --password=myrootpass --xml my_ps_db > after.xml $ diff before.xml after.xml Thus was the ps_stock_available table revealed. Original post follows: ****************************** I've enabled basic stock management in prestashop I've manually entered some sample values for quantities of both products and product attribute combinations. The back office behavior is as expected; quantities are decremented when the item is ordered and the order confirmed. Trouble is, when I check the quantity field in either ps_product or ps_product_attribute, it's always set to 0. I'm sure I've identified the correct id_product / id_product_attribute. So, apparently the quantity field in those tables is not used for basic stock management. ps_product_shop and ps_product_attribute_shop do not have quantity fields. ps_stock table exists but is empty (I think it's just for advanced stock management, which I'm not planning to use). There is no ps_stock_available table.
  10. I'm getting ready for Black Friday, when I will be putting thousands of items on sale prices for the weekend. I developed some PHP automation to update and roll back the prices. I found that if you update the price field in ps_product table, nothing happens. The previous price continues to be displayed in both front and back office. Turns out, you also have to update the price field in ps_product_shop table. ps_product_shop duplicates several fields from ps_product, including not only price but also id_category_default. Where there is a discrepancy between ps_product and ps_product_shop, ps_product_shop seems to always win. This can drive you crazy when you update the values in ps_product and nothing happens. Hope this helps someone!
  11. SOLVED: if you want to use SQL queries to assign products to categories, you have to update the category id in three (3) places: ps_product.id_category_default (shokinro apparently didn't read my original question; I had already noticed this) ps_category_product.id_category ps_product_shop.id_category_default ps_product_shop duplicates several fields from ps_product, including not only id_category_default but also price. Where there is a discrepancy between ps_product and ps_product_shop, ps_product_shop seems to always win. This can drive you crazy when you update the values in ps_product and nothing happens. Hope this helps someone! -----original question below------- Using Prestashop I had a category (call it category A) with many Imperial products and many Metric products. I decided to create separate subcategories for Imperial and Metric and move all the products into those new categories. Once the new categories were created, I used a couple of database queries to update ps_product.id_category_default and ps_category_product.id_category for the selected products. Now, in the front view, all the products appear in the new categories they belong to. In the back view, when looking at products and filtering by category, the products also appear in the correct places, but the Category column still shows category A! So, when I filter products by category, and go into "Metric" category, I see all the products that belong there, but the category column shows all category A, not category Metric. The same products are not seen at all when viewing products in category A. If I edit one of these products, the category association shows correctly (e.g. Metric and not A). If I change nothing and save, then the category information magically becomes correct in the BO product listing, and the product is "fixed". This matters, because I have a ProductController override which uses id_category_default to make some display decisions: $category = new Category($this->product->id_category_default); // Use properties of $category to do stuff // Wait, why'd it return category A??? This product is in Metric! This override starts to work normally on products where I've "re-saved". Studying the database, I don't see any difference between "re-saved" products and the others. ps_product.id_category_default and ps_category_product.id_category don't get changed by the "re-save". But somehow re-saving the product gets rid of the weird behavior. I *could* just edit and re-save all the products, but there are hundreds, and the whole idea of using SQL queries was to avoid the manual process. I tried clearing the cache under advanced-> performance. That didn't fix the problem. Where, other than ps_product.id_category_default and ps_category_product.id_category, might this incorrect mapping persist in the database?
  12. Using P-Shop When you view a pdf invoice, the text in the Product column is the product_name properties of OrderDetail objects. The product_name property consists of the name of the product, plus the names and values of all attributes of the product for that order, all concatenated into a single string. Here's the code in classes/order/OrderDetail.php, in the create() function: $this->product_name = $product['name']. ((isset($product['attributes']) && $product['attributes'] != null) ? ' - '.$product['attributes'] : ''); I had an order for a product with about six attributes, and the names and values of all those attributes were longish. Taken all together, they added up to a string about 300+ characters long. For some reason, the string was getting truncated at 255 characters when the pdf invoice was generated, so sales staff couldn't see exactly what the customer ordered. The problem isn't in code, it's in the data model. The database field product_name in ps_order_detail table is varchar(255). This turned out to be a bit stingy, in my case. I decided to alter the table to accommodate strings up to 1024 characters. If you have the same problem, just execute the following query on your database (using phpMyAdmin or mysql) (check your database prefix, I'm using "ps_"): ALTER TABLE `ps_order_detail` MODIFY `product_name` VARCHAR(1024) After that, future invoices will display all the OrderDetail info.
  13. (Using P-Shop It's easy to override methods that return raw data. For instance, BlockNewProducts.php in the blocknewproducts module has the getNewProducts() method: class BlockNewProducts extends Module{ ... protected function getNewProducts() { // makes an array called $newProducts, which contains several product objects return $newProducts; } ... } So you can override like: class BlockNewProductsOverride extends BlockNewProducts { protected function getNewProducts() { $NewProducts = array(); $BaseProducts = parent::getNewProducts(); foreach ($BaseProducts as $product){ // Add Custom Fields To Each Product Object $product['my-key']="My Most Excellent Value"; // Push modified product objects onto a new array $NewProducts[] = $product ; } // Now the template can behave differently depending on the values in each product's my-key return $NewProducts ; } } But some modules don't have a separate method like this. Consider BlockViewed.php in the blockviewed module. Its hookRightColumn() method does all the work in the class. You can skip most of the code, what's important is: * The method is longish * The method contains all the "business logic" for displaying viewed objects, and... * The method calls display() at the end. class BlockViewed extends Module { ... public function hookRightColumn($params) { $productsViewed = (isset($params['cookie']->viewed) && !empty($params['cookie']->viewed)) ? array_slice(array_reverse(explode(',', $params['cookie']->viewed)), 0, Configuration::get('PRODUCTS_VIEWED_NBR')) : array(); if (count($productsViewed)) { $defaultCover = Language::getIsoById($params['cookie']->id_lang).'-default'; $productIds = implode(',', array_map('intval', $productsViewed)); $productsImages = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT MAX(image_shop.id_image) id_image, p.id_product, il.legend, product_shop.active, pl.name, pl.description_short, pl.link_rewrite, cl.link_rewrite AS category_rewrite FROM '._DB_PREFIX_.'product p '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product'.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = p.id_product)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN '._DB_PREFIX_.'image_lang il ON (il.id_image = image_shop.id_image AND il.id_lang = '.(int)($params['cookie']->id_lang).') LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').') WHERE p.id_product IN ('.$productIds.') AND pl.id_lang = '.(int)($params['cookie']->id_lang).' AND cl.id_lang = '.(int)($params['cookie']->id_lang).' GROUP BY product_shop.id_product' ); $productsImagesArray = array(); foreach ($productsImages as $pi) $productsImagesArray[$pi['id_product']] = $pi; $productsViewedObj = array(); foreach ($productsViewed as $productViewed) { $obj = (object)'Product'; if (!isset($productsImagesArray[$productViewed]) || (!$obj->active = $productsImagesArray[$productViewed]['active'])) continue; else { $obj->id = (int)($productsImagesArray[$productViewed]['id_product']); $obj->id_image = (int)$productsImagesArray[$productViewed]['id_image']; $obj->cover = (int)($productsImagesArray[$productViewed]['id_product']).'-'.(int)($productsImagesArray[$productViewed]['id_image']); $obj->legend = $productsImagesArray[$productViewed]['legend']; $obj->name = $productsImagesArray[$productViewed]['name']; $obj->description_short = $productsImagesArray[$productViewed]['description_short']; $obj->link_rewrite = $productsImagesArray[$productViewed]['link_rewrite']; $obj->category_rewrite = $productsImagesArray[$productViewed]['category_rewrite']; // $obj is not a real product so it cannot be used as argument for getProductLink() $obj->product_link = $this->context->link->getProductLink($obj->id, $obj->link_rewrite, $obj->category_rewrite); if (!isset($obj->cover) || !$productsImagesArray[$productViewed]['id_image']) { $obj->cover = $defaultCover; $obj->legend = ''; } $productsViewedObj[] = $obj; } } if (!count($productsViewedObj)) return; $this->smarty->assign(array( 'productsViewedObj' => $productsViewedObj, 'mediumSize' => Image::getSize('medium'))); return $this->display(__FILE__, 'blockviewed.tpl'); } return; } ... } How is it possible to override this? You'd literally have to copy the entire method into your override to add any functionality to it. That kind of override will not play well with upgrades. I think this is a violation of the MVC concept, because it couples the Model to the View so tightly that you can't floss in between. Business logic belongs in a separate method where it can be safely overridden. Any method making a display() call should be getting its input data from a separate "business logic" method. This problem is widespread in Prestashop core modules and classes. Is there something I'm missing here? Is there an elegant way to override methods like this?
  14. Okay, I was able to improve it somewhat, getting rid of one of the str_replace calls: $product['cat_image']=str_replace( _PS_ROOT_DIR_, _PS_BASE_URL_.'/'.str_replace('/','', __PS_BASE_URI__), _PS_CAT_IMG_DIR_.$category->id_category.'-small_default.jpg' ); (I just noticed, this won't work if there's a slash inside __PS_BASE_URI__. So if your shop is at e.g. www.mydomain.com/xxx/myshop you'll need to use the uglier version in my first post.) That's an acceptable way to find the category image URL, given a prestashop category object. I still suspect there may be a way that's "more standard", given this is probably a pretty common thing to want to do.
  15. I have a catalog with many thousands of similar items, and I don't want to bother to attach images to every single one. Instead, I use a generic image, assigned to the category. I've developed a couple of overrides so far, so that when viewing a product, (whether in product view, blocknewproducts module, etc.) the generic category image is substituted for the (nonexistent) product image. It all looks very nice. What doesn't look so nice is the way I have to scrounge around to get the URL of the category image so I can pass it to the template. Here's the logic (Prestashop $product['cat_image_url']=str_replace('http:', 'http:/', str_replace('//','/', str_replace( _PS_ROOT_DIR_, _PS_BASE_URL_.__PS_BASE_URI__, _PS_CAT_IMG_DIR_.$category->id_category.'-small_default.jpg' ) ) ); That's three, count 'em three, nested str_replace calls. The problem is, PS_BASE_URL has a trailing slash, and PS_BASE_URI has a leading slash. That makes a double slash in the middle of the URL. To clean that up, you need to replace the double slash with a single. But now you've wrecked the double slash after 'http:' so you have to go back and add another slash after 'http:'. Browsers seem to tolerate the double-slash after PS_BASE_URL, treating it as a single slash. Whatever, I'm uptight and I like to do things intentionally, not lean on the other guy to deal with my sloppy work. Anybody know a cleaner way, in Prestashop or PHP, to get the category image URL, given a category object?
  16. Disregard, it appears to be working now. Still says override is false in class_index.php, but legacy logins are working. Sorry for the fuss.
  17. I have a PS instance where I've imported a large number of Customer records including password hashes created by ZenCart. The import module I used comes with an override class in Customer.php, which adds the functionality to check/decode those hashes for legacy customers. It's pretty much exactly what JoAo Cunha was doing with PS1.5x here: https://www.prestashop.com/forums/topic/163534-integrating-zen-cartoscommerce-passwords-with-prestashop/ THE PROBLEM: the override class never gets loaded. If this seems like a familiar problem, I've already seen and tried the following solutions: Put Customer.php (class Customer extends CustomerCore) in prestashop/override/classes Make sure Customer.php is readable to the apache2 user (www-data on my system) Blow away prestashop/cache/class_index.php (Wanted to make sure you know I did that.) Verify there are no subfolders in override/controllers/front which might contain override classes Clear cache in BO -> Advanced Parameters -> Performance Make sure all Debug options (disable all overrides) are set to NO in Performance -> Debug Make sure _PS_MODE_DEV_ is set to 'false' in prestashop/config/defines.inc.php Review http://doc.prestashop.com/display/PS16/Overriding+default+behaviors PS generates a new class_index.php file each time, and each time it contains this snippet: This suggests to me that PS perhaps doesn't detect overriding classes the same as previous versions?
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More