Jump to content
thirty bees forum

ssimard

Members
  • Posts

    162
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by ssimard

  1. The closing body tag is located at the END of your page, it's normal. The header.tpl is just for the header.
  2. Ok so basically there are 2 separate code blocks. One goes in the header, and the other one is the logo I assume so it can go ANYWHERE inside your body.
  3. I did my own theme using the default one as a template, so I don't have this problem ;-) What kind of code is it, Javascript ? It can be added to the custom code section in the back office too.
  4. Well if you're not using the default theme, it won't get upgraded ;-)
  5. If you want it on all your pages, just go to /themes/yourtheme/header.tpl, edit that file and paste the code you've got at the proper place. This is the general header file, you'll be able to paste it just fine between the head and body tag. Or did I miss something ?
  6. @mockob said in Retina images are not created when uploading through the webservice: @DRMasterChief if your theme supports retina images that code is unnecessary but I saw many themes which advertise they support retina images and they don't. Actually there are quite few which really do... Actually there is more... Even if your theme supports Retina, the csv import and image creation through the webservice DOES NOT create them. It's only working when you add them through the backend. Also I would suggest to use the great ImageMagick v1.3.0 - by Michael Dekker & Robert Andersson module. It allows you to keep the original uploaded image UNMODIFIED on the server. Keep the original copy on the server. By default thirty bees encodes the image immediately after uploading and twice when resizing. By enabling this option, encoding right after the upload will be disabled. You also have to make sure that you have the option to create high resolution image set to ON in the back office (see picture, sorry for the french language).
  7. It was not solved in 1.0.3 so I did this fix today in mine. EdIt: I did not check if the fix for csv upload was done in 1.0.3 cause I did fix it in mine anyway.. I may have misunderstood your question.
  8. If you want to add stuff in the HEAD setion of your page, you have to do it in the hookDisplayHeader function of your controller. This is also where you would load custom css and Javascript files. You can load a tpl from there and add your code in it. For example, in the socialsharing module, look in the socialsharing_header.tpl of the module in your theme. Oh and of course, you will have to register your module for this hook if it's not already done.
  9. This is a follow-up to this thread: Retina images help. Retina 2x images are NOT created either via the webservice. I got it fixed for csv import but we are going to maintain our products via Filemaker Pro and I also need to import images using the webservice. I fixed it for my use so if someone is willing to fix this in the real build it would be much appreciated. Fix goes into /override/webservice/WebserviceSpecificManagementImages.php. I did not fix the customizations part since I don't need it. The added code is under the "// Retina 2x images" comments. Hopefully this helps someone else, here is the full override code: ``` class WebserviceSpecificManagementImages extends WebserviceSpecificManagementImagesCore { /** * Write the posted image on disk * * @param string $receptionPath * @param int $destWidth * @param int $destHeight * @param array $imageTypes * @param string $parentPath * * @return bool * * @throws WebserviceException */ protected function writePostedImageOnDisk($receptionPath, $destWidth = null, $destHeight = null, $imageTypes = null, $parentPath = null) { $imgMaxUploadSize = Tools::getMaxUploadSize(); // Retina 2x images $generateHiDpiImages = (bool) Configuration::get('PS_HIGHT_DPI'); if ($this->wsObject->method == 'PUT') { if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) { $file = $_FILES['image']; if ($file['size'] > $imgMaxUploadSize) { throw new WebserviceException(sprintf('The image size is too large (maximum allowed is %d KB)', ($imgMaxUploadSize / 1000)), [72, 400]); } // Get mime content type $mimeType = false; if (Tools::isCallable('finfo_open')) { $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME; $finfo = finfo_open($const); $mimeType = finfo_file($finfo, $file['tmp_name']); finfo_close($finfo); } elseif (Tools::isCallable('mime_content_type')) { $mimeType = mime_content_type($file['tmp_name']); } elseif (Tools::isCallable('exec')) { $mimeType = trim(exec('file -b --mime-type '.escapeshellarg($file['tmp_name']))); } if (empty($mimeType) || $mimeType == 'regular file') { $mimeType = $file['type']; } if (($pos = strpos($mimeType, ';')) !== false) { $mimeType = substr($mimeType, 0, $pos); } // Check mime content type if (!$mimeType || !in_array($mimeType, $this->acceptedImgMimeTypes)) { throw new WebserviceException('This type of image format is not recognized, allowed formats are: '.implode('", "', $this->acceptedImgMimeTypes), [73, 400]); } // Check error while uploading elseif ($file['error']) { throw new WebserviceException('Error while uploading image. Please change your server\'s settings', [74, 400]); } // Try to copy image file to a temporary file if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['image']['tmp_name'], $tmpName)) { throw new WebserviceException('Error while copying image to the temporary directory', [75, 400]); } // Try to copy image file to the image directory else { $result = $this->writeImageOnDisk($tmpName, $receptionPath, $destWidth, $destHeight, $imageTypes, $parentPath); } @unlink($tmpName); return $result; } else { throw new WebserviceException('Please set an "image" parameter with image data for value', [76, 400]); } } elseif ($this->wsObject->method == 'POST') { if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) { $file = $_FILES['image']; if ($file['size'] > $imgMaxUploadSize) { throw new WebserviceException(sprintf('The image size is too large (maximum allowed is %d KB)', ($imgMaxUploadSize / 1000)), [72, 400]); } require_once(_PS_CORE_DIR_.'/images.inc.php'); if ($error = ImageManager::validateUpload($file)) { throw new WebserviceException('Image upload error : '.$error, [76, 400]); } if (isset($file['tmp_name']) && $file['tmp_name'] != null) { if ($this->imageType == 'products') { $product = new Product((int) $this->wsObject->urlSegment[2]); if (!Validate::isLoadedObject($product)) { throw new WebserviceException('Product '.(int) $this->wsObject->urlSegment[2].' does not exist', [76, 400]); } $image = new Image(); $image->id_product = (int) ($product->id); $image->position = Image::getHighestPosition($product->id) + 1; if (!Image::getCover((int) $product->id)) { $image->cover = 1; } else { $image->cover = 0; } if (!$image->add()) { throw new WebserviceException('Error while creating image', [76, 400]); } if (!Validate::isLoadedObject($product)) { throw new WebserviceException('Product '.(int) $this->wsObject->urlSegment[2].' does not exist', [76, 400]); } Hook::exec('updateProduct', ['id_product' => (int) $this->wsObject->urlSegment[2]]); } // copy image if (!isset($file['tmp_name'])) { return false; } if ($error = ImageManager::validateUpload($file, $imgMaxUploadSize)) { throw new WebserviceException('Bad image : '.$error, [76, 400]); } if ($this->imageType == 'products') { $image = new Image($image->id); if (!(Configuration::get('PS_OLD_FILESYSTEM') && file_exists(_PS_PROD_IMG_DIR_.$product->id.'-'.$image->id.'.jpg'))) { $image->createImgFolder(); } if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($file['tmp_name'], $tmpName)) { throw new WebserviceException('An error occurred during the image upload', [76, 400]); } elseif (!ImageManager::resize($tmpName, _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'.'.$image->image_format)) { throw new WebserviceException('An error occurred while copying image', [76, 400]); } else { $imagesTypes = ImageType::getImagesTypes('products'); foreach ($imagesTypes as $imageType) { if (!ImageManager::resize($tmpName, _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'-'.stripslashes($imageType['name']).'.'.$image->image_format, $imageType['width'], $imageType['height'], $image->image_format)) { $this->_errors[] = Tools::displayError('An error occurred while copying image:').' '.stripslashes($imageType['name']); } // Retina 2x images if ($generateHiDpiImages) { if (!ImageManager::resize($tmpName, _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'-'.stripslashes($imageType['name']).'2x.'.$image->image_format, (int) $imageType['width'] * 2, (int) $imageType['height'] * 2, $image->image_format)) { $this->_errors[] = Tools::displayError('An error occurred while copying image:').' '.stripslashes($imageType['name']).'2x'; } } } } @unlink($tmpName); $this->imgToDisplay = _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'.'.$image->image_format; $this->objOutput->setFieldsToDisplay('full'); $this->output = $this->objOutput->renderEntity($image, 1); $imageContent = ['sqlId' => 'content', 'value' => base64_encode(file_get_contents($this->imgToDisplay)), 'encode' => 'base64']; $this->output .= $this->objOutput->objectRender->renderField($imageContent); } elseif (in_array($this->imageType, ['categories', 'manufacturers', 'suppliers', 'stores'])) { if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($file['tmp_name'], $tmpName)) { throw new WebserviceException('An error occurred during the image upload', [76, 400]); } elseif (!ImageManager::resize($tmpName, $receptionPath)) { throw new WebserviceException('An error occurred while copying image', [76, 400]); } $imagesTypes = ImageType::getImagesTypes($this->imageType); foreach ($imagesTypes as $imageType) { if (!ImageManager::resize($tmpName, $parentPath.$this->wsObject->urlSegment[2].'-'.stripslashes($imageType['name']).'.jpg', $imageType['width'], $imageType['height'])) { $this->_errors[] = Tools::displayError('An error occurred while copying image:').' '.stripslashes($imageType['name']); } // Retina 2x images if ($generateHiDpiImages) { if (!ImageManager::resize($tmpName, $parentPath.$this->wsObject->urlSegment[2].'-'.stripslashes($imageType['name']).'2.jpg', (int) $imageType['width'] * 2, (int) $imageType['height'] * 2)) { $this->_errors[] = Tools::displayError('An error occurred while copying image:').' '.stripslashes($imageType['name']).'2x'; } } } @unlink(_PS_TMP_IMG_DIR_.$tmpName); $this->imgToDisplay = $receptionPath; } elseif ($this->imageType == 'customizations') { $filename = md5(uniqid(rand(), true)); $this->imgToDisplay = _PS_UPLOAD_DIR_.$filename; if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($file['tmp_name'], $tmpName)) { throw new WebserviceException('An error occurred during the image upload', [76, 400]); } elseif (!ImageManager::resize($tmpName, $this->imgToDisplay)) { throw new WebserviceException('An error occurred while copying image', [76, 400]); } $productPictureWidth = (int) Configuration::get('PS_PRODUCT_PICTURE_WIDTH'); $productPictureHeight = (int) Configuration::get('PS_PRODUCT_PICTURE_HEIGHT'); if (!ImageManager::resize($this->imgToDisplay, $this->imgToDisplay.'_small', $productPictureWidth, $productPictureHeight)) { throw new WebserviceException('An error occurred while resizing image', [76, 400]); } @unlink(_PS_TMP_IMG_DIR_.$tmpName); $query = 'INSERT INTO `'._DB_PREFIX_.'customized_data` (`id_customization`, `type`, `index`, `value`) VALUES ('.(int) $this->wsObject->urlSegment[3].', 0, '.(int) $this->wsObject->urlSegment[4].', \''.$filename.'\')'; if (!Db::getInstance()->execute($query)) { return false; } } return true; } } } else { throw new WebserviceException('Method '.$this->wsObject->method.' is not allowed for an image resource', [77, 405]); } } } ```
  10. Well looks like I will have to look into the webservice code after all. Just upgraded to 1.0.3 and the retina images are not created via the webservice image upload either. Will report what I find.
  11. I have to set quite a bit of folders to 775 on my host otherwise I get lot's of random 500 internal errors when using the back office and other functionalities because the www-data group cannot write otherwise.
  12. @mdekker did you finally include my code in the csv import section ? Just curious cause I am still running 1.0.2 (will upgrade to 1.0.3 soon I promise) and the retina 2x images are NOT created either via the webservice. I got it fixed for csv import but we are going to maintain our products via Filemaker Pro and I need to also import images using the webservice. I was being lazy and wanted to ask before looking up in the code, taking a chance that it had been fixed in 1.0.3 at the same time :grinning: If anyone is curious about how to upload an image to a product using the webservice, here's my php code: ``` <?php function addNewImage( $productid, $imagename ) { $url = 'https://yourthirtybeessite.com/api/images/products/' . $productid; $imagepath = 'img/'. $image_name; $key = 'YOURAPIKEY'; $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:multipart/form-data','Expect:')); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_USERPWD, $key.':'); curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => new CurlFile($image_path))); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); return $result; } echo("Uploading an image..."); echo(addNewImage(71,'cafe.jpg')); ?>```
  13. @dprophitjr said in Retina images! Please help!: @ssimard at the end of srcset, I see a space then 2x. That, to me, adds a %20 because linux doesn't like filenames with spaces in them like WinDoze will allow. Just wondering? My god i'm terribly sorry, I didn't see this reply until now. Actually you have to enclose the 2x into the filename string, not after.. Ex. On browsers without srcset support, the value of the src attribute will be used as the image src [default image]. On regular resolution displays, the 1x variant of the srcset will be used [1x image]. On displays with 2 device pixels per CSS pixel, the 2x variant of the srcset will be used [2x image]. Similarly, there is a 3x image, and a 4x image. See example here: The srcset Attribute
  14. Well nevermind I found it. PSLOCALELANGUAGE in the configuration table was set to english.. changed it for french since my site is not multilingual.
  15. Hi guys, might be a stupid question (I hope !) but I am unable to make french work with the Smarty date_format option on my server. I've read everything about having to 'setLocale' in PHP before using it but it does not work ? On my local setup (my OSX computer) it does work in french with the same ThirtyBees configs (french Canadian language pack with fr_CA locale code) without having to do anything. I have the following locales installed on my linux server: enUS.utf8, frCA.utf8 and fr_FR.utf8 but using the setLocale does not work, maybe I am doing it wrong ? I tried to do it in my controller's initContent and it was a no go. Please make me feel bad and prove me it was a simple fix ;-) Thanks ! P.S. I am parsing a podcast feed and want to format the dates..
  16. I think having language specific forums is a great idea for people that does not read/write english. French is my mother language personally but I will stick to english forums since I can. I will however answer french posts if possible. win/win situation
  17. I did the fix manually and it worked perfectly :-)
  18. Thanks a lot guys, I am loving this community already ;-)
  19. +1 to this since I am having the same issue. My store is french only and I now have the "fr" iso code in all my urls.. Previously the code would not show if there was only 1 language available.
  20. Oh well, turned the backup option off and everything worked as it should, doesn't matter much on my dev environment anyway. Will chime in again if I get errors on my live setup.
  21. Hi, I'm having an issue with the updater during the backup part of the installation. I'm getting [Ajax / Server Error for action backupFiles] textStatus: "error " errorThrown:"Internal Server Error " jqXHR: " ". PHP error log shows this (I am not sure it is related thou), any ideas ? Thanks. [24-Jul-2017 09:36:50 America/New_York] PHP Warning: sprintf(): Too few arguments in /Applications/XAMPP/xamppfiles/htdocs/tbquebecamerique/modules/tbupdater/classes/AjaxProcessor.php on line 317 [24-Jul-2017 09:37:06 America/New_York] PHP Fatal error: Class 'Context' not found in /Applications/XAMPP/xamppfiles/htdocs/tbquebecamerique/modules/tbupdater/classes/Tools.php on line 1420
  22. Awesome infos guys, thanks a lot, I will take a look at the webservice API ! jnsgioia yes, it is custom.
×
×
  • Create New...