/** * 取得一张图片的HTTP访问链接 * * @param $id_image * @param $type * @return bool|string */ public static function getImageLink($id_image, $type = "") { if (!$id_image) { return false; } $image = new Image((int) $id_image); if ($image->getExistingImgPath()) { if (empty($type)) { return _TM_PRO_URL . $image->getExistingImgPath() . '.jpg'; } return _TM_PRO_URL . $image->getExistingImgPath() . '-' . $type . '.jpg'; } }
public function reloadImages() { $dir = _TM_PRO_IMG_DIR; $productsImages = Image::getAllImages(); foreach ($productsImages as $k => $image) { $imageObj = new Image($image['id_image']); //echo $dir.$imageObj->getExistingImgPath().'.jpg'; if (file_exists($dir . $imageObj->getExistingImgPath() . '.jpg')) { if (!ImageCore::imageResize($dir . $imageObj->getExistingImgPath() . '.jpg', $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($this->name) . '.jpg', (int) $this->width, (int) $this->height)) { $errors = true; } } } }
public function displayForm($isMainTab = true) { global $currentIndex, $cookie; parent::displayForm(); $imagesTypes = ImageType::getImagesTypes(); $imageObj = new Image(Tools::getValue('id_image')); echo ' <script type="text/javascript" src="../js/cropper/prototype.js"></script> <script type="text/javascript" src="../js/cropper/scriptaculous.js"></script> <script type="text/javascript" src="../js/cropper/builder.js"></script> <script type="text/javascript" src="../js/cropper/dragdrop.js"></script> <script type="text/javascript" src="../js/cropper/cropper.js"></script> <script type="text/javascript" src="../js/cropper/loader.js"></script> <form enctype="multipart/form-data" method="post" action="' . $currentIndex . '&imageresize&token=' . Tools::getAdminToken('AdminCatalog' . (int) Tab::getIdFromClassName('AdminCatalog') . (int) $cookie->id_employee) . '"> <input type="hidden" name="id_product" value="' . Tools::getValue('id_product') . '" /> <input type="hidden" name="id_category" value="' . Tools::getValue('id_category') . '" /> <input type="hidden" name="saveandstay" value="' . Tools::getValue('submitAddAndStay') . '" /> <input type="hidden" name="conf" value="' . Tools::getValue('toconf') . '" /> <input type="hidden" name="imageresize" value="imageresize" /> <input type="hidden" name="id_image" value="' . Tools::getValue('id_image') . '" /> <fieldset> <legend><img src="../img/admin/picture.gif" />' . $this->l('Image resize') . '</legend> ' . $this->l('Using your mouse, define which area of the image is to be used for generating each type of thumbnail.') . ' <br /><br /> <img src="' . _THEME_PROD_DIR_ . $imageObj->getExistingImgPath() . '.jpg" id="testImage"> <label for="imageChoice">' . $this->l('Thumbnails format') . '</label> <div class="margin-form""> <select name="imageChoice" id="imageChoice">'; foreach ($imagesTypes as $type) { echo '<option value="../img/p/' . $imageObj->getExistingImgPath() . '.jpg|' . $type['width'] . '|' . $type['height'] . '|' . $type['id_image_type'] . '">' . $type['name'] . '</option>'; } echo ' </select> <input type="submit" class="button" style="margin-left : 40px;" name="resize" value="' . $this->l(' Save all ') . '" /> </div>'; foreach ($imagesTypes as $type) { echo ' <input type="hidden" name="' . $type['id_image_type'] . '_x1" id="' . $type['id_image_type'] . '_x1" value="0" /> <input type="hidden" name="' . $type['id_image_type'] . '_y1" id="' . $type['id_image_type'] . '_y1" value="0" /> <input type="hidden" name="' . $type['id_image_type'] . '_x2" id="' . $type['id_image_type'] . '_x2" value="0" /> <input type="hidden" name="' . $type['id_image_type'] . '_y2" id="' . $type['id_image_type'] . '_y2" value="0" />'; } echo ' </fieldset> </form>'; }
/** * Old legacy way to generate a thumbnail. * * Use it upon a new Image management system is available. * * @param $imageId * @param string $imageType * @param string $tableName * @param string $imageDir * @return string The HTML < img > tag */ public function getThumbnailForListing($imageId, $imageType = 'jpg', $tableName = 'product', $imageDir = 'p') { if ($tableName == 'product') { $image = new \Image($imageId); $path_to_image = _PS_IMG_DIR_ . $imageDir . '/' . $image->getExistingImgPath() . '.' . $imageType; } else { $path_to_image = _PS_IMG_DIR_ . $imageDir . '/' . $imageId . '.' . $imageType; } $thumbPath = \ImageManager::thumbnail($path_to_image, $tableName . '_mini_' . $imageId . '.' . $imageType, 45, $imageType); // because legacy uses relative path to reach a directory under root directory... $replacement = 'src="' . $this->legacyContext->getRootUrl(); $thumbPath = preg_replace('/src="(\\.\\.\\/)+/', $replacement, $thumbPath); return $thumbPath; }
function setItemBuys($id_order, $items) { if (count($items)) { $buys = array(); foreach ($items as $item) { $id_image = Product::getCover($item['id']); $image_url = ''; if (sizeof($id_image) > 0) { $image = new Image($id_image['id_image']); // get image full URL $image_url = _PS_BASE_URL_ . _THEME_PROD_DIR_ . $image->getExistingImgPath() . ".jpg"; } $sql = "INSERT INTO " . _DB_PREFIX_ . "neo_items_buys (id_product, id_neo_exchange, name, price, image, created_at, status)\n VALUES ('" . $item['id'] . "','" . $id_order . "','" . pSQL($item['name']) . "','" . $item['price'] . "','" . $image_url . "',now(),1)"; Db::getInstance()->executeS($sql); $sql = "UPDATE " . _DB_PREFIX_ . "stock_available SET quantity = quantity+(-1) WHERE id_product = '" . $item['id'] . "'"; Db::getInstance()->execute($sql); $buys[] = '<div style="vertical-align:top"><img style="float:left;margin-right:10px;border:1px solid rgb(204,204,204);height:79px" alt="' . $item['name'] . '" src="' . $image_url . '"/> ' . $item['name'] . '<br><br>' . $item['price'] . '</div>'; } return $buys; } else { return false; } }
private function displayCustomizedDatas(&$customizedDatas, &$product, &$currency, &$image, $tokenCatalog, &$stock) { if (!($order = $this->loadObject(true))) { return; } if (is_array($customizedDatas) and isset($customizedDatas[(int) $product['id_product']][(int) $product['id_product_attribute']])) { if ($image = new Image($image['id_image'])) { echo ' <tr> <td align="center">' . (isset($image->id_image) ? cacheImage(_PS_IMG_DIR_ . 'p/' . $image->getExistingImgPath() . '.jpg', 'product_mini_' . (int) $product['id_product'] . (isset($product['id_product_attribute']) ? '_' . (int) $product['id_product_attribute'] : '') . '.jpg', 45, 'jpg') : '--') . '</td> <td><a href="index.php?tab=AdminCatalog&id_product=' . $product['id_product'] . '&updateproduct&token=' . $tokenCatalog . '"> <span class="productName">' . $product['name'] . '</span>' . (isset($product['attributes']) ? '<br />' . $product['attributes'] : '') . '<br /> ' . ($product['reference'] ? $this->l('Ref:') . ' ' . $product['reference'] : '') . (($product['reference'] and $product['supplier_reference']) ? ' / ' . $product['supplier_reference'] : '') . '</a></td> <td align="center">' . Tools::displayPrice($product['price_wt'], $currency, false) . '</td> <td align="center" class="productQuantity">' . $product['customizationQuantityTotal'] . '</td> <td align="center" class="productQuantity">' . (int) $stock['quantity'] . '</td> <td align="right">' . Tools::displayPrice($product['total_customization_wt'], $currency, false) . '</td> </tr>'; } foreach ($customizedDatas[(int) $product['id_product']][(int) $product['id_product_attribute']] as $customization) { echo ' <tr> <td colspan="2">'; foreach ($customization['datas'] as $type => $datas) { if ($type == _CUSTOMIZE_FILE_) { $i = 0; echo '<ul style="margin: 0; padding: 0; list-style-type: none;">'; foreach ($datas as $data) { echo '<li style="display: inline; margin: 2px;"> <a href="displayImage.php?img=' . $data['value'] . '&name=' . (int) $order->id . '-file' . ++$i . '" target="_blank"><img src="' . _THEME_PROD_PIC_DIR_ . $data['value'] . '_small" alt="" /></a> </li>'; } echo '</ul>'; } elseif ($type == _CUSTOMIZE_TEXTFIELD_) { $i = 0; echo '<ul style="margin-bottom: 4px; padding: 0; list-style-type: none;">'; foreach ($datas as $data) { echo '<li>' . ($data['name'] ? $data['name'] : $this->l('Text #') . ++$i) . $this->l(':') . ' <b>' . $data['value'] . '</b></li>'; } echo '</ul>'; } } echo '</td> <td align="center"></td> <td align="center" class="productQuantity">' . $customization['quantity'] . '</td> <td align="center" class="productQuantity"></td> <td align="center"></td> </tr>'; } } }
public function ajaxProcessAddImage() { self::$currentIndex = 'index.php?tab=AdminProducts'; $allowedExtensions = array('jpeg', 'gif', 'png', 'jpg'); // max file size in bytes $uploader = new FileUploader($allowedExtensions, $this->max_image_size); $result = $uploader->handleUpload(); if (isset($result['success'])) { $obj = new Image((int) $result['success']['id_image']); // Associate image to shop from context $shops = Shop::getContextListShopID(); $obj->associateTo($shops); $json_shops = array(); foreach ($shops as $id_shop) { $json_shops[$id_shop] = true; } $json = array('name' => $result['success']['name'], 'status' => 'ok', 'id' => $obj->id, 'path' => $obj->getExistingImgPath(), 'position' => $obj->position, 'cover' => $obj->cover, 'shops' => $json_shops); @unlink(_PS_TMP_IMG_DIR_ . 'product_' . (int) $obj->id_product . '.jpg'); @unlink(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $obj->id_product . '_' . $this->context->shop->id . '.jpg'); die(Tools::jsonEncode($json)); } else { die(Tools::jsonEncode($result)); } }
public function hookwatermark($params) { global $smarty; $image = new Image($params['id_image']); $image->id_product = $params['id_product']; $file = _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '-watermark.jpg'; //first make a watermark image $return = $this->watermarkByImage(_PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '.jpg', dirname(__FILE__) . '/watermark.gif', $file, 23, 0, 0, 'right'); //go through file formats defined for watermark and resize them foreach ($this->imageTypes as $imageType) { $newFile = _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg'; if (!imageResize($file, $newFile, (int) $imageType['width'], (int) $imageType['height'])) { $return = false; } } return $return; }
public function hookActionWatermark($params) { $image = new Image($params['id_image']); $image->id_product = $params['id_product']; $file = _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '-watermark.jpg'; $str_shop = '-' . (int) $this->context->shop->id; if (Shop::getContext() != Shop::CONTEXT_SHOP || !Tools::file_exists_cache(dirname(__FILE__) . '/watermark' . $str_shop . '.gif')) { $str_shop = ''; } //first make a watermark image $return = $this->watermarkByImage(_PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '.jpg', dirname(__FILE__) . '/watermark' . $str_shop . '.gif', $file, 23, 0, 0, 'right'); //go through file formats defined for watermark and resize them foreach ($this->imageTypes as $imageType) { $newFile = _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg'; if (!ImageManager::resize($file, $newFile, (int) $imageType['width'], (int) $imageType['height'])) { $return = false; } } return $return; }
$imageAlt = stripslashes($slideTitle); if (empty($imageAlt)) { $imageAlt = "slide"; } if ($bgType == "image" && !empty($filename)) { $title .= " (" . $filename . ")"; } $postID = $slide->getID(); $tem_post_types = $slide->tem_post_types(); // print '<pre>'; // print_r(Tools::getvalue('id')); // print '</pre>'; $sdsrevsliderid = Tools::getvalue('id'); if (isset($sdsrevsliderid) && !empty($sdsrevsliderid)) { $RevSlider = new RevSlider(); $img_type_set = $RevSlider->GetSliderImgSettings($sdsrevsliderid); } if (!isset($img_type_set) && empty($img_type_set)) { $img_type_set = 'home_default'; } // start get image thumbnail $prdid_image = Product::getCover($postID); if (sizeof($prdid_image) > 0) { $prdimage = new Image($prdid_image['id_image']); $prdimage_url = _PS_BASE_URL_ . _THEME_PROD_DIR_ . $prdimage->getExistingImgPath() . "-" . $img_type_set . ".jpg"; } $urlImageForView = $prdimage_url; // end get image thumbnail // $urlEditSlide = UniteFunctionsWPRev::getUrlEditPost($postID); $urlEditSlide = 'index.php?controller=AdminProducts&id_product=' . $postID . '&updateproduct&token=' . Tools::getAdminTokenLite('AdminProducts'); $linkEdit = UniteFunctionsRev::getHtmlLink($urlEditSlide, $title, "", "", true);
public function viewDetails() { global $currentIndex, $cookie, $link; $irow = 0; if (!($order = $this->loadObject())) { return; } $customer = new Customer($order->id_customer); $customerStats = $customer->getStats(); $addressInvoice = new Address($order->id_address_invoice, (int) $cookie->id_lang); if (Validate::isLoadedObject($addressInvoice) and $addressInvoice->id_state) { $invoiceState = new State((int) $addressInvoice->id_state); } $addressDelivery = new Address($order->id_address_delivery, (int) $cookie->id_lang); if (Validate::isLoadedObject($addressDelivery) and $addressDelivery->id_state) { $deliveryState = new State((int) $addressDelivery->id_state); } $carrier = new Carrier($order->id_carrier); $history = $order->getHistory($cookie->id_lang); $products = $order->getProducts(); $customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart); Product::addCustomizationPrice($products, $customizedDatas); $discounts = $order->getDiscounts(); $messages = Message::getMessagesByOrderId($order->id, true); $states = OrderState::getOrderStates((int) $cookie->id_lang); $currency = new Currency($order->id_currency); $currentLanguage = new Language((int) $cookie->id_lang); $currentState = OrderHistory::getLastOrderState($order->id); $sources = ConnectionsSource::getOrderSources($order->id); $cart = Cart::getCartByOrderId($order->id); $row = array_shift($history); if ($prevOrder = Db::getInstance()->getValue('SELECT id_order FROM ' . _DB_PREFIX_ . 'orders WHERE id_order < ' . (int) $order->id . ' ORDER BY id_order DESC')) { $prevOrder = '<a href="' . $currentIndex . '&token=' . Tools::getValue('token') . '&vieworder&id_order=' . $prevOrder . '"><img style="width:24px;height:24px" src="../img/admin/arrow-left.png" /></a>'; } if ($nextOrder = Db::getInstance()->getValue('SELECT id_order FROM ' . _DB_PREFIX_ . 'orders WHERE id_order > ' . (int) $order->id . ' ORDER BY id_order ASC')) { $nextOrder = '<a href="' . $currentIndex . '&token=' . Tools::getValue('token') . '&vieworder&id_order=' . $nextOrder . '"><img style="width:24px;height:24px" src="../img/admin/arrow-right.png" /></a>'; } if ($order->total_paid != $order->total_paid_real) { echo '<center><span class="warning" style="font-size: 16px">' . $this->l('Warning:') . ' ' . Tools::displayPrice($order->total_paid_real, $currency, false) . ' ' . $this->l('paid instead of') . ' ' . Tools::displayPrice($order->total_paid, $currency, false) . ' !</span></center><div class="clear"><br /><br /></div>'; } // display bar code if module enabled $hook = Module::hookExec('invoice', array('id_order' => $order->id)); if ($hook !== false) { echo '<div style="float: right; margin: -40px 40px 10px 0;">'; echo $hook; echo '</div><br class="clear" />'; } // display order header echo ' <div style="float:left" style="width:440px">'; echo '<h2> ' . $prevOrder . ' ' . (Validate::isLoadedObject($customer) ? $customer->firstname . ' ' . $customer->lastname . ' - ' : '') . $this->l('Order #') . sprintf('%06d', $order->id) . ' ' . $nextOrder . ' </h2> <div style="width:429px"> ' . ((($currentState->invoice or $order->invoice_number) and count($products)) ? '<a href="pdf.php?id_order=' . $order->id . '&pdf"><img src="../img/admin/charged_ok.gif" alt="' . $this->l('View invoice') . '" /> ' . $this->l('View invoice') . '</a>' : '<img src="../img/admin/charged_ko.gif" alt="' . $this->l('No invoice') . '" /> ' . $this->l('No invoice')) . ' - ' . (($currentState->delivery or $order->delivery_number) ? '<a href="pdf.php?id_delivery=' . $order->delivery_number . '"><img src="../img/admin/delivery.gif" alt="' . $this->l('View delivery slip') . '" /> ' . $this->l('View delivery slip') . '</a>' : '<img src="../img/admin/delivery_ko.gif" alt="' . $this->l('No delivery slip') . '" /> ' . $this->l('No delivery slip')) . ' - <a href="javascript:window.print()"><img src="../img/admin/printer.gif" alt="' . $this->l('Print order') . '" title="' . $this->l('Print order') . '" /> ' . $this->l('Print page') . '</a> </div> <div class="clear"> </div>'; /* Display current status */ echo ' <table cellspacing="0" cellpadding="0" class="table" style="width: 429px"> <tr> <th>' . Tools::displayDate($row['date_add'], (int) $cookie->id_lang, true) . '</th> <th><img src="../img/os/' . $row['id_order_state'] . '.gif" /></th> <th>' . stripslashes($row['ostate_name']) . '</th> <th>' . (!empty($row['employee_lastname']) ? '(' . stripslashes(Tools::substr($row['employee_firstname'], 0, 1)) . '. ' . stripslashes($row['employee_lastname']) . ')' : '') . '</th> </tr>'; /* Display previous status */ foreach ($history as $row) { echo ' <tr class="' . ($irow++ % 2 ? 'alt_row' : '') . '"> <td>' . Tools::displayDate($row['date_add'], (int) $cookie->id_lang, true) . '</td> <td><img src="../img/os/' . $row['id_order_state'] . '.gif" /></td> <td>' . stripslashes($row['ostate_name']) . '</td> <td>' . (!empty($row['employee_lastname']) ? '(' . stripslashes(Tools::substr($row['employee_firstname'], 0, 1)) . '. ' . stripslashes($row['employee_lastname']) . ')' : '') . '</td> </tr>'; } echo ' </table> <br />'; /* Display status form */ echo ' <form action="' . $currentIndex . '&view' . $this->table . '&token=' . $this->token . '" method="post" style="text-align:center;"> <select name="id_order_state">'; $currentStateTab = $order->getCurrentStateFull($cookie->id_lang); foreach ($states as $state) { echo '<option value="' . $state['id_order_state'] . '"' . ($state['id_order_state'] == $currentStateTab['id_order_state'] ? ' selected="selected"' : '') . '>' . stripslashes($state['name']) . '</option>'; } echo ' </select> <input type="hidden" name="id_order" value="' . $order->id . '" /> <input type="submit" name="submitState" value="' . $this->l('Change') . '" class="button" /> </form>'; /* Display customer information */ if (Validate::isLoadedObject($customer)) { echo '<br /> <fieldset style="width: 400px"> <legend><img src="../img/admin/tab-customers.gif" /> ' . $this->l('Customer information') . '</legend> <span style="font-weight: bold; font-size: 14px;"><a href="?tab=AdminCustomers&id_customer=' . $customer->id . '&viewcustomer&token=' . Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $cookie->id_employee) . '"> ' . $customer->firstname . ' ' . $customer->lastname . '</a></span> (' . $this->l('#') . $customer->id . ')<br /> (<a href="mailto:' . $customer->email . '">' . $customer->email . '</a>)<br /><br />'; if ($customer->isGuest()) { echo ' ' . $this->l('This order has been placed by a') . ' <b>' . $this->l('guest') . '</b>'; if (!Customer::customerExists($customer->email)) { echo '<form method="POST" action="index.php?tab=AdminCustomers&id_customer=' . (int) $customer->id . '&token=' . Tools::getAdminTokenLite('AdminCustomers') . '"> <input type="hidden" name="id_lang" value="' . (int) $order->id_lang . '" /> <p class="center"><input class="button" type="submit" name="submitGuestToCustomer" value="' . $this->l('Transform to customer') . '" /></p> ' . $this->l('This feature will generate a random password and send an e-mail to the customer') . ' </form>'; } else { echo '<div><b style="color:red;">' . $this->l('A registered customer account exists with the same email address') . '</b></div>'; } } else { echo $this->l('Account registered:') . ' ' . Tools::displayDate($customer->date_add, (int) $cookie->id_lang, true) . '<br /> ' . $this->l('Valid orders placed:') . ' <b>' . $customerStats['nb_orders'] . '</b><br /> ' . $this->l('Total paid since registration:') . ' <b>' . Tools::displayPrice(Tools::ps_round(Tools::convertPrice($customerStats['total_orders'], $currency), 2), $currency, false) . '</b><br />'; } echo '</fieldset>'; } /* Display sources */ if (sizeof($sources)) { echo '<br /> <fieldset style="width: 400px;"><legend><img src="../img/admin/tab-stats.gif" /> ' . $this->l('Sources') . '</legend><ul ' . (sizeof($sources) > 3 ? 'style="height: 200px; overflow-y: scroll; width: 360px;"' : '') . '>'; foreach ($sources as $source) { echo '<li> ' . Tools::displayDate($source['date_add'], (int) $cookie->id_lang, true) . '<br /> <b>' . $this->l('From:') . '</b> <a href="' . $source['http_referer'] . '">' . preg_replace('/^www./', '', parse_url($source['http_referer'], PHP_URL_HOST)) . '</a><br /> <b>' . $this->l('To:') . '</b> ' . $source['request_uri'] . '<br /> ' . ($source['keywords'] ? '<b>' . $this->l('Keywords:') . '</b> ' . $source['keywords'] . '<br />' : '') . '<br /> </li>'; } echo '</ul></fieldset>'; } // display hook specified to this page : AdminOrder if (($hook = Module::hookExec('adminOrder', array('id_order' => $order->id))) !== false) { echo $hook; } echo ' </div> <div style="float: left; margin-left: 40px">'; /* Display invoice information */ echo '<fieldset style="width: 400px">'; if (($currentState->invoice or $order->invoice_number) and count($products)) { echo '<legend><a href="pdf.php?id_order=' . $order->id . '&pdf"><img src="../img/admin/charged_ok.gif" /> ' . $this->l('Invoice') . '</a></legend> <a href="pdf.php?id_order=' . $order->id . '&pdf">' . $this->l('Invoice #') . '<b>' . Configuration::get('PS_INVOICE_PREFIX', (int) $cookie->id_lang) . sprintf('%06d', $order->invoice_number) . '</b></a> <br />' . $this->l('Created on:') . ' ' . Tools::displayDate($order->invoice_date, (int) $cookie->id_lang, true); } else { echo '<legend><img src="../img/admin/charged_ko.gif" />' . $this->l('Invoice') . '</legend> ' . $this->l('No invoice yet.'); } echo '</fieldset><br />'; /* Display shipping infos */ echo ' <fieldset style="width:400px"> <legend><img src="../img/admin/delivery.gif" /> ' . $this->l('Shipping information') . '</legend> ' . $this->l('Total weight:') . ' <b>' . number_format($order->getTotalWeight(), 3) . ' ' . Configuration::get('PS_WEIGHT_UNIT') . '</b><br /> ' . $this->l('Carrier:') . ' <b>' . ($carrier->name == '0' ? Configuration::get('PS_SHOP_NAME') : $carrier->name) . '</b><br /> ' . (($currentState->delivery or $order->delivery_number) ? '<br /><a href="pdf.php?id_delivery=' . $order->delivery_number . '">' . $this->l('Delivery slip #') . '<b>' . Configuration::get('PS_DELIVERY_PREFIX', (int) $cookie->id_lang) . sprintf('%06d', $order->delivery_number) . '</b></a><br />' : ''); if ($order->shipping_number) { echo $this->l('Tracking number:') . ' <b>' . $order->shipping_number . '</b> ' . (!empty($carrier->url) ? '(<a href="' . str_replace('@', $order->shipping_number, $carrier->url) . '" target="_blank">' . $this->l('Track the shipment') . '</a>)' : ''); } /* Carrier module */ if ($carrier->is_module == 1) { $module = Module::getInstanceByName($carrier->external_module_name); if (method_exists($module, 'displayInfoByCart')) { echo call_user_func(array($module, 'displayInfoByCart'), $order->id_cart); } } /* Display shipping number field */ if ($carrier->url && $order->hasBeenShipped()) { echo ' <form action="' . $currentIndex . '&view' . $this->table . '&token=' . $this->token . '" method="post" style="margin-top:10px;"> <input type="text" name="shipping_number" value="' . $order->shipping_number . '" /> <input type="hidden" name="id_order" value="' . $order->id . '" /> <input type="submit" name="submitShippingNumber" value="' . $this->l('Set shipping number') . '" class="button" /> </form>'; } echo ' </fieldset>'; /* Display summary order */ echo ' <br /> <fieldset style="width: 400px"> <legend><img src="../img/admin/details.gif" /> ' . $this->l('Order details') . '</legend> <label>' . $this->l('Original cart:') . ' </label> <div style="margin: 2px 0 1em 190px;"><a href="?tab=AdminCarts&id_cart=' . $cart->id . '&viewcart&token=' . Tools::getAdminToken('AdminCarts' . (int) Tab::getIdFromClassName('AdminCarts') . (int) $cookie->id_employee) . '">' . $this->l('Cart #') . sprintf('%06d', $cart->id) . '</a></div> <label>' . $this->l('Payment mode:') . ' </label> <div style="margin: 2px 0 1em 190px;">' . Tools::substr($order->payment, 0, 32) . ' ' . ($order->module ? '(' . $order->module . ')' : '') . '</div> <div style="margin: 2px 0 1em 50px;"> <table class="table" width="300px;" cellspacing="0" cellpadding="0"> <tr><td width="150px;">' . $this->l('Products') . '</td><td align="right">' . Tools::displayPrice($order->getTotalProductsWithTaxes(), $currency, false) . '</td></tr> ' . ($order->total_discounts > 0 ? '<tr><td>' . $this->l('Discounts') . '</td><td align="right">-' . Tools::displayPrice($order->total_discounts, $currency, false) . '</td></tr>' : '') . ' ' . ($order->total_wrapping > 0 ? '<tr><td>' . $this->l('Wrapping') . '</td><td align="right">' . Tools::displayPrice($order->total_wrapping, $currency, false) . '</td></tr>' : '') . ' <tr><td>' . $this->l('Shipping') . '</td><td align="right">' . Tools::displayPrice($order->total_shipping, $currency, false) . '</td></tr> <tr style="font-size: 20px"><td>' . $this->l('Total') . '</td><td align="right">' . Tools::displayPrice($order->total_paid, $currency, false) . ($order->total_paid != $order->total_paid_real ? '<br /><font color="red">(' . $this->l('Paid:') . ' ' . Tools::displayPrice($order->total_paid_real, $currency, false, false) . ')</font>' : '') . '</td></tr> </table> </div> <div style="float: left; margin-right: 10px; margin-left: 42px;"> <span class="bold">' . $this->l('Recycled package:') . '</span> ' . ($order->recyclable ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />') . ' </div> <div style="float: left; margin-right: 10px;"> <span class="bold">' . $this->l('Gift wrapping:') . '</span> ' . ($order->gift ? '<img src="../img/admin/enabled.gif" /> </div> <div style="clear: left; margin: 0px 42px 0px 42px; padding-top: 2px;"> ' . (!empty($order->gift_message) ? '<div style="border: 1px dashed #999; padding: 5px; margin-top: 8px;"><b>' . $this->l('Message:') . '</b><br />' . nl2br2($order->gift_message) . '</div>' : '') : '<img src="../img/admin/disabled.gif" />') . ' </div> </fieldset>'; echo '</div> <div class="clear"> </div>'; /* Display adresses : delivery & invoice */ echo '<div class="clear"> </div> <div style="float: left"> <fieldset style="width: 400px;"> <legend><img src="../img/admin/delivery.gif" alt="' . $this->l('Shipping address') . '" />' . $this->l('Shipping address') . '</legend> <div style="float: right"> <a href="?tab=AdminAddresses&id_address=' . $addressDelivery->id . '&addaddress&realedit=1&id_order=' . $order->id . ($addressDelivery->id == $addressInvoice->id ? '&address_type=1' : '') . '&token=' . Tools::getAdminToken('AdminAddresses' . (int) Tab::getIdFromClassName('AdminAddresses') . (int) $cookie->id_employee) . '&back=' . urlencode($_SERVER['REQUEST_URI']) . '"><img src="../img/admin/edit.gif" /></a> <a href="http://maps.google.com/maps?f=q&hl=' . $currentLanguage->iso_code . '&geocode=&q=' . $addressDelivery->address1 . ' ' . $addressDelivery->postcode . ' ' . $addressDelivery->city . ($addressDelivery->id_state ? ' ' . $deliveryState->name : '') . '" target="_blank"><img src="../img/admin/google.gif" alt="" class="middle" /></a> </div> ' . $this->displayAddressDetail($addressDelivery) . (!empty($addressDelivery->other) ? '<hr />' . $addressDelivery->other . '<br />' : '') . '</fieldset> </div> <div style="float: left; margin-left: 40px"> <fieldset style="width: 400px;"> <legend><img src="../img/admin/invoice.gif" alt="' . $this->l('Invoice address') . '" />' . $this->l('Invoice address') . '</legend> <div style="float: right"><a href="?tab=AdminAddresses&id_address=' . $addressInvoice->id . '&addaddress&realedit=1&id_order=' . $order->id . ($addressDelivery->id == $addressInvoice->id ? '&address_type=2' : '') . '&back=' . urlencode($_SERVER['REQUEST_URI']) . '&token=' . Tools::getAdminToken('AdminAddresses' . (int) Tab::getIdFromClassName('AdminAddresses') . (int) $cookie->id_employee) . '"><img src="../img/admin/edit.gif" /></a></div> ' . $this->displayAddressDetail($addressInvoice) . (!empty($addressInvoice->other) ? '<hr />' . $addressInvoice->other . '<br />' : '') . '</fieldset> </div> <div class="clear"> </div>'; // List of products echo ' <a name="products"><br /></a> <form action="' . $currentIndex . '&submitCreditSlip&vieworder&token=' . $this->token . '" method="post" onsubmit="return orderDeleteProduct(\'' . $this->l('Cannot return this product') . '\', \'' . $this->l('Quantity to cancel is greater than quantity available') . '\');"> <input type="hidden" name="id_order" value="' . $order->id . '" /> <fieldset style="width: 868px; "> <legend><img src="../img/admin/cart.gif" alt="' . $this->l('Products') . '" />' . $this->l('Products') . '</legend> <div style="float:left;"> <table style="width: 868px;" cellspacing="0" cellpadding="0" class="table" id="orderProducts"> <tr> <th align="center" style="width: 60px"> </th> <th>' . $this->l('Product') . '</th> <th style="width: 80px; text-align: center">' . $this->l('UP') . ' <sup>*</sup></th> <th style="width: 20px; text-align: center">' . $this->l('Qty') . '</th> ' . ($order->hasBeenPaid() ? '<th style="width: 20px; text-align: center">' . $this->l('Refunded') . '</th>' : '') . ' ' . ($order->hasBeenDelivered() ? '<th style="width: 20px; text-align: center">' . $this->l('Returned') . '</th>' : '') . ' <th style="width: 30px; text-align: center">' . $this->l('Stock') . '</th> <th style="width: 90px; text-align: center">' . $this->l('Total') . ' <sup>*</sup></th> <th colspan="2" style="width: 120px;"><img src="../img/admin/delete.gif" alt="' . $this->l('Products') . '" /> ' . ($order->hasBeenDelivered() ? $this->l('Return') : ($order->hasBeenPaid() ? $this->l('Refund') : $this->l('Cancel'))) . '</th>'; echo ' </tr>'; $tokenCatalog = Tools::getAdminToken('AdminCatalog' . (int) Tab::getIdFromClassName('AdminCatalog') . (int) $cookie->id_employee); foreach ($products as $k => $product) { if ($order->getTaxCalculationMethod() == PS_TAX_EXC) { $product_price = $product['product_price'] + $product['ecotax']; } else { $product_price = $product['product_price_wt']; } $image = array(); if (isset($product['product_attribute_id']) and (int) $product['product_attribute_id']) { $image = Db::getInstance()->getRow(' SELECT id_image FROM ' . _DB_PREFIX_ . 'product_attribute_image WHERE id_product_attribute = ' . (int) $product['product_attribute_id']); } if (!isset($image['id_image']) or !$image['id_image']) { $image = Db::getInstance()->getRow(' SELECT id_image FROM ' . _DB_PREFIX_ . 'image WHERE id_product = ' . (int) $product['product_id'] . ' AND cover = 1'); } $stock = Db::getInstance()->getRow(' SELECT ' . ($product['product_attribute_id'] ? 'pa' : 'p') . '.quantity FROM ' . _DB_PREFIX_ . 'product p ' . ($product['product_attribute_id'] ? 'LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute pa ON p.id_product = pa.id_product' : '') . ' WHERE p.id_product = ' . (int) $product['product_id'] . ' ' . ($product['product_attribute_id'] ? 'AND pa.id_product_attribute = ' . (int) $product['product_attribute_id'] : '')); if (isset($image['id_image'])) { $target = _PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $product['product_id'] . (isset($product['product_attribute_id']) ? '_' . (int) $product['product_attribute_id'] : '') . '.jpg'; if (file_exists($target)) { $products[$k]['image_size'] = getimagesize($target); } } // Customization display $this->displayCustomizedDatas($customizedDatas, $product, $currency, $image, $tokenCatalog, $k); // Normal display if ($product['product_quantity'] > $product['customizationQuantityTotal']) { $quantity = $product['product_quantity'] - $product['customizationQuantityTotal']; $imageObj = new Image($image['id_image']); echo ' <tr' . ((isset($image['id_image']) and isset($products[$k]['image_size'])) ? ' height="' . ($products[$k]['image_size'][1] + 7) . '"' : '') . '> <td align="center">' . (isset($image['id_image']) ? cacheImage(_PS_IMG_DIR_ . 'p/' . $imageObj->getExistingImgPath() . '.jpg', 'product_mini_' . (int) $product['product_id'] . (isset($product['product_attribute_id']) ? '_' . (int) $product['product_attribute_id'] : '') . '.jpg', 45, 'jpg') : '--') . '</td> <td><a href="index.php?tab=AdminCatalog&id_product=' . $product['product_id'] . '&updateproduct&token=' . $tokenCatalog . '"> <span class="productName">' . $product['product_name'] . '</span><br /> ' . ($product['product_reference'] ? $this->l('Ref:') . ' ' . $product['product_reference'] . '<br />' : '') . ($product['product_supplier_reference'] ? $this->l('Ref Supplier:') . ' ' . $product['product_supplier_reference'] : '') . '</a></td> <td align="center">' . Tools::displayPrice($product_price, $currency, false) . '</td> <td align="center" class="productQuantity" ' . ($quantity > 1 ? 'style="font-weight:700;font-size:1.1em;color:red"' : '') . '>' . (int) $quantity . '</td> ' . ($order->hasBeenPaid() ? '<td align="center" class="productQuantity">' . (int) $product['product_quantity_refunded'] . '</td>' : '') . ' ' . ($order->hasBeenDelivered() ? '<td align="center" class="productQuantity">' . (int) $product['product_quantity_return'] . '</td>' : '') . ' <td align="center" class="productQuantity">' . (int) $stock['quantity'] . '</td> <td align="center">' . Tools::displayPrice(Tools::ps_round($product_price, 2) * ((int) $product['product_quantity'] - $product['customizationQuantityTotal']), $currency, false) . '</td> <td align="center" class="cancelCheck"> <input type="hidden" name="totalQtyReturn" id="totalQtyReturn" value="' . (int) $product['product_quantity_return'] . '" /> <input type="hidden" name="totalQty" id="totalQty" value="' . (int) $product['product_quantity'] . '" /> <input type="hidden" name="productName" id="productName" value="' . $product['product_name'] . '" />'; if ((!$order->hasBeenDelivered() or Configuration::get('PS_ORDER_RETURN')) and (int) $product['product_quantity_return'] < (int) $product['product_quantity']) { echo ' <input type="checkbox" name="id_order_detail[' . $k . ']" id="id_order_detail[' . $k . ']" value="' . $product['id_order_detail'] . '" onchange="setCancelQuantity(this, ' . (int) $product['id_order_detail'] . ', ' . (int) ($product['product_quantity_in_stock'] - $product['customizationQuantityTotal'] - $product['product_quantity_reinjected']) . ')" ' . ((int) ($product['product_quantity_return'] + $product['product_quantity_refunded']) >= (int) $product['product_quantity'] ? 'disabled="disabled" ' : '') . '/>'; } else { echo '--'; } echo ' </td> <td class="cancelQuantity">'; if ((int) ($product['product_quantity_return'] + $product['product_quantity_refunded']) >= (int) $product['product_quantity']) { echo '<input type="hidden" name="cancelQuantity[' . $k . ']" value="0" />'; } elseif (!$order->hasBeenDelivered() or Configuration::get('PS_ORDER_RETURN')) { echo ' <input type="text" id="cancelQuantity_' . (int) $product['id_order_detail'] . '" name="cancelQuantity[' . $k . ']" size="2" onclick="selectCheckbox(this);" value="" /> '; } echo $this->getCancelledProductNumber($order, $product) . ' </td> </tr>'; } } echo ' </table> <div style="float:left; width:280px; margin-top:15px;"><sup>*</sup> ' . $this->l('According to the group of this customer, prices are printed:') . ' ' . ($order->getTaxCalculationMethod() == PS_TAX_EXC ? $this->l('tax excluded.') : $this->l('tax included.')) . (!Configuration::get('PS_ORDER_RETURN') ? '<br /><br />' . $this->l('Merchandise returns are disabled') : '') . '</div>'; if (sizeof($discounts)) { echo ' <div style="float:right; width:280px; margin-top:15px;"> <table cellspacing="0" cellpadding="0" class="table" style="width:100%;"> <tr> <th><img src="../img/admin/coupon.gif" alt="' . $this->l('Discounts') . '" />' . $this->l('Discount name') . '</th> <th align="center" style="width: 100px">' . $this->l('Value') . '</th> </tr>'; foreach ($discounts as $discount) { echo ' <tr> <td>' . $discount['name'] . '</td> <td align="center">' . ($discount['value'] != 0.0 ? '- ' : '') . Tools::displayPrice($discount['value'], $currency, false) . '</td> </tr>'; } echo ' </table></div>'; } echo ' </div>'; // Cancel product echo ' <div style="clear:both; height:15px;"> </div> <div style="float: right; width: 160px;">'; if ($order->hasBeenDelivered() and Configuration::get('PS_ORDER_RETURN')) { echo ' <input type="checkbox" id="reinjectQuantities" name="reinjectQuantities" class="button" /> <label for="reinjectQuantities" style="float:none; font-weight:normal;">' . $this->l('Re-stock products') . '</label><br />'; } if (!$order->hasBeenDelivered() and $order->hasBeenPaid() or $order->hasBeenDelivered() and Configuration::get('PS_ORDER_RETURN')) { echo ' <input type="checkbox" id="generateCreditSlip" name="generateCreditSlip" class="button" onclick="toogleShippingCost(this)" /> <label for="generateCreditSlip" style="float:none; font-weight:normal;">' . $this->l('Generate a credit slip') . '</label><br /> <input type="checkbox" id="generateDiscount" name="generateDiscount" class="button" onclick="toogleShippingCost(this)" /> <label for="generateDiscount" style="float:none; font-weight:normal;">' . $this->l('Generate a voucher') . '</label><br /> <span id="spanShippingBack" style="display:none;"><input type="checkbox" id="shippingBack" name="shippingBack" class="button" /> <label for="shippingBack" style="float:none; font-weight:normal;">' . $this->l('Repay shipping costs') . '</label><br /></span>'; } if (!$order->hasBeenDelivered() or $order->hasBeenDelivered() and Configuration::get('PS_ORDER_RETURN')) { echo ' <div style="text-align:center; margin-top:5px;"><input type="submit" name="cancelProduct" value="' . ($order->hasBeenDelivered() ? $this->l('Return products') : ($order->hasBeenPaid() ? $this->l('Refund products') : $this->l('Cancel products'))) . '" class="button" style="margin-top:8px;" /></div>'; } echo ' </div>'; echo ' </fieldset> </form> <div class="clear" style="height:20px;"> </div>'; /* Display send a message to customer & returns/credit slip*/ $returns = OrderReturn::getOrdersReturn($order->id_customer, $order->id); $slips = OrderSlip::getOrdersSlip($order->id_customer, $order->id); echo ' <div style="float: left"> <form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '&token=' . $this->token . '" method="post" onsubmit="if (getE(\'visibility\').checked == true) return confirm(\'' . $this->l('Do you want to send this message to the customer?', __CLASS__, true, false) . '\');"> <fieldset style="width: 400px;"> <legend style="cursor: pointer;" onclick="$(\'#message\').slideToggle();$(\'#message_m\').slideToggle();return false"><img src="../img/admin/email_edit.gif" /> ' . $this->l('New message') . '</legend> <div id="message_m" style="display: ' . (Tools::getValue('message') ? 'none' : 'block') . '; overflow: auto; width: 400px;"> <a href="#" onclick="$(\'#message\').slideToggle();$(\'#message_m\').slideToggle();return false"><b>' . $this->l('Click here') . '</b> ' . $this->l('to add a comment or send a message to the customer') . '</a> </div> <div id="message" style="display: ' . (Tools::getValue('message') ? 'block' : 'none') . '"> <select name="order_message" id="order_message" onchange="orderOverwriteMessage(this, \'' . $this->l('Do you want to overwrite your existing message?') . '\')"> <option value="0" selected="selected">-- ' . $this->l('Choose a standard message') . ' --</option>'; $orderMessages = OrderMessage::getOrderMessages((int) $order->id_lang); foreach ($orderMessages as $orderMessage) { echo ' <option value="' . htmlentities($orderMessage['message'], ENT_COMPAT, 'UTF-8') . '">' . $orderMessage['name'] . '</option>'; } echo ' </select><br /><br /> <b>' . $this->l('Display to consumer?') . '</b> <input type="radio" name="visibility" id="visibility" value="0" /> ' . $this->l('Yes') . ' <input type="radio" name="visibility" value="1" checked="checked" /> ' . $this->l('No') . ' <p id="nbchars" style="display:inline;font-size:10px;color:#666;"></p><br /><br /> <textarea id="txt_msg" name="message" cols="50" rows="8" onKeyUp="var length = document.getElementById(\'txt_msg\').value.length; if (length > 600) length = \'600+\'; document.getElementById(\'nbchars\').innerHTML = \'' . $this->l('600 chars max') . ' (\' + length + \')\';">' . htmlentities(Tools::getValue('message'), ENT_COMPAT, 'UTF-8') . '</textarea><br /><br /> <input type="hidden" name="id_order" value="' . (int) $order->id . '" /> <input type="hidden" name="id_customer" value="' . (int) $order->id_customer . '" /> <input type="submit" class="button" name="submitMessage" value="' . $this->l('Send') . '" /> </div> </fieldset> </form>'; /* Display list of messages */ if (sizeof($messages)) { echo ' <br /> <fieldset style="width: 400px;"> <legend><img src="../img/admin/email.gif" /> ' . $this->l('Messages') . '</legend>'; foreach ($messages as $message) { echo '<div style="overflow:auto; width:400px;" ' . ($message['is_new_for_me'] ? 'class="new_message"' : '') . '>'; if ($message['is_new_for_me']) { echo '<a class="new_message" title="' . $this->l('Mark this message as \'viewed\'') . '" href="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '&token=' . $this->token . '&messageReaded=' . (int) $message['id_message'] . '"><img src="../img/admin/enabled.gif" alt="" /></a>'; } echo $this->l('At') . ' <i>' . Tools::displayDate($message['date_add'], (int) $cookie->id_lang, true); echo '</i> ' . $this->l('from') . ' <b>' . ($message['elastname'] ? $message['efirstname'] . ' ' . $message['elastname'] : $message['cfirstname'] . ' ' . $message['clastname']) . '</b>'; echo (int) $message['private'] == 1 ? '<span style="color:red; font-weight:bold;">' . $this->l('Private:') . '</span>' : ''; echo '<p>' . nl2br2($message['message']) . '</p>'; echo '</div>'; echo '<br />'; } echo '<p class="info">' . $this->l('When you read a message, please click on the green check.') . '</p>'; echo '</fieldset>'; } echo '</div>'; /* Display return product */ echo '<div style="float: left; margin-left: 40px"> <fieldset style="width: 400px;"> <legend><img src="../img/admin/return.gif" alt="' . $this->l('Merchandise returns') . '" />' . $this->l('Merchandise returns') . '</legend>'; if (!sizeof($returns)) { echo $this->l('No merchandise return for this order.'); } else { foreach ($returns as $return) { $state = new OrderReturnState($return['state']); echo '(' . Tools::displayDate($return['date_upd'], $cookie->id_lang) . ') : <b><a href="index.php?tab=AdminReturn&id_order_return=' . $return['id_order_return'] . '&updateorder_return&token=' . Tools::getAdminToken('AdminReturn' . (int) Tab::getIdFromClassName('AdminReturn') . (int) $cookie->id_employee) . '">' . $this->l('#') . sprintf('%06d', $return['id_order_return']) . '</a></b> - ' . $state->name[$cookie->id_lang] . '<br />'; } } echo '</fieldset>'; /* Display credit slip */ echo ' <br /> <fieldset style="width: 400px;"> <legend><img src="../img/admin/slip.gif" alt="' . $this->l('Credit slip') . '" />' . $this->l('Credit slip') . '</legend>'; if (!sizeof($slips)) { echo $this->l('No slip for this order.'); } else { foreach ($slips as $slip) { echo '(' . Tools::displayDate($slip['date_upd'], $cookie->id_lang) . ') : <b><a href="pdf.php?id_order_slip=' . $slip['id_order_slip'] . '">' . $this->l('#') . sprintf('%06d', $slip['id_order_slip']) . '</a></b><br />'; } } echo '</fieldset> </div>'; echo '<div class="clear"> </div>'; echo '<br /><br /><a href="' . $currentIndex . '&token=' . $this->token . '"><img src="../img/admin/arrow2.gif" /> ' . $this->l('Back to list') . '</a><br />'; }
<?php include_once '../../config/config.inc.php'; include_once '../../init.php'; //$this->instant_search = Tools::getValue('instantSearch'); //$this->ajax_search = Tools::getValue('ajaxSearch'); //parent::initContent(); $query = Tools::replaceAccentedChars(urldecode(Tools::getValue('q'))); $original_query = Tools::getValue('q'); $searchResults = Search::find((int) Tools::getValue('id_lang'), $query, 1, 10, 'position', 'desc', true); foreach ($searchResults as &$product) { //$product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']); $links = new Link(); $product['product_link'] = $links->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']); /** *Get product cover */ $tdgetpover = Product::getCover($product['id_product']); $cproduct_image = new Image($tdgetpover['id_image']); $cproductimg_url = $cproduct_image->getExistingImgPath() . '-small_default.jpg'; $product['ajaxsearchimage'] = $cproductimg_url; } die(Tools::jsonEncode($searchResults));
public function ajaxProcessaddProductImage() { self::$currentIndex = 'index.php?tab=AdminProducts'; $product = new Product((int) Tools::getValue('id_product')); $legends = Tools::getValue('legend'); if (!is_array($legends)) { $legends = (array) $legends; } if (!Validate::isLoadedObject($product)) { $files = array(); $files[0]['error'] = Tools::displayError('Cannot add image because product creation failed.'); } $image_uploader = new HelperImageUploader('file'); $image_uploader->setAcceptTypes(array('jpeg', 'gif', 'png', 'jpg'))->setMaxSize($this->max_image_size); $files = $image_uploader->process(); foreach ($files as &$file) { $image = new Image(); $image->id_product = (int) $product->id; $image->position = Image::getHighestPosition($product->id) + 1; foreach ($legends as $key => $legend) { if (!empty($legend)) { $image->legend[(int) $key] = $legend; } } if (!Image::getCover($image->id_product)) { $image->cover = 1; } else { $image->cover = 0; } if (($validate = $image->validateFieldsLang(false, true)) !== true) { $file['error'] = Tools::displayError($validate); } if (isset($file['error']) && (!is_numeric($file['error']) || $file['error'] != 0)) { continue; } if (!$image->add()) { $file['error'] = Tools::displayError('Error while creating additional image'); } else { if (!($new_path = $image->getPathForCreation())) { $file['error'] = Tools::displayError('An error occurred during new folder creation'); continue; } $error = 0; if (!ImageManager::resize($file['save_path'], $new_path . '.' . $image->image_format, null, null, 'jpg', false, $error)) { switch ($error) { case ImageManager::ERROR_FILE_NOT_EXIST: $file['error'] = Tools::displayError('An error occurred while copying image, the file does not exist anymore.'); break; case ImageManager::ERROR_FILE_WIDTH: $file['error'] = Tools::displayError('An error occurred while copying image, the file width is 0px.'); break; case ImageManager::ERROR_MEMORY_LIMIT: $file['error'] = Tools::displayError('An error occurred while copying image, check your memory limit.'); break; default: $file['error'] = Tools::displayError('An error occurred while copying image.'); break; } continue; } else { $imagesTypes = ImageType::getImagesTypes('products'); foreach ($imagesTypes as $imageType) { if (!ImageManager::resize($file['save_path'], $new_path . '-' . stripslashes($imageType['name']) . '.' . $image->image_format, $imageType['width'], $imageType['height'], $image->image_format)) { $file['error'] = Tools::displayError('An error occurred while copying image:') . ' ' . stripslashes($imageType['name']); continue; } } } unlink($file['save_path']); //Necesary to prevent hacking unset($file['save_path']); Hook::exec('actionWatermark', array('id_image' => $image->id, 'id_product' => $product->id)); if (!$image->update()) { $file['error'] = Tools::displayError('Error while updating status'); continue; } // Associate image to shop from context $shops = Shop::getContextListShopID(); $image->associateTo($shops); $json_shops = array(); foreach ($shops as $id_shop) { $json_shops[$id_shop] = true; } $file['status'] = 'ok'; $file['id'] = $image->id; $file['position'] = $image->position; $file['cover'] = $image->cover; $file['legend'] = $image->legend; $file['path'] = $image->getExistingImgPath(); $file['shops'] = $json_shops; @unlink(_PS_TMP_IMG_DIR_ . 'product_' . (int) $product->id . '.jpg'); @unlink(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $product->id . '_' . $this->context->shop->id . '.jpg'); } } die(Tools::jsonEncode(array($image_uploader->getName() => $files))); }
public function hookActionWatermark($params) { $image = new Image($params['id_image']); $image->id_product = $params['id_product']; $file = _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '-watermark.jpg'; $file_org = _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '.jpg'; $str_shop = '-' . (int) $this->context->shop->id; if (Shop::getContext() != Shop::CONTEXT_SHOP || !Tools::file_exists_cache(dirname(__FILE__) . '/watermark' . $str_shop . '.gif')) { $str_shop = ''; } //first make a watermark image $return = $this->watermarkByImage(_PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '.jpg', dirname(__FILE__) . '/watermark' . $str_shop . '.gif', $file, 23, 0, 0, 'right'); if (!Configuration::get('WATERMARK_HASH')) { Configuration::updateValue('WATERMARK_HASH', Tools::passwdGen(10)); } if (isset($params['image_type']) && is_array($params['image_type'])) { $this->imageTypes = array_intersect($this->imageTypes, $params['image_type']); } //go through file formats defined for watermark and resize them foreach ($this->imageTypes as $imageType) { $newFile = _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg'; if (!ImageManager::resize($file, $newFile, (int) $imageType['width'], (int) $imageType['height'])) { $return = false; } $new_file_org = _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '-' . Configuration::get('WATERMARK_HASH') . '.jpg'; if (!ImageManager::resize($file_org, $new_file_org, (int) $imageType['width'], (int) $imageType['height'])) { $return = false; } } return $return; }
private function getProductsInfo() { if ((int) $this->product_id < 1) { return false; } $sel_total_ordered = ''; $query_where_parts = array(); $id_shop = (int) $this->def_shop; if (!empty($this->shop_id) && (int) $this->shop_id != -1) { $query_where_parts[] = 'o.id_shop = ' . (int) $this->shop_id; $sel_total_ordered = ' AND id_shop = ' . (int) $this->shop_id; $id_shop = (int) $this->shop_id; } // Get product information $product_obj = new DbQuery(); $product_obj->select("\r\n\t\t\tp.id_product,\r\n\t\t\tpl.name,\r\n\t\t\tp.price AS default_price,\r\n\t\t\tp.wholesale_price AS default_wholesale_price,\r\n\t\t\tsa.quantity,\r\n\t\t\tp.reference AS sku,\r\n\t\t\tif (p.active = 1, 'Enabled', 'Disabled') AS active,\r\n\t\t\ti.id_image,\r\n\t\t\tps.price AS price,\r\n\t\t\tps.wholesale_price,\r\n\t\t\ts.name AS shop_name,\r\n\t\t\t(SELECT SUM(product_quantity) FROM " . _DB_PREFIX_ . 'order_detail WHERE product_id = p.id_product' . pSQL($sel_total_ordered) . ') AS total_ordered '); $product_obj->from('product', 'p'); $product_obj->leftJoin('product_lang', 'pl', 'pl.id_product = p.id_product AND pl.id_lang = ' . (int) $this->def_lang); $product_obj->leftJoin('image', 'i', 'i.id_product = p.id_product AND i.cover = 1'); $product_obj->leftJoin('stock_available', 'sa', 'p.id_product = sa.id_product AND sa.id_product_attribute = 0'); $product_obj->leftJoin('product_shop', 'ps', 'ps.id_product = p.id_product AND ps.id_shop = ' . (int) $id_shop); $product_obj->leftJoin('shop', 's', 's.id_shop = ' . (int) $id_shop); $product_obj->where('p.id_product = ' . (int) $this->product_id); $product_obj->groupBy('p.id_product'); $product_sql = $product_obj->build(); $product = Db::getInstance()->executeS($product_sql); $product = array_shift($product); if (!$product['total_ordered']) { $product['total_ordered'] = 0; } // Convert price if ($this->currency_code != $this->def_currency) { $product['price'] = $this->convertPrice($product['price'], $this->def_currency); $product['wholesale_price'] = $this->convertPrice($product['wholesale_price'], $this->def_currency); } // Form price $product['price'] = $this->displayPrice($product['price'], $this->currency_code, true); $product['wholesale_price'] = $this->displayPrice($product['wholesale_price'], $this->currency_code, true); // Get product images $id_image = $product['id_image']; $image_info = new Image($id_image); $home_type = 'home_'; $thickbox_type = 'thickbox_'; $default = 'default'; if (file_exists(_PS_PROD_IMG_DIR_ . $image_info->getExistingImgPath() . '-' . $home_type . $default . '.jpg')) { $product['id_image'] = _PS_BASE_URL_ . _THEME_PROD_DIR_ . $image_info->getExistingImgPath() . '-' . $home_type . $default . '.jpg'; } else { $product['id_image'] = ''; } if (file_exists(_PS_PROD_IMG_DIR_ . $image_info->getExistingImgPath() . '-' . $thickbox_type . $default . '.jpg')) { $product['id_image_large'] = _PS_BASE_URL_ . _THEME_PROD_DIR_ . $image_info->getExistingImgPath() . '-' . $thickbox_type . $default . '.jpg'; } else { $product['id_image_large'] = ''; } return $product; }
private function getPrestashopPreferences($post) { $customer_fields = Context::getContext()->customer->getFields(); $cart = Context::getContext()->cart; //Get shipment data $address_delivery = new Address((int) $cart->id_address_delivery); $shipments = array('receiver_address' => array('floor' => '-', 'zip_code' => $address_delivery->postcode, 'street_name' => $address_delivery->address1 . ' - ' . $address_delivery->address2 . ' - ' . $address_delivery->city . '/' . $address_delivery->country, 'apartment' => '-', 'street_number' => '-')); // Get costumer data $address_invoice = new Address((int) $cart->id_address_invoice); $phone = $address_invoice->phone; $phone .= $phone == '' ? '' : '|'; $phone .= $address_invoice->phone_mobile; $customer_data = array('first_name' => $customer_fields['firstname'], 'last_name' => $customer_fields['lastname'], 'email' => $customer_fields['email'], 'phone' => array('area_code' => '-', 'number' => $phone), 'address' => array('zip_code' => $address_invoice->postcode, 'street_name' => $address_invoice->address1 . ' - ' . $address_invoice->address2 . ' - ' . $address_invoice->city . '/' . $address_invoice->country, 'street_number' => '-'), 'identification' => array('number' => $post != null && array_key_exists('docNumber', $post) ? $post['docNumber'] : '', 'type' => $post != null && array_key_exists('docType', $post) ? $post['docType'] : '')); //items $image_url = ''; $products = $cart->getProducts(); $items = array(); $summary = ''; foreach ($products as $key => $product) { $image_url = ''; // get image URL if (!empty($product['id_image'])) { $image = new Image($product['id_image']); $image_url = _PS_BASE_URL_ . _THEME_PROD_DIR_ . $image->getExistingImgPath() . '.' . $image->image_format; } $item = array('id' => $product['id_product'], 'title' => $product['name'], 'description' => $product['description_short'], 'quantity' => $product['quantity'], 'unit_price' => $product['price_wt'], 'picture_url' => $image_url, 'category_id' => Configuration::get('MERCADOPAGO_CATEGORY')); if ($key == 0) { $summary .= $product['name']; } else { $summary .= ', ' . $product['name']; } $items[] = $item; } // include shipping cost $shipping_cost = (double) $cart->getOrderTotal(true, Cart::ONLY_SHIPPING); if ($shipping_cost > 0) { $item = array('title' => 'Shipping', 'description' => 'Shipping service used by store', 'quantity' => 1, 'unit_price' => $shipping_cost, 'category_id' => Configuration::get('MERCADOPAGO_CATEGORY')); $items[] = $item; } // include wrapping cost $wrapping_cost = (double) $cart->getOrderTotal(true, Cart::ONLY_WRAPPING); if ($wrapping_cost > 0) { $item = array('title' => 'Wrapping', 'description' => 'Wrapping service used by store', 'quantity' => 1, 'unit_price' => $wrapping_cost, 'category_id' => Configuration::get('MERCADOPAGO_CATEGORY')); $items[] = $item; } // include discounts $discounts = (double) $cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS); if ($discounts > 0) { $item = array('title' => 'Discount', 'description' => 'Discount provided by store', 'quantity' => 1, 'unit_price' => -$discounts, 'category_id' => Configuration::get('MERCADOPAGO_CATEGORY')); $items[] = $item; } $data = array('external_reference' => $cart->id, 'customer' => $customer_data, 'items' => $items, 'shipments' => $shipments); if (!$this->mercadopago->isTestUser()) { switch (Configuration::get('MERCADOPAGO_COUNTRY')) { case 'MLB': $data['sponsor_id'] = 178326379; break; case 'MLM': $data['sponsor_id'] = 187899553; break; case 'MLA': $data['sponsor_id'] = 187899872; break; case 'MCO': $data['sponsor_id'] = 187900060; break; case 'MLV': $data['sponsor_id'] = 187900246; break; case 'MLC': $data['sponsor_id'] = 187900485; break; } } if ($post != null) { $cart = Context::getContext()->cart; $data['reason'] = $summary; $data['amount'] = (double) number_format($cart->getOrderTotal(true, Cart::BOTH), 2, '.', ''); $data['payer_email'] = $customer_fields['email']; $data['notification_url'] = $this->link->getModuleLink('mercadopago', 'notification', array(), Configuration::get('PS_SSL_ENABLED'), null, null, false) . '?checkout=custom&'; // add only for creditcard if (array_key_exists('card_token_id', $post)) { $data['card_token_id'] = $post['card_token_id']; $data['installments'] = (int) $post['installments']; // add only it has issuer id if (array_key_exists('issuersOptions', $post)) { $data['card_issuer_id'] = (int) $post['issuersOptions']; } } $data['payment_method_id'] = $post['payment_method_id']; } else { $data['auto_return'] = Configuration::get('MERCADOPAGO_AUTO_RETURN') == 'approved' ? 'approved' : ''; $data['back_urls']['success'] = $this->link->getModuleLink('mercadopago', 'standardreturn', array(), Configuration::get('PS_SSL_ENABLED'), null, null, false); $data['back_urls']['failure'] = $this->link->getPageLink('order-opc', Configuration::get('PS_SSL_ENABLED'), null, null, false, null); $data['back_urls']['pending'] = $this->link->getModuleLink('mercadopago', 'standardreturn', array(), Configuration::get('PS_SSL_ENABLED'), null, null, false); $data['payment_methods']['excluded_payment_methods'] = $this->getExcludedPaymentMethods(); $data['payment_methods']['excluded_payment_types'] = array(); $data['payment_methods']['installments'] = (int) Configuration::get('MERCADOPAGO_INSTALLMENTS'); $data['notification_url'] = $this->link->getModuleLink('mercadopago', 'notification', array(), Configuration::get('PS_SSL_ENABLED'), null, null, false) . '?checkout=standard&'; // swap to payer index since customer is only for transparent $data['customer']['name'] = $data['customer']['first_name']; $data['customer']['surname'] = $data['customer']['last_name']; $data['payer'] = $data['customer']; unset($data['customer']); } return $data; }
public function hookUpdateOrderStatus($var1) { /* Configuration status is reached */ if ($var1['newOrderStatus']->id == Configuration::get('feedaty_status_request')) { /* Load the order */ $order = new Order($var1['id_order']); /* Gets all products on order */ $products = $order->getProducts(); $final_products = array(); /* For each product we get picture, id, name, url */ foreach ($products as $product) { $tmp = array(); $id_image = Product::getCover($product['product_id']); if (count($id_image) > 0) { $image = new Image($id_image['id_image']); $tmp['ImageUrl'] = _PS_BASE_URL_ . _THEME_PROD_DIR_ . $image->getExistingImgPath() . '.jpg'; } $tmp['Id'] = $product['product_id']; $tmp['Name'] = $product['product_name']; $tmp['Brand'] = ''; $link = new Link(); $tmp['Url'] = $link->getProductLink((int) $product['product_id']); $final_products[] = $tmp; } /* Gets information about customer who made the order */ $customer = new Customer((int) $order->id_customer); /* Retrive also order date, customer email, id order, prestashop version and plugin version */ $tmp_order = array(); $tmp_order['OrderId'] = $var1['id_order']; $tmp_order['OrderDate'] = $order->date_add; $tmp_order['CustomerEmail'] = $customer->email; $tmp_order['CustomerId'] = $customer->email; $tmp_order['Platform'] = 'PrestaShop ' . _PS_VERSION_ . ' / ' . $this->version; $tmp_order['Products'] = $final_products; $js_data = array(); $js_data['merchantCode'] = Configuration::get('feedaty_code'); $js_data['orders'][] = $tmp_order; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://' . 'www.zoorate.com/ws/feedatyapi.svc/SubmitOrders'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, '60'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, Tools::jsonEncode($js_data)); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Expect:')); curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_exec($ch); curl_close($ch); /* We don't need any responce, if worked ok so otherwise no problem */ } }
public function searchProductTable() { $result = BaseSearcher::doSearchProducts($this->searchtext, $this->idcate, $this->context->cookie->id_lang); if (!empty($result)) { $i = 0; foreach ($result as $product) { if ($i == (int) Configuration::get('TCS_INSTANT_LIMIT')) { break; } $newproduct = new Product((int) $product['id_product'], true, $this->context->cookie->id_lang); if (Validate::isLoadedObject($newproduct)) { //print_r($newproduct); $id_image = Product::getCover($newproduct->id); // get Image by id if (sizeof($id_image) > 0) { $image = new Image($id_image['id_image']); // get image full URL $image_url = _PS_BASE_URL_ . _THEME_PROD_DIR_ . $image->getExistingImgPath() . '.jpg'; } $link = new Link(); $productlink = $link->getProductLink($newproduct); ?> <div id="product-box"> <div class="thumbnail imagebo"> <?php if (Configuration::get('TCS_DISPLAY_IMAGE') == 1) { ?> <a href="<?php echo $productlink; ?> "> <img class="img-responsive p-box-img" src="<?php echo $image_url; ?> "> </a> <?php } ?> <div class="caption"> <?php if (Configuration::get('TCS_DISPLAY_NAME') == 1) { ?> <h3 class="product-name"> <a href="<?php echo $productlink; ?> "> <?php echo $newproduct->name; ?> </a></h3> <?php } ?> <?php if (Configuration::get('TCS_DISPLAY_REF') == 1) { ?> <h4 class="product-ref"> <?php echo $newproduct->reference; ?> </h4> <?php } ?> <?php if (Configuration::get('TCS_DISPLAY_SHORTDES') == 1) { ?> <p class="product-desc"> <?php echo $newproduct->description_short; ?> </p> <?php } ?> <?php if (Configuration::get('TCS_DISPLAY_MANU') == 1) { ?> <p class="product-man"> Manufacture: <span> <?php echo $newproduct->manufacturer_name; ?> </span> </p> <?php } if (Configuration::get('TCS_DISPLAY_SUP') == 1) { ?> <p class="product-sup"> Supplier: <span> <?php echo $newproduct->supplier_name; ?> </span> </p> <?php } ?> <?php if (Configuration::get('TCS_DISPLAY_PRICE') == 1) { ?> <p class="product-price"> <?php echo Tools::displayPrice($newproduct->price); ?> </p> <?php } ?> <?php if (Configuration::get('TCS_DISPLAY_CARTBTN') == 1) { ?> <p class="cart-box"><a data-minimal_quantity="1" data-id-product="<?php echo $newproduct->id; ?> " title="<?php echo $this->mod->l('Add to cart'); ?> " rel="nofollow" href="<?php echo $this->context->link->getPageLink('cart'); ?> ?qty=1&id_product=<?php echo $newproduct->id; ?> " class="button ajax_add_to_cart_button btn btn-default"> <span> <?php echo $this->mod->l('Add to cart'); ?> </span> </a></p> <?php } ?> </div> </div> </div> <?php } // } ++$i; } // print_r($result); exit; } else { echo '<div id="product-box"> No product found </div>'; exit; } }
/** * @deprecated 1.5.0 */ function deleteImage($id_item, $id_image = NULL) { Tools::displayAsDeprecated(); // Category if (!$id_image) { $path = _PS_CAT_IMG_DIR_; $table = 'category'; if (file_exists(_PS_TMP_IMG_DIR_ . $table . '_' . $id_item . '.jpg')) { unlink(_PS_TMP_IMG_DIR_ . $table . '_' . $id_item . '.jpg'); } if (!$id_image and file_exists($path . $id_item . '.jpg')) { unlink($path . $id_item . '.jpg'); } /* Auto-generated images */ $imagesTypes = ImageType::getImagesTypes(); foreach ($imagesTypes as $k => $imagesType) { if (file_exists($path . $id_item . '-' . $imagesType['name'] . '.jpg')) { unlink($path . $id_item . '-' . $imagesType['name'] . '.jpg'); } } } else { $path = _PS_PROD_IMG_DIR_; $table = 'product'; $image = new Image($id_image); $image->id_product = $id_item; if (file_exists($path . $image->getExistingImgPath() . '.jpg')) { unlink($path . $image->getExistingImgPath() . '.jpg'); } /* Auto-generated images */ $imagesTypes = ImageType::getImagesTypes(); foreach ($imagesTypes as $k => $imagesType) { if (file_exists($path . $image->getExistingImgPath() . '-' . $imagesType['name'] . '.jpg')) { unlink($path . $image->getExistingImgPath() . '-' . $imagesType['name'] . '.jpg'); } } } /* BO "mini" image */ if (file_exists(_PS_TMP_IMG_DIR_ . $table . '_mini_' . $id_item . '.jpg')) { unlink(_PS_TMP_IMG_DIR_ . $table . '_mini_' . $id_item . '.jpg'); } return true; }
/** * Write the posted image on disk * * @param string $sreceptionPath * @param int $destWidth * @param int $destHeight * @param array $imageTypes * @param string $parentPath * @return boolean */ protected function writePostedImageOnDisk($receptionPath, $destWidth = null, $destHeight = null, $imageTypes = null, $parentPath = null) { if ($this->wsObject->method == 'PUT') { if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) { $file = $_FILES['image']; if ($file['size'] > $this->imgMaxUploadSize) { throw new WebserviceException(sprintf('The image size is too large (maximum allowed is %d KB)', $this->imgMaxUploadSize / 1000), array(72, 400)); } // Get mime content type $mime_type = false; if (Tools::isCallable('finfo_open')) { $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME; $finfo = finfo_open($const); $mime_type = finfo_file($finfo, $file['tmp_name']); finfo_close($finfo); } elseif (Tools::isCallable('mime_content_type')) { $mime_type = mime_content_type($file['tmp_name']); } elseif (Tools::isCallable('exec')) { $mime_type = trim(exec('file -b --mime-type ' . escapeshellarg($file['tmp_name']))); } if (empty($mime_type) || $mime_type == 'regular file') { $mime_type = $file['type']; } if (($pos = strpos($mime_type, ';')) !== false) { $mime_type = substr($mime_type, 0, $pos); } // Check mime content type if (!$mime_type || !in_array($mime_type, $this->acceptedImgMimeTypes)) { throw new WebserviceException('This type of image format not recognized, allowed formats are: ' . implode('", "', $this->acceptedImgMimeTypes), array(73, 400)); } elseif ($file['error']) { throw new WebserviceException('Error while uploading image. Please change your server\'s settings', array(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', array(75, 400)); } 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', array(76, 400)); } } elseif ($this->wsObject->method == 'POST') { if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) { $file = $_FILES['image']; if ($file['size'] > $this->imgMaxUploadSize) { throw new WebserviceException(sprintf('The image size is too large (maximum allowed is %d KB)', $this->imgMaxUploadSize / 1000), array(72, 400)); } require_once _PS_ROOT_DIR_ . '/images.inc.php'; if ($error = ImageManager::validateUpload($file)) { throw new WebserviceException('Image upload error : ' . $error, array(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] . ' doesn\'t exists', array(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', array(76, 400)); } if (!Validate::isLoadedObject($product)) { throw new WebserviceException('Product ' . (int) $this->wsObject->urlSegment[2] . ' doesn\'t exists', array(76, 400)); } } // copy image if (!isset($file['tmp_name'])) { return false; } if ($error = ImageManager::validateUpload($file, $this->imgMaxUploadSize)) { throw new WebserviceException('Bad image : ' . $error, array(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', array(76, 400)); } elseif (!ImageManager::resize($tmpName, _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '.' . $image->image_format)) { throw new WebserviceException('An error occurred while copying image', array(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']); } } } @unlink($tmpName); $this->imgToDisplay = _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '.' . $image->image_format; $this->objOutput->setFieldsToDisplay('full'); $this->output = $this->objOutput->renderEntity($image, 1); $image_content = array('sqlId' => 'content', 'value' => base64_encode(file_get_contents($this->imgToDisplay)), 'encode' => 'base64'); $this->output .= $this->objOutput->objectRender->renderField($image_content); } elseif (in_array($this->imageType, array('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', array(76, 400)); } elseif (!ImageManager::resize($tmpName, $receptionPath)) { throw new WebserviceException('An error occurred while copying image', array(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']); } } @unlink(_PS_TMP_IMG_DIR_ . $tmpName); $this->imgToDisplay = $receptionPath; } return true; } } } else { throw new WebserviceException('Method ' . $this->wsObject->method . ' is not allowed for an image resource', array(77, 405)); } }
public function getTableMostViewed($date_from, $date_to) { $header = array(array('id' => 'image', 'title' => $this->l('Image'), 'class' => 'text-center'), array('id' => 'product', 'title' => $this->l('Product'), 'class' => 'text-center'), array('id' => 'views', 'title' => $this->l('Views'), 'class' => 'text-center'), array('id' => 'added_to_cart', 'title' => $this->l('Added to cart'), 'class' => 'text-center'), array('id' => 'purchased', 'title' => $this->l('Purchased'), 'class' => 'text-center'), array('id' => 'rate', 'title' => $this->l('Percentage'), 'class' => 'text-center')); if (Configuration::get('PS_STATSDATA_PAGESVIEWS')) { $products = $this->getTotalViewed($date_from, $date_to, (int) Configuration::get('DASHPRODUCT_NBR_SHOW_MOST_VIEWED')); $body = array(); if (is_array($products) && count($products)) { foreach ($products as $product) { $product_obj = new Product((int) $product['id_object'], true, $this->context->language->id); if (!Validate::isLoadedObject($product_obj)) { continue; } $img = ''; if (($row_image = Product::getCover($product_obj->id)) && $row_image['id_image']) { $image = new Image($row_image['id_image']); $path_to_image = _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '.' . $this->context->controller->imageType; $img = ImageManager::thumbnail($path_to_image, 'product_mini_' . $product_obj->id . '.' . $this->context->controller->imageType, 45, $this->context->controller->imageType); } $tr = array(); $tr[] = array('id' => 'product', 'value' => $img, 'class' => 'text-center'); $tr[] = array('id' => 'product', 'value' => Tools::htmlentitiesUTF8($product_obj->name) . '<br/>' . Tools::displayPrice(Product::getPriceStatic((int) $product_obj->id)), 'class' => 'text-center'); $tr[] = array('id' => 'views', 'value' => $product['counter'], 'class' => 'text-center'); $added_cart = $this->getTotalProductAddedCart($date_from, $date_to, (int) $product_obj->id); $tr[] = array('id' => 'added_to_cart', 'value' => $added_cart, 'class' => 'text-center'); $purchased = $this->getTotalProductPurchased($date_from, $date_to, (int) $product_obj->id); $tr[] = array('id' => 'purchased', 'value' => $this->getTotalProductPurchased($date_from, $date_to, (int) $product_obj->id), 'class' => 'text-center'); $tr[] = array('id' => 'rate', 'value' => $product['counter'] ? round(100 * $purchased / $product['counter'], 1) . '%' : '-', 'class' => 'text-center'); $body[] = $tr; } } } else { $body = '<div class="alert alert-info">' . $this->l('You must enable the "Save global page views" option from the "Data mining for statistics" module in order to display the most viewed products, or use the Google Analytics module.') . '</div>'; } return array('header' => $header, 'body' => $body); }
public function displayListContent($token = NULL) { /* Display results in a table * * align : determine value alignment * prefix : displayed before value * suffix : displayed after value * image : object image * icon : icon determined by values * active : allow to toggle status */ global $currentIndex, $cookie; $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $id_category = 1; // default categ $irow = 0; if ($this->_list and isset($this->fieldsDisplay['position'])) { $positions = array_map(create_function('$elem', 'return (int)($elem[\'position\']);'), $this->_list); sort($positions); } if ($this->_list) { $isCms = false; if (preg_match('/cms/Ui', $this->identifier)) { $isCms = true; } $keyToGet = 'id_' . ($isCms ? 'cms_' : '') . 'category' . (in_array($this->identifier, array('id_category', 'id_cms_category')) ? '_parent' : ''); foreach ($this->_list as $tr) { $id = $tr[$this->identifier]; echo '<tr' . (array_key_exists($this->identifier, $this->identifiersDnd) ? ' id="tr_' . (($id_category = (int) Tools::getValue('id_' . ($isCms ? 'cms_' : '') . 'category', '1')) ? $id_category : '') . '_' . $id . '_' . $tr['position'] . '"' : '') . ($irow++ % 2 ? ' class="alt_row"' : '') . ' ' . ((isset($tr['color']) and $this->colorOnBackground) ? 'style="background-color: ' . $tr['color'] . '"' : '') . '> <td class="center">'; if ($this->delete and (!isset($this->_listSkipDelete) or !in_array($id, $this->_listSkipDelete))) { echo '<input type="checkbox" name="' . $this->table . 'Box[]" value="' . $id . '" class="noborder" />'; } echo '</td>'; foreach ($this->fieldsDisplay as $key => $params) { $tmp = explode('!', $key); $key = isset($tmp[1]) ? $tmp[1] : $tmp[0]; echo ' <td ' . (isset($params['position']) ? ' id="td_' . (isset($id_category) and $id_category ? $id_category : 0) . '_' . $id . '"' : '') . ' class="' . ((!isset($this->noLink) or !$this->noLink) ? 'pointer' : '') . ((isset($params['position']) and $this->_orderBy == 'position') ? ' dragHandle' : '') . (isset($params['align']) ? ' ' . $params['align'] : '') . '" '; if (!isset($params['position']) and (!isset($this->noLink) or !$this->noLink)) { echo ' onclick="document.location = \'' . $currentIndex . '&' . $this->identifier . '=' . $id . ($this->view ? '&view' : '&update') . $this->table . '&token=' . ($token != NULL ? $token : $this->token) . '\'">' . (isset($params['prefix']) ? $params['prefix'] : ''); } else { echo '>'; } if (isset($params['active']) and isset($tr[$key])) { $this->_displayEnableLink($token, $id, $tr[$key], $params['active'], Tools::getValue('id_category'), Tools::getValue('id_product')); } elseif (isset($params['activeVisu']) and isset($tr[$key])) { echo '<img src="../img/admin/' . ($tr[$key] ? 'enabled.gif' : 'disabled.gif') . '" alt="' . ($tr[$key] ? $this->l('Enabled') : $this->l('Disabled')) . '" title="' . ($tr[$key] ? $this->l('Enabled') : $this->l('Disabled')) . '" />'; } elseif (isset($params['position'])) { if ($this->_orderBy == 'position' and $this->_orderWay != 'DESC') { echo '<a' . (!($tr[$key] != $positions[sizeof($positions) - 1]) ? ' style="display: none;"' : '') . ' href="' . $currentIndex . '&' . $keyToGet . '=' . (int) $id_category . '&' . $this->identifiersDnd[$this->identifier] . '=' . $id . ' &way=1&position=' . (int) ($tr['position'] + 1) . '&token=' . ($token != NULL ? $token : $this->token) . '"> <img src="../img/admin/' . ($this->_orderWay == 'ASC' ? 'down' : 'up') . '.gif" alt="' . $this->l('Down') . '" title="' . $this->l('Down') . '" /></a>'; echo '<a' . (!($tr[$key] != $positions[0]) ? ' style="display: none;"' : '') . ' href="' . $currentIndex . '&' . $keyToGet . '=' . (int) $id_category . '&' . $this->identifiersDnd[$this->identifier] . '=' . $id . ' &way=0&position=' . (int) ($tr['position'] - 1) . '&token=' . ($token != NULL ? $token : $this->token) . '"> <img src="../img/admin/' . ($this->_orderWay == 'ASC' ? 'up' : 'down') . '.gif" alt="' . $this->l('Up') . '" title="' . $this->l('Up') . '" /></a>'; } else { echo (int) ($tr[$key] + 1); } } elseif (isset($params['image'])) { // item_id is the product id in a product image context, else it is the image id. $item_id = isset($params['image_id']) ? $tr[$params['image_id']] : $id; // If it's a product image if (isset($tr['id_image'])) { $image = new Image((int) $tr['id_image']); $path_to_image = _PS_IMG_DIR_ . $params['image'] . '/' . $image->getExistingImgPath() . '.' . $this->imageType; } else { $path_to_image = _PS_IMG_DIR_ . $params['image'] . '/' . $item_id . (isset($tr['id_image']) ? '-' . (int) $tr['id_image'] : '') . '.' . $this->imageType; } echo cacheImage($path_to_image, $this->table . '_mini_' . $item_id . '.' . $this->imageType, 45, $this->imageType); } elseif (isset($params['icon']) and (isset($params['icon'][$tr[$key]]) or isset($params['icon']['default']))) { echo '<img src="../img/admin/' . (isset($params['icon'][$tr[$key]]) ? $params['icon'][$tr[$key]] : $params['icon']['default'] . '" alt="' . $tr[$key]) . '" title="' . $tr[$key] . '" />'; } elseif (isset($params['price'])) { echo Tools::displayPrice($tr[$key], isset($params['currency']) ? Currency::getCurrencyInstance((int) $tr['id_currency']) : $currency, false); } elseif (isset($params['float'])) { echo rtrim(rtrim($tr[$key], '0'), '.'); } elseif (isset($params['type']) and $params['type'] == 'date') { echo Tools::displayDate($tr[$key], (int) $cookie->id_lang); } elseif (isset($params['type']) and $params['type'] == 'datetime') { echo Tools::displayDate($tr[$key], (int) $cookie->id_lang, true); } elseif (isset($tr[$key])) { $echo = $key == 'price' ? round($tr[$key], 2) : isset($params['maxlength']) ? Tools::substr($tr[$key], 0, $params['maxlength']) . '...' : $tr[$key]; echo isset($params['callback']) ? call_user_func_array(array($this->className, $params['callback']), array($echo, $tr)) : $echo; } else { echo '--'; } echo (isset($params['suffix']) ? $params['suffix'] : '') . '</td>'; } if ($this->edit or $this->delete or $this->view and $this->view !== 'noActionColumn') { echo '<td class="center" style="white-space: nowrap;">'; if ($this->view) { $this->_displayViewLink($token, $id); } if ($this->edit) { $this->_displayEditLink($token, $id); } if ($this->delete and (!isset($this->_listSkipDelete) or !in_array($id, $this->_listSkipDelete))) { $this->_displayDeleteLink($token, $id); } if ($this->duplicate) { $this->_displayDuplicate($token, $id); } if ($this->allegro) { $this->_displayAllegroLink($id); } echo '</td>'; } echo '</tr>'; } } }
<?php /** * Created by PhpStorm. * User: larismendi * Date: 18/03/2015 * Time: 09:04 PM */ session_start(); require dirname(__FILE__) . '/../config/config.inc.php'; $json = array(); if ($_POST) { $pais = $_POST["pais"]; $plataforma = $_POST["plataforma"]; $tipo = $_POST["tipo"]; $titulo = $_POST["titulo"]; $sql = "SELECT\n ppl.id_product id,\n ppl.name,\n pps.price,\n pcl2.name status,\n sav.quantity\n FROM\n " . _DB_PREFIX_ . "category pc,\n " . _DB_PREFIX_ . "category_lang pcl2,\n " . _DB_PREFIX_ . "category_product pcp,\n " . _DB_PREFIX_ . "product_shop pps,\n " . _DB_PREFIX_ . "product_lang ppl,\n " . _DB_PREFIX_ . "stock_available sav\n WHERE\n pc.id_parent IN (SELECT id_category FROM " . _DB_PREFIX_ . "category_lang WHERE name LIKE '%" . $plataforma . "%')\n AND pcl2.id_category = pc.id_category\n AND pcl2.id_category = pcp.id_category\n AND pcp.id_category = pps.id_category_default\n AND pps.id_product = ppl.id_product\n AND sav.id_product = pps.id_product\n AND sav.quantity > 0\n AND ppl.name LIKE '%" . $titulo . "%'\n GROUP BY id\n ORDER BY ppl.name"; if ($results = Db::getInstance()->ExecuteS($sql)) { foreach ($results as $row) { $id_image = Product::getCover($row["id"]); $image_url = ''; if (sizeof($id_image) > 0) { $image = new Image($id_image['id_image']); // get image full URL $image_url = _PS_BASE_URL_ . _THEME_PROD_DIR_ . $image->getExistingImgPath() . ".jpg"; } $json[] = array('id' => $row["id"], 'sku' => $row["name"], 'label' => $row["name"], 'available' => $row["quantity"], 'price' => round($row["price"]), 'precio_usado' => $row['status'] == 'Usados' ? round($row["price"]) : 0, 'imagen' => $image_url); } } } echo json_encode($json);
public function hookHeader($params) { $shop_id = $this->getShopId(); $buttons_code = $this->client->getButtonsCode(); if (Configuration::get('ADDSHOPPERS_OPENGRAPH') == '1') { $this->context->smarty->assign('buttons_opengraph', $buttons_code['buttons']['open-graph']); } if (Configuration::get('ADDSHOPPERS_BUTTONS') == '1') { $this->context->smarty->assign('buttons_social', $buttons_code['buttons']['button2']); } $id_lang = (int) Tools::getValue('id_lang', (int) Configuration::get('PS_LANG_DEFAULT')); $this->context->smarty->assign(array('shop_id' => Tools::safeOutput($shop_id), 'default_account' => $shop_id == $this->client->getDefaultShopId(), 'social' => Tools::safeOutput(Configuration::get('ADDSHOPPERS_BUTTONS')), 'floating_buttons' => Tools::safeOutput(Configuration::get('ADDSHOPPERS_FLOATING_BUTTONS')), 'opengraph' => Tools::safeOutput(Configuration::get('ADDSHOPPERS_OPENGRAPH')), 'actual_url' => Tools::safeOutput($this->_getCurrentUrl()), 'absolute_base_url' => Tools::safeOutput($this->_getAbsoluteBaseUrl()), 'id_lang' => (int) $id_lang)); if (Tools::isSubmit('id_product')) { $product = new Product((int) Tools::getValue('id_product')); if (Validate::isLoadedObject($product)) { $currency = new Currency((int) $this->context->cookie->id_currency); $this->context->smarty->assign(array('id_product' => (int) $product->id, 'stock' => isset($product->available_now) ? Tools::safeOutput(AddshoppersClient::WIDGET_STOCK_IN_STOCK) : Tools::safeOutput(AddshoppersClient::WIDGET_STOCK_OUT_OF_STOCK), 'price' => Tools::safeOutput($currency->sign) . number_format((double) $product->getPrice(), 2), 'product_name' => Tools::safeOutput($product->name[$id_lang]), 'product_description' => Tools::safeOutput($product->description[$id_lang]), 'is_product_page' => true)); $quantity = (int) StockAvailable::getQuantityAvailableByProduct((int) $product->id); if ($quantity > 0) { $this->context->smarty->assign('instock', (int) $quantity); } $images = Image::getImages((int) $id_lang, (int) $product->id); $id_image = Product::getCover($product->id); // get Image by id if (sizeof($id_image) > 0) { $image = new Image($id_image['id_image']); // get image full URL $image_url = _PS_BASE_URL_ . _THEME_PROD_DIR_ . $image->getExistingImgPath() . ".jpg"; $this->context->smarty->assign('image_url', $image_url); } } else { $this->context->smarty->assign('is_product_page', false); } } else { $this->context->smarty->assign('is_product_page', false); } return $this->display(__FILE__, 'header.tpl'); }
public function renderView() { if (!($cart = $this->loadObject(true))) { return; } $customer = new Customer($cart->id_customer); $currency = new Currency($cart->id_currency); $this->context->cart = $cart; $this->context->currency = $currency; $this->context->customer = $customer; $this->toolbar_title = sprintf($this->l('Cart #%06d'), $this->context->cart->id); $products = $cart->getProducts(); $customized_datas = Product::getAllCustomizedDatas((int) $cart->id); Product::addCustomizationPrice($products, $customized_datas); $summary = $cart->getSummaryDetails(); /* Display order information */ $id_order = (int) Order::getOrderByCartId($cart->id); $order = new Order($id_order); if (Validate::isLoadedObject($order)) { $tax_calculation_method = $order->getTaxCalculationMethod(); $id_shop = (int) $order->id_shop; } else { $id_shop = (int) $cart->id_shop; $tax_calculation_method = Group::getPriceDisplayMethod(Group::getCurrent()->id); } if ($tax_calculation_method == PS_TAX_EXC) { $total_products = $summary['total_products']; $total_discounts = $summary['total_discounts_tax_exc']; $total_wrapping = $summary['total_wrapping_tax_exc']; $total_price = $summary['total_price_without_tax']; $total_shipping = $summary['total_shipping_tax_exc']; } else { $total_products = $summary['total_products_wt']; $total_discounts = $summary['total_discounts']; $total_wrapping = $summary['total_wrapping']; $total_price = $summary['total_price']; $total_shipping = $summary['total_shipping']; } foreach ($products as $k => &$product) { if ($tax_calculation_method == PS_TAX_EXC) { $product['product_price'] = $product['price']; $product['product_total'] = $product['total']; } else { $product['product_price'] = $product['price_wt']; $product['product_total'] = $product['total_wt']; } $image = array(); if (isset($product['id_product_attribute']) && (int) $product['id_product_attribute']) { $image = Db::getInstance()->getRow('SELECT id_image FROM ' . _DB_PREFIX_ . 'product_attribute_image WHERE id_product_attribute = ' . (int) $product['id_product_attribute']); } if (!isset($image['id_image'])) { $image = Db::getInstance()->getRow('SELECT id_image FROM ' . _DB_PREFIX_ . 'image WHERE id_product = ' . (int) $product['id_product'] . ' AND cover = 1'); } $product_obj = new Product($product['id_product']); $product['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct($product['id_product'], isset($product['id_product_attribute']) ? $product['id_product_attribute'] : null, (int) $id_shop); $image_product = new Image($image['id_image']); $product['image'] = isset($image['id_image']) ? ImageManager::thumbnail(_PS_IMG_DIR_ . 'p/' . $image_product->getExistingImgPath() . '.jpg', 'product_mini_' . (int) $product['id_product'] . (isset($product['id_product_attribute']) ? '_' . (int) $product['id_product_attribute'] : '') . '.jpg', 45, 'jpg') : '--'; } $helper = new HelperKpi(); $helper->id = 'box-kpi-cart'; $helper->icon = 'icon-shopping-cart'; $helper->color = 'color1'; $helper->title = $this->l('Total Cart', null, null, false); $helper->subtitle = sprintf($this->l('Cart #%06d', null, null, false), $cart->id); $helper->value = Tools::displayPrice($total_price, $currency); $kpi = $helper->generate(); $this->tpl_view_vars = array('kpi' => $kpi, 'products' => $products, 'discounts' => $cart->getCartRules(), 'order' => $order, 'cart' => $cart, 'currency' => $currency, 'customer' => $customer, 'customer_stats' => $customer->getStats(), 'total_products' => $total_products, 'total_discounts' => $total_discounts, 'total_wrapping' => $total_wrapping, 'total_price' => $total_price, 'total_shipping' => $total_shipping, 'customized_datas' => $customized_datas); return parent::renderView(); }
protected function _regenerateWatermark($dir, $type = null) { $result = Db::getInstance()->executeS(' SELECT m.`name` FROM `' . _DB_PREFIX_ . 'module` m LEFT JOIN `' . _DB_PREFIX_ . 'hook_module` hm ON hm.`id_module` = m.`id_module` LEFT JOIN `' . _DB_PREFIX_ . 'hook` h ON hm.`id_hook` = h.`id_hook` WHERE h.`name` = \'actionWatermark\' AND m.`active` = 1'); if ($result && count($result)) { $productsImages = Image::getAllImages(); foreach ($productsImages as $image) { $imageObj = new Image($image['id_image']); if (file_exists($dir . $imageObj->getExistingImgPath() . '.jpg')) { foreach ($result as $module) { $moduleInstance = Module::getInstanceByName($module['name']); if ($moduleInstance && is_callable(array($moduleInstance, 'hookActionWatermark'))) { call_user_func(array($moduleInstance, 'hookActionWatermark'), array('id_image' => $imageObj->id, 'id_product' => $imageObj->id_product, 'image_type' => $type)); } if (time() - $this->start_time > $this->max_execution_time - 4) { // stop 4 seconds before the tiemout, just enough time to process the end of the page on a slow server return 'timeout'; } } } } } }
/** * ONLY FOR DEVELOPMENT PURPOSE */ public function backupImageImage() { $types = array(); foreach (ImageType::getImagesTypes('products') as $type) { $types[] = $type['name']; } $backup_path = $this->img_path . 'p/'; $from_path = _PS_PROD_IMG_DIR_; if (!is_dir($backup_path) && !mkdir($backup_path)) { $this->setError(sprintf('Cannot create directory <i>%s</i>', $backup_path)); } foreach (Image::getAllImages() as $image) { $image = new Image($image['id_image']); $image_path = $image->getExistingImgPath(); if (file_exists($from_path . $image_path . '.' . $image->image_format)) { copy($from_path . $image_path . '.' . $image->image_format, $backup_path . $this->generateId('image', $image->id) . '.' . $image->image_format); } foreach ($types as $type) { if (file_exists($from_path . $image_path . '-' . $type . '.' . $image->image_format)) { copy($from_path . $image_path . '-' . $type . '.' . $image->image_format, $backup_path . $this->generateId('image', $image->id) . '-' . $type . '.' . $image->image_format); } } } }
function displayFormAttributes($obj, $languages, $defaultLanguage) { global $currentIndex, $cookie; $attributeJs = array(); $attributes = Attribute::getAttributes((int) $cookie->id_lang, true); foreach ($attributes as $k => $attribute) { $attributeJs[$attribute['id_attribute_group']][$attribute['id_attribute']] = $attribute['name']; } $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $attributes_groups = AttributeGroup::getAttributesGroups((int) $cookie->id_lang); $default_country = new Country((int) Configuration::get('PS_COUNTRY_DEFAULT')); $images = Image::getImages((int) $cookie->id_lang, $obj->id); if ($obj->id) { echo ' <script type="text/javascript"> $(document).ready(function(){ $(\'#id_mvt_reason\').change(function(){ updateMvtStatus($(this).val()); }); updateMvtStatus($(this).val()); }); </script> <table cellpadding="5"> <tr> <td colspan="2"><b>' . $this->l('Add or modify combinations for this product') . '</b> - <a href="index.php?tab=AdminCatalog&id_product=' . $obj->id . '&id_category=' . (int) Tools::getValue('id_category') . '&attributegenerator&token=' . Tools::getAdminToken('AdminCatalog' . (int) Tab::getIdFromClassName('AdminCatalog') . (int) $cookie->id_employee) . '" onclick="return confirm(\'' . $this->l('Are you sure you want to delete entered product information?', __CLASS__, true, false) . '\');"><img src="../img/admin/appearance.gif" alt="combinations_generator" class="middle" title="' . $this->l('Product combinations generator') . '" /> ' . $this->l('Product combinations generator') . '</a> </td> </tr> </table> <hr style="width:100%;" /><br /> <table cellpadding="5" style="width:100%"> <tr> <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;" valign="top">' . $this->l('Group:') . '</td> <td style="padding-bottom:5px;"><select name="attribute_group" id="attribute_group" style="width: 200px;" onchange="populate_attrs();">'; if (isset($attributes_groups)) { foreach ($attributes_groups as $k => $attribute_group) { if (isset($attributeJs[$attribute_group['id_attribute_group']])) { echo ' <option value="' . $attribute_group['id_attribute_group'] . '"> ' . htmlentities(stripslashes($attribute_group['name']), ENT_COMPAT, 'UTF-8') . ' </option>'; } } } echo ' </select></td> </tr> <tr> <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;" valign="top">' . $this->l('Attribute:') . '</td> <td style="padding-bottom:5px;"><select name="attribute" id="attribute" style="width: 200px;"> <option value="0">---</option> </select> <script type="text/javascript" language="javascript">populate_attrs();</script> </td> </tr> <tr> <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;" valign="top"> <input style="width: 140px; margin-bottom: 10px;" type="button" value="' . $this->l('Add') . '" class="button" onclick="add_attr();"/><br /> <input style="width: 140px;" type="button" value="' . $this->l('Delete') . '" class="button" onclick="del_attr()"/></td> <td align="left"> <select id="product_att_list" name="attribute_combinaison_list[]" multiple="multiple" size="4" style="width: 320px;"></select> </td> </tr> <tr><td colspan="2"><hr style="width:100%;" /></td></tr> <tr> <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Reference:') . '</td> <td style="padding-bottom:5px;"> <input size="55" type="text" id="attribute_reference" name="attribute_reference" value="" style="width: 130px; margin-right: 44px;" /> ' . $this->l('EAN13:') . '<input size="55" maxlength="13" type="text" id="attribute_ean13" name="attribute_ean13" value="" style="width: 110px; margin-left: 10px; margin-right: 44px;" /> ' . $this->l('UPC:') . '<input size="55" maxlength="12" type="text" id="attribute_upc" name="attribute_upc" value="" style="width: 110px; margin-left: 10px;" /> <span class="hint" name="help_box">' . $this->l('Special characters allowed:') . ' .-_#<span class="hint-pointer"> </span></span> </td> </tr> <tr> <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Supplier Reference:') . '</td> <td style="padding-bottom:5px;"> <input size="55" type="text" id="attribute_supplier_reference" name="attribute_supplier_reference" value="" style="width: 130px; margin-right: 44px;" /> ' . $this->l('Location:') . '<input size="55" type="text" id="attribute_location" name="attribute_location" value="" style="width: 101px; margin-left: 10px;" /> <span class="hint" name="help_box">' . $this->l('Special characters allowed:') . ' .-_#<span class="hint-pointer"> </span></span> </td> </tr> <tr><td colspan="2"><hr style="width:100%;" /></td></tr> <tr> <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Wholesale price:') . '</td> <td style="padding-bottom:5px;">' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . '<input type="text" size="6" name="attribute_wholesale_price" id="attribute_wholesale_price" value="0.00" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\');" />' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . ' (' . $this->l('overrides Wholesale price on Information tab') . ')</td> </tr> <tr> <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Impact on price:') . '</td> <td colspan="2" style="padding-bottom:5px;"> <select name="attribute_price_impact" id="attribute_price_impact" style="width: 140px;" onchange="check_impact(); calcImpactPriceTI();"> <option value="0">' . $this->l('None') . '</option> <option value="1">' . $this->l('Increase') . '</option> <option value="-1">' . $this->l('Reduction') . '</option> </select> <span id="span_impact"> ' . $this->l('of') . ' ' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . ' <input type="text" size="6" name="attribute_price" id="attribute_price" value="0.00" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\'); calcImpactPriceTI();"/>' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : ''); if ($default_country->display_tax_label) { echo ' ' . $this->l('(tax excl.)') . '<span ' . (Tax::excludeTaxeOption() ? 'style="display:none"' : '') . '> ' . $this->l('or') . ' ' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . ' <input type="text" size="6" name="attribute_priceTI" id="attribute_priceTI" value="0.00" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\'); calcImpactPriceTE();"/>' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . ' ' . $this->l('(tax incl.)') . '</span> ' . $this->l('final product price will be set to') . ' ' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . '<span id="attribute_new_total_price">0.00</span>' . ($currency->format % 2 == 0 ? $currency->sign . ' ' : ''); } echo ' </span> </td> </tr> <tr> <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Impact on weight:') . '</td> <td colspan="2" style="padding-bottom:5px;"><select name="attribute_weight_impact" id="attribute_weight_impact" style="width: 140px;" onchange="check_weight_impact();"> <option value="0">' . $this->l('None') . '</option> <option value="1">' . $this->l('Increase') . '</option> <option value="-1">' . $this->l('Reduction') . '</option> </select> <span id="span_weight_impact"> ' . $this->l('of') . ' <input type="text" size="6" name="attribute_weight" id="attribute_weight" value="0.00" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\');" /> ' . Configuration::get('PS_WEIGHT_UNIT') . '</span></td> </tr> <tr id="tr_unit_impact"> <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Impact on unit price :') . '</td> <td colspan="2" style="padding-bottom:5px;"><select name="attribute_unit_impact" id="attribute_unit_impact" style="width: 140px;" onchange="check_unit_impact();"> <option value="0">' . $this->l('None') . '</option> <option value="1">' . $this->l('Increase') . '</option> <option value="-1">' . $this->l('Reduction') . '</option> </select> <span id="span_unit_impact"> ' . $this->l('of') . ' ' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . ' <input type="text" size="6" name="attribute_unity" id="attribute_unity" value="0.00" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\');" />' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . ' / <span id="unity_third">' . $this->getFieldValue($obj, 'unity') . '</span> </span></td> </tr>'; if (Configuration::get('PS_USE_ECOTAX')) { echo ' <tr> <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;">' . $this->l('Eco-tax:') . '</td> <td style="padding-bottom:5px;">' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . '<input type="text" size="3" name="attribute_ecotax" id="attribute_ecotax" value="0.00" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\');" />' . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . ' (' . $this->l('overrides Eco-tax on Information tab') . ')</td> </tr>'; } echo ' <tr id="initial_stock_attribute"> <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;" class="col-left">' . $this->l('Initial stock:') . '</td> <td><input type="text" name="attribute_quantity" size="3" maxlength="10" value="0"/></td> </tr> </tr> <tr id="stock_mvt_attribute" style="display:none;"> <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;" class="col-left">' . $this->l('Stock movement:') . '</td> <td style="padding-bottom:5px;"> <select id="id_mvt_reason" name="id_mvt_reason"> <option value="-1">--</option>'; $reasons = StockMvtReason::getStockMvtReasons((int) $cookie->id_lang); foreach ($reasons as $reason) { echo '<option rel="' . $reason['sign'] . '" value="' . $reason['id_stock_mvt_reason'] . '" ' . (Configuration::get('PS_STOCK_MVT_REASON_DEFAULT') == $reason['id_stock_mvt_reason'] ? 'selected="selected"' : '') . '>' . $reason['name'] . '</option>'; } echo '</select> <input type="text" name="attribute_mvt_quantity" size="3" maxlength="10" value="0"/> <span style="display:none;" id="mvt_sign"></span> <br /> <div class="hint clear" style="display: block;width: 70%;">' . $this->l('Choose the reason and enter the quantity that you want to increase or decrease in your stock') . '</div> </td> </tr> <tr> <td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;" class="col-left">' . $this->l('Minimum quantity:') . '</td> <td style="padding-bottom:5px;"> <input size="3" maxlength="10" name="attribute_minimal_quantity" id="attribute_minimal_quantity" type="text" value="' . ($this->getFieldValue($obj, 'attribute_minimal_quantity') ? $this->getFieldValue($obj, 'attribute_minimal_quantity') : 1) . '" /> <p>' . $this->l('The minimum quantity to buy this product (set to 1 to disable this feature)') . '</p> </td> </tr> <tr style="display:none;" id="attr_qty_stock"> <td style="width:150px">' . $this->l('Quantity in stock:') . '</td> <td style="padding-bottom:5px;"><b><span style="display:none;" id="attribute_quantity"></span></b></td> </tr> <tr><td colspan="2"><hr style="width:100%;" /></td></tr> <tr> <td style="width:150px">' . $this->l('Image:') . '</td> <td style="padding-bottom:5px;"> <ul id="id_image_attr">'; $i = 0; $imageType = ImageType::getByNameNType('small', 'products'); $imageWidth = (isset($imageType['width']) ? (int) $imageType['width'] : 64) + 25; foreach ($images as $image) { $imageObj = new Image($image['id_image']); echo '<li style="float: left; width: ' . $imageWidth . 'px;"><input type="checkbox" name="id_image_attr[]" value="' . (int) $image['id_image'] . '" id="id_image_attr_' . (int) $image['id_image'] . '" /> <label for="id_image_attr_' . (int) $image['id_image'] . '" style="float: none;"><img src="' . _THEME_PROD_DIR_ . $imageObj->getExistingImgPath() . '-small.jpg" alt="' . htmlentities(stripslashes($image['legend']), ENT_COMPAT, 'UTF-8') . '" title="' . htmlentities(stripslashes($image['legend']), ENT_COMPAT, 'UTF-8') . '" /></label></li>'; ++$i; } echo '</ul> <img id="pic" alt="" title="" style="display: none; width: 100px; height: 100px; float: left; border: 1px dashed #BBB; margin-left: 20px;" /> </td> </tr> <tr> <td style="width:150px">' . $this->l('Default:') . '<br /><br /></td> <td style="padding-bottom:5px;"> <input type="checkbox" name="attribute_default" id="attribute_default" value="1" /> ' . $this->l('Make this the default combination for this product') . '<br /><br /> </td> </tr> <tr> <td style="width:150px"> </td> <td style="padding-bottom:5px;"> <span style="float: left;"><input type="submit" name="submitProductAttribute" id="submitProductAttribute" value="' . $this->l('Add this combination') . '" class="button" onclick="attr_selectall(); this.form.action += \'&addproduct&tabs=3\';" /> </span> <span id="ResetSpan" style="float: left; margin-left: 8px; display: none;"> <input type="reset" name="ResetBtn" id="ResetBtn" onclick="init_elems(); getE(\'submitProductAttribute\').value = \'' . $this->l('Add this attributes group', __CLASS__, true) . '\'; getE(\'id_product_attribute\').value = 0; $(\'#ResetSpan\').slideToggle();" class="button" value="' . $this->l('Cancel modification') . '" /></span><span class="clear"></span> </td> </tr> <tr><td colspan="2"><hr style="width:100%;" /></td></tr> <tr> <td colspan="2"> <br /> <table border="0" cellpadding="0" cellspacing="0" class="table"> <tr> <th>' . $this->l('Attributes') . '</th> <th>' . $this->l('Impact') . '</th> <th>' . $this->l('Weight') . '</th> <th>' . $this->l('Reference') . '</th> <th>' . $this->l('EAN13') . '</th> <th>' . $this->l('UPC') . '</th> <th class="center">' . $this->l('Quantity') . '</th> <th class="center">' . $this->l('Actions') . '</th> </tr>'; if ($obj->id) { /* Build attributes combinaisons */ $combinaisons = $obj->getAttributeCombinaisons((int) $cookie->id_lang); $groups = array(); if (is_array($combinaisons)) { $combinationImages = $obj->getCombinationImages((int) $cookie->id_lang); foreach ($combinaisons as $k => $combinaison) { $combArray[$combinaison['id_product_attribute']]['wholesale_price'] = $combinaison['wholesale_price']; $combArray[$combinaison['id_product_attribute']]['price'] = $combinaison['price']; $combArray[$combinaison['id_product_attribute']]['weight'] = $combinaison['weight']; $combArray[$combinaison['id_product_attribute']]['unit_impact'] = $combinaison['unit_price_impact']; $combArray[$combinaison['id_product_attribute']]['reference'] = $combinaison['reference']; $combArray[$combinaison['id_product_attribute']]['supplier_reference'] = $combinaison['supplier_reference']; $combArray[$combinaison['id_product_attribute']]['ean13'] = $combinaison['ean13']; $combArray[$combinaison['id_product_attribute']]['upc'] = $combinaison['upc']; $combArray[$combinaison['id_product_attribute']]['attribute_minimal_quantity'] = $combinaison['minimal_quantity']; $combArray[$combinaison['id_product_attribute']]['location'] = $combinaison['location']; $combArray[$combinaison['id_product_attribute']]['quantity'] = $combinaison['quantity']; $combArray[$combinaison['id_product_attribute']]['id_image'] = isset($combinationImages[$combinaison['id_product_attribute']][0]['id_image']) ? $combinationImages[$combinaison['id_product_attribute']][0]['id_image'] : 0; $combArray[$combinaison['id_product_attribute']]['default_on'] = $combinaison['default_on']; $combArray[$combinaison['id_product_attribute']]['ecotax'] = $combinaison['ecotax']; $combArray[$combinaison['id_product_attribute']]['attributes'][] = array($combinaison['group_name'], $combinaison['attribute_name'], $combinaison['id_attribute']); if ($combinaison['is_color_group']) { $groups[$combinaison['id_attribute_group']] = $combinaison['group_name']; } } } $irow = 0; if (isset($combArray)) { foreach ($combArray as $id_product_attribute => $product_attribute) { $list = ''; $jsList = ''; /* In order to keep the same attributes order */ asort($product_attribute['attributes']); foreach ($product_attribute['attributes'] as $attribute) { $list .= addslashes(htmlspecialchars($attribute[0])) . ' - ' . addslashes(htmlspecialchars($attribute[1])) . ', '; $jsList .= '\'' . addslashes(htmlspecialchars($attribute[0])) . ' : ' . addslashes(htmlspecialchars($attribute[1])) . '\', \'' . $attribute[2] . '\', '; } $list = rtrim($list, ', '); $jsList = rtrim($jsList, ', '); $attrImage = $product_attribute['id_image'] ? new Image($product_attribute['id_image']) : false; echo ' <tr' . ($irow++ % 2 ? ' class="alt_row"' : '') . ($product_attribute['default_on'] ? ' style="background-color:#D1EAEF"' : '') . '> <td>' . stripslashes($list) . '</td> <td class="right">' . ($currency->format % 2 != 0 ? $currency->sign . ' ' : '') . $product_attribute['price'] . ($currency->format % 2 == 0 ? ' ' . $currency->sign : '') . '</td> <td class="right">' . $product_attribute['weight'] . Configuration::get('PS_WEIGHT_UNIT') . '</td> <td class="right">' . $product_attribute['reference'] . '</td> <td class="right">' . $product_attribute['ean13'] . '</td> <td class="right">' . $product_attribute['upc'] . '</td> <td class="center">' . $product_attribute['quantity'] . '</td> <td class="center"> <a style="cursor: pointer;"> <img src="../img/admin/edit.gif" alt="' . $this->l('Modify this combination') . '" onclick="javascript:fillCombinaison(\'' . $product_attribute['wholesale_price'] . '\', \'' . $product_attribute['price'] . '\', \'' . $product_attribute['weight'] . '\', \'' . $product_attribute['unit_impact'] . '\', \'' . $product_attribute['reference'] . '\', \'' . $product_attribute['supplier_reference'] . '\', \'' . $product_attribute['ean13'] . '\', \'' . $product_attribute['quantity'] . '\', \'' . ($attrImage ? $attrImage->id : 0) . '\', Array(' . $jsList . '), \'' . $id_product_attribute . '\', \'' . $product_attribute['default_on'] . '\', \'' . $product_attribute['ecotax'] . '\', \'' . $product_attribute['location'] . '\', \'' . $product_attribute['upc'] . '\', \'' . $product_attribute['attribute_minimal_quantity'] . '\'); calcImpactPriceTI();" /></a> ' . (!$product_attribute['default_on'] ? '<a href="' . $currentIndex . '&defaultProductAttribute&id_product_attribute=' . $id_product_attribute . '&id_product=' . $obj->id . '&' . (Tools::isSubmit('id_category') ? 'id_category=' . (int) Tools::getValue('id_category') . '&' : '&') . 'token=' . Tools::getAdminToken('AdminCatalog' . (int) Tab::getIdFromClassName('AdminCatalog') . (int) $cookie->id_employee) . '"> <img src="../img/admin/asterisk.gif" alt="' . $this->l('Make this the default combination') . '" title="' . $this->l('Make this combination the default one') . '"></a>' : '') . ' <a href="' . $currentIndex . '&deleteProductAttribute&id_product_attribute=' . $id_product_attribute . '&id_product=' . $obj->id . '&' . (Tools::isSubmit('id_category') ? 'id_category=' . (int) Tools::getValue('id_category') . '&' : '&') . 'token=' . Tools::getAdminToken('AdminCatalog' . (int) Tab::getIdFromClassName('AdminCatalog') . (int) $cookie->id_employee) . '" onclick="return confirm(\'' . $this->l('Are you sure?', __CLASS__, true, false) . '\');"> <img src="../img/admin/delete.gif" alt="' . $this->l('Delete this combination') . '" /></a></td> </tr>'; } echo '<tr><td colspan="7" align="center"><a href="' . $currentIndex . '&deleteAllProductAttributes&id_product=' . $obj->id . '&token=' . Tools::getAdminToken('AdminCatalog' . (int) Tab::getIdFromClassName('AdminCatalog') . (int) $cookie->id_employee) . '" onclick="return confirm(\'' . $this->l('Are you sure?', __CLASS__, true, false) . '\');"><img src="../img/admin/delete.gif" alt="' . $this->l('Delete this combination') . '" /> ' . $this->l('Delete all combinations') . '</a></td></tr>'; } else { echo '<tr><td colspan="7" align="center"><i>' . $this->l('No combination yet') . '.</i></td></tr>'; } } echo ' </table> <br />' . $this->l('The row in blue is the default combination.') . ' <br /> ' . $this->l('A default combination must be designated for each product.') . ' </td> </tr> </table> <script type="text/javascript"> var impact = getE(\'attribute_price_impact\'); var impact2 = getE(\'attribute_weight_impact\'); var s_attr_group = document.getElementById(\'span_new_group\'); var s_attr_name = document.getElementById(\'span_new_attr\'); var s_impact = document.getElementById(\'span_impact\'); var s_impact2 = document.getElementById(\'span_weight_impact\'); init_elems(); </script> <hr style="width:100%;" /> <table cellpadding="5"> <tr> <td class="col-left"><b>' . $this->l('Color picker:') . '</b></td> <td style="padding-bottom:5px;"> <select name="id_color_default"> <option value="0">' . $this->l('Do not display') . '</option>'; foreach ($attributes_groups as $k => $attribute_group) { if (isset($groups[$attribute_group['id_attribute_group']])) { echo '<option value="' . (int) $attribute_group['id_attribute_group'] . '" ' . ((int) $attribute_group['id_attribute_group'] == (int) $obj->id_color_default ? 'selected="selected"' : '') . '>' . htmlentities(stripslashes($attribute_group['name']), ENT_COMPAT, 'UTF-8') . '</option>'; } } echo ' </select> <input type="submit" value="' . $this->l('OK') . '" name="submitAdd' . $this->table . 'AndStay" class="button" /> <a href="index.php?tab=AdminAttributesGroups&token=' . Tools::getAdminToken('AdminAttributesGroups' . (int) Tab::getIdFromClassName('AdminAttributesGroups') . (int) $cookie->id_employee) . '" onclick="return confirm(\'' . $this->l('Are you sure you want to delete entered product information?', __CLASS__, true, false) . '\');"><img src="../img/admin/asterisk.gif" alt="" /> ' . $this->l('Color attribute management') . '</a> <p >' . $this->l('Activate the color choice by selecting a color attribute group.') . '</p> </td> </tr> </table>'; } else { echo '<b>' . $this->l('You must save this product before adding combinations') . '.</b>'; } }
/** * Copy images from a product to another * * @param integer $id_product_old Source product ID * @param boolean $id_product_new Destination product ID */ public static function duplicateProductImages($id_product_old, $id_product_new, $combination_images) { $images_types = ImageType::getImagesTypes('products'); $result = Db::getInstance()->executeS(' SELECT `id_image` FROM `' . _DB_PREFIX_ . 'image` WHERE `id_product` = ' . (int) $id_product_old); foreach ($result as $row) { $image_old = new Image($row['id_image']); $image_new = clone $image_old; unset($image_new->id); $image_new->id_product = (int) $id_product_new; // A new id is generated for the cloned image when calling add() if ($image_new->add()) { $new_path = $image_new->getPathForCreation(); foreach ($images_types as $image_type) { if (file_exists(_PS_PROD_IMG_DIR_ . $image_old->getExistingImgPath() . '-' . $image_type['name'] . '.jpg')) { if (!Configuration::get('PS_LEGACY_IMAGES')) { $image_new->createImgFolder(); } copy(_PS_PROD_IMG_DIR_ . $image_old->getExistingImgPath() . '-' . $image_type['name'] . '.jpg', $new_path . '-' . $image_type['name'] . '.jpg'); } } if (file_exists(_PS_PROD_IMG_DIR_ . $image_old->getExistingImgPath() . '.jpg')) { copy(_PS_PROD_IMG_DIR_ . $image_old->getExistingImgPath() . '.jpg', $new_path . '.jpg'); } Image::replaceAttributeImageAssociationId($combination_images, (int) $image_old->id, (int) $image_new->id); // Duplicate shop associations for images $image_new->duplicateShops($id_product_old); } else { return false; } } return Image::duplicateAttributeImageAssociations($combination_images); }
public static function buildXML() { global $country_infos; $context = Context::getContext(); $country_infos = array('id_group' => 0, 'id_tax' => 1); $html = '<products>' . "\n"; /* First line, columns */ $columns = array('id', 'name', 'smallimage', 'bigimage', 'producturl', 'description', 'price', 'retailprice', 'discount', 'recommendable', 'instock'); /* Setting parameters */ $conf = Configuration::getMultiple(array('PS_REWRITING_SETTINGS', 'PS_LANG_DEFAULT', 'PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT', 'PS_COUNTRY_DEFAULT', 'PS_SHOP_NAME', 'PS_CURRENCY_DEFAULT', 'PS_CARRIER_DEFAULT')); /* Searching for products */ $result = Db::getInstance()->executeS(' SELECT DISTINCT p.`id_product`, i.`id_image` FROM `' . _DB_PREFIX_ . 'product` p JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.id_product = p.id_product) LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.id_product = p.id_product) WHERE p.`active` = 1 AND i.id_image IS NOT NULL GROUP BY p.id_product'); foreach ($result as $k => $row) { if (Pack::isPack(intval($row['id_product']))) { continue; } $product = new Product(intval($row['id_product']), true); if (Validate::isLoadedObject($product)) { $imageObj = new Image($row['id_image']); $imageObj->id_product = intval($product->id); $line = array(); $line[] = $product->manufacturer_name . ' - ' . $product->name[intval($conf['PS_LANG_DEFAULT'])]; $line[] = Tools::getProtocol() . $_SERVER['HTTP_HOST'] . _THEME_PROD_DIR_ . $imageObj->getExistingImgPath() . '-small.jpg'; $line[] = Tools::getProtocol() . $_SERVER['HTTP_HOST'] . _THEME_PROD_DIR_ . $imageObj->getExistingImgPath() . '-thickbox.jpg'; $line[] = $context->link->getProductLink(intval($product->id), $product->link_rewrite[intval($conf['PS_LANG_DEFAULT'])], $product->ean13) . '&utm_source=criteo&aff=criteo'; $line[] = str_replace(array("\n", "\r", "\t", '|'), '', strip_tags(html_entity_decode($product->description_short[intval($conf['PS_LANG_DEFAULT'])], ENT_COMPAT, 'UTF-8'))); $price = $product->getPrice(true, intval(Product::getDefaultAttribute($product->id))); $line[] = number_format($price, 2, '.', ''); $line[] = number_format($product->getPrice(true, intval(Product::getDefaultAttribute(intval($product->id))), 6, NULL, false, false), 2, '.', ''); $line[] = $product->getPrice(true, NULL, 2, NULL, true); $line[] = '1'; $line[] = '1'; $cptXML = 1; $html .= "\t" . '<product id="' . $product->id . '">' . "\n"; foreach ($line as $column) { $html .= "\t\t" . '<' . $columns[$cptXML] . '>' . $column . '</' . $columns[$cptXML] . '>' . "\n"; $cptXML++; } $html .= "\t" . '</product>' . "\n"; } } $html .= '</products>' . "\n"; echo $html; }