protected static function generateImageLink($product, $ps_product, $id_lang, $iso_code) { $link = new Link(); $cover = Image::getCover($ps_product->id); $product->{"image_link_small_{$iso_code}"} = $link->getImageLink($ps_product->link_rewrite[$id_lang], $cover["id_image"], ImageType::getFormatedName("small")); $product->{"image_link_large_{$iso_code}"} = $link->getImageLink($ps_product->link_rewrite[$id_lang], $cover["id_image"], ImageType::getFormatedName("large")); return $product; }
protected function formatProduct($id_product, $id_lang) { $link = new Link(); $product = new Product($id_product, true, $id_lang); $category = new Category($product->id_category_default, $id_lang); $product->objectID = $product->id; $product->category = $category->name; $product->url = $link->getProductLink($product->id); /* Cover */ $cover = Image::getCover($product->id); $product->image_link_small = $link->getImageLink($product->link_rewrite, $cover['id_image'], ImageType::getFormatedName('small')); $product->image_link_large = $link->getImageLink($product->link_rewrite, $cover['id_image'], ImageType::getFormatedName('large')); return $product; }
public function renderList($id_wishlist) { $wishlist = new WishList($id_wishlist); $products = WishList::getProductByIdCustomer($id_wishlist, $wishlist->id_customer, $this->context->language->id); foreach ($products as $key => $val) { $image = Image::getCover($val['id_product']); $products[$key]['image'] = $this->context->link->getImageLink($val['link_rewrite'], $image['id_image'], ImageType::getFormatedName('small')); } $fields_list = array('image' => array('title' => $this->l('Image'), 'type' => 'image'), 'name' => array('title' => $this->l('Product'), 'type' => 'text'), 'attributes_small' => array('title' => $this->l('Combination'), 'type' => 'text'), 'quantity' => array('title' => $this->l('Quantity'), 'type' => 'text'), 'priority' => array('title' => $this->l('Priority'), 'type' => 'priority', 'values' => array($this->l('High'), $this->l('Medium'), $this->l('Low')))); $helper = new HelperList(); $helper->shopLinkType = ''; $helper->simple_header = true; $helper->no_link = true; $helper->actions = array('view'); $helper->show_toolbar = false; $helper->module = $this; $helper->identifier = 'id_product'; $helper->title = $this->l('Product list'); $helper->table = $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name; $helper->tpl_vars = array('priority' => array($this->l('High'), $this->l('Medium'), $this->l('Low'))); return $helper->generateList($products, $fields_list); }
public function save() { $product = new Product($_GET['id_product']); if (!Validate::isLoadedObject($product)) { return array('error' => Tools::displayError('Cannot add image because product creation failed.')); } else { $image = new Image(); $image->id_product = (int) $product->id; $image->position = Image::getHighestPosition($product->id) + 1; $legends = Tools::getValue('legend'); if (is_array($legends)) { foreach ($legends as $key => $legend) { if (Validate::isGenericName($legend)) { $image->legend[(int) $key] = $legend; } else { return array('error' => sprintf(Tools::displayError('Error on image caption: "%1s" is not a valid caption.'), Tools::safeOutput($legend))); } } } if (!Image::getCover($image->id_product)) { $image->cover = 1; } else { $image->cover = 0; } if (($validate = $image->validateFieldsLang(false, true)) !== true) { return array('error' => Tools::displayError($validate)); } if (!$image->add()) { return array('error' => Tools::displayError('Error while creating additional image')); } else { return $this->copyImage($product->id, $image->id); } } }
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 ajaxProcessDeleteProductImage() { $this->display = 'content'; $res = true; /* Delete product image */ $image = new Image((int) Tools::getValue('id_image')); $this->content['id'] = $image->id; $res &= $image->delete(); // if deleted image was the cover, change it to the first one if (!Image::getCover($image->id_product)) { $res &= Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'image_shop` image_shop, ' . _DB_PREFIX_ . 'image i SET image_shop.`cover` = 1, i.cover = 1 WHERE image_shop.`id_image` = (SELECT id_image FROM (SELECT image_shop.id_image FROM ' . _DB_PREFIX_ . 'image i' . Shop::addSqlAssociation('image', 'i') . ' WHERE i.id_product =' . (int) $image->id_product . ' LIMIT 1 ) tmpImage) AND id_shop=' . (int) $this->context->shop->id . ' AND i.id_image = image_shop.id_image '); } if (file_exists(_PS_TMP_IMG_DIR_ . 'product_' . $image->id_product . '.jpg')) { $res &= @unlink(_PS_TMP_IMG_DIR_ . 'product_' . $image->id_product . '.jpg'); } if (file_exists(_PS_TMP_IMG_DIR_ . 'product_mini_' . $image->id_product . '_' . $this->context->shop->id . '.jpg')) { $res &= @unlink(_PS_TMP_IMG_DIR_ . 'product_mini_' . $image->id_product . '_' . $this->context->shop->id . '.jpg'); } if ($res) { $this->jsonConfirmation($this->_conf[7]); } else { $this->jsonError(Tools::displayError('An error occurred while attempting to delete the product image.')); } }
public function initContent() { include _PS_MODULE_DIR_ . 'blocksearch_mod' . DIRECTORY_SEPARATOR . 'IqitSearch.php'; $query = Tools::replaceAccentedChars(urldecode(Tools::getValue('q'))); $original_query = Tools::getValue('q'); $search_query_cat = (int) Tools::getValue('search_query_cat'); if ($this->ajax_search) { self::$link = new Link(); $image = new Image(); $searchResults = IqitSearch::find((int) Tools::getValue('id_lang'), $query, $search_query_cat, 1, 10, 'position', 'desc', true); $taxes = Product::getTaxCalculationMethod(); $currency = (int) Context::getContext()->currency->id; $iso_code = $this->context->language->iso_code; if (is_array($searchResults)) { foreach ($searchResults as &$product) { $imageID = $image->getCover($product['id_product']); if (isset($imageID['id_image'])) { $imgLink = $this->context->link->getImageLink($product['prewrite'], (int) $product['id_product'] . '-' . $imageID['id_image'], 'small_default'); } else { $imgLink = _THEME_PROD_DIR_ . $iso_code . "-default-small_default.jpg"; } $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']); $product['obr_thumb'] = $imgLink; $product['product_price'] = Product::getPriceStatic((int) $product['id_product'], false, NULL, 2); if ($taxes == 0 or $taxes == 2) { $product['product_price'] = Tools::displayPrice(Product::getPriceStatic((int) $product['id_product'], true), $currency); } elseif ($taxes == 1) { $product['product_price'] = Tools::displayPrice(Product::getPriceStatic((int) $product['id_product'], false), $currency); } } } $this->ajaxDie(Tools::jsonEncode($searchResults)); } // Only controller content initialization when the user use the normal search parent::initContent(); if ($this->instant_search && !is_array($query)) { $this->productSort(); $this->n = abs((int) Tools::getValue('n', $product_per_page)); $this->p = abs((int) Tools::getValue('p', 1)); $search = IqitSearch::find($this->context->language->id, $query, $search_query_cat, 1, 10, 'position', 'desc'); Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $this->addColorsToProductList($search['result']); if (method_exists('Product', 'getProductsImgs')) { $image_array = array(); for ($i = 0; $i < $nbProducts; $i++) { if (isset($search['result'][$i]['id_product'])) { $image_array[$search['result'][$i]['id_product']] = Product::getProductsImgs($search['result'][$i]['id_product']); } } $this->context->smarty->assign('productimg', (isset($image_array) and $image_array) ? $image_array : NULL); } $this->context->smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $original_query, 'instant_search' => $this->instant_search, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } elseif (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) { $this->productSort(); $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE'))); $this->p = abs((int) Tools::getValue('p', 1)); $original_query = $query; $query = Tools::replaceAccentedChars(urldecode($query)); $search = IqitSearch::find($this->context->language->id, $query, $search_query_cat, $this->p, $this->n, $this->orderBy, $this->orderWay); if (is_array($search['result'])) { foreach ($search['result'] as &$product) { $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&') . 'search_query=' . urlencode($query) . '&results=' . (int) $search['total']; } } Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $this->addColorsToProductList($search['result']); /************************* /Images Array ******************************/ if (method_exists('Product', 'getProductsImgs')) { $image_array = array(); for ($i = 0; $i < $nbProducts; $i++) { if (isset($search['result'][$i]['id_product'])) { $image_array[$search['result'][$i]['id_product']] = Product::getProductsImgs($search['result'][$i]['id_product']); } } $this->context->smarty->assign('productimg', (isset($image_array) and $image_array) ? $image_array : NULL); } /************************* /Images Array ******************************/ $this->context->smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $original_query, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } elseif (($tag = urldecode(Tools::getValue('tag'))) && !is_array($tag)) { $nbProducts = (int) Search::searchTag($this->context->language->id, $tag, true); $this->pagination($nbProducts); $result = Search::searchTag($this->context->language->id, $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay); Hook::exec('actionSearch', array('expr' => $tag, 'total' => count($result))); $this->addColorsToProductList($result); /************************* /Images Array ******************************/ if (method_exists('Product', 'getProductsImgs')) { $image_array = array(); for ($i = 0; $i < $nbProducts; $i++) { if (isset($result[$i]['id_product'])) { $image_array[$result[$i]['id_product']] = Product::getProductsImgs($result[$i]['id_product']); } } $this->context->smarty->assign('productimg', (isset($image_array) and $image_array) ? $image_array : NULL); } /************************* /Images Array ******************************/ $this->context->smarty->assign(array('search_tag' => $tag, 'products' => $result, 'search_products' => $result, 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } else { $this->context->smarty->assign(array('products' => array(), 'search_products' => array(), 'pages_nb' => 1, 'nbProducts' => 0)); } $this->context->smarty->assign(array('add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM'))); $this->setTemplate(_PS_THEME_DIR_ . 'search.tpl'); }
function getPictures($prod_id, $link_rewrite) { $link = $this->context->link; $cover = Image::getCover($prod_id); $cover_picture = $link->getImageLink($link_rewrite, $prod_id . '-' . $cover['id_image'], $this->image_type); $pictures = array($cover_picture); $images = Image::getImages($this->id_lang, $prod_id); foreach ($images as $image) { if ($image['id_image'] != $cover['id_image']) { $picture = $link->getImageLink($link_rewrite, $prod_id . '-' . $image['id_image'], $this->image_type); $pictures[] = $picture; } } return array_slice($pictures, 0, 10); }
public function save() { $product = new Product($_GET['id_product']); if (!Validate::isLoadedObject($product)) { return array('error' => Tools::displayError('Cannot add image because product creation failed.')); } else { $image = new Image(); $image->id_product = (int) $product->id; $image->position = Image::getHighestPosition($product->id) + 1; if (!Image::getCover($image->id_product)) { $image->cover = 1; } else { $image->cover = 0; } if (!$image->add()) { return array('error' => Tools::displayError('Error while creating additional image')); } else { return $this->copyImage($product->id, $image->id); } } }
function ajaxProcessDeleteProductImage() { ${${"GLOBALS"}["gyrslyepsx"]} = true; ${"GLOBALS"}["mkyfovtt"] = "json"; $rxlcerg = "res"; ${${"GLOBALS"}["jjqqyxpkvq"]} = new Image((int) Tools::getValue("id_image")); ${$rxlcerg} &= $image->delete(); if (!Image::getCover($image->id_product)) { ${${"GLOBALS"}["gyrslyepsx"]} &= Db::getInstance()->execute("\n\t\t\tUPDATE `" . _DB_PREFIX_ . "image`\n\t\t\tSET `cover` = 1\n\t\t\tWHERE `id_product` = " . (int) $image->id_product . " LIMIT 1"); } if (file_exists(_PS_TMP_IMG_DIR_ . "product_" . $image->id_product . ".jpg")) { ${${"GLOBALS"}["gyrslyepsx"]} &= @unlink(_PS_TMP_IMG_DIR_ . "product_" . $image->id_product . ".jpg"); } $ibipyme = "json"; if (file_exists(_PS_TMP_IMG_DIR_ . "product_mini_" . $image->id_product . ".jpg")) { ${${"GLOBALS"}["gyrslyepsx"]} &= @unlink(_PS_TMP_IMG_DIR_ . "product_mini_" . $image->id_product . ".jpg"); } if (${${"GLOBALS"}["gyrslyepsx"]}) { ${$ibipyme} = array("status" => "ok", "content" => array("id" => $image->id), "message" => ""); } else { ${${"GLOBALS"}["mkyfovtt"]} = array("status" => "error", "message" => Tools::displayError("Error on deleting product image")); } return Tools::jsonEncode(${${"GLOBALS"}["pthyxux"]}); }
/** * Return the rich snippet code to the hook footer in front office if configurated * * Case 1: Return rich snippet code if configurated * Case 2: Return '' if not configurated or if the product are no reviews * * @return tpl string in hook footer */ public function hookFooter() { global $smarty, $cookie; if (Configuration::get('AV_MULTILINGUE') == 'checked') { $this->id_lang = $this->context->language->id; $this->iso_lang = pSQL(Language::getIsoById($this->id_lang)); $this->group_name = $this->getIdConfigurationGroup($this->iso_lang); } $id_product = (int) Tools::getValue('id_product'); if (empty($id_product)) { return ''; } $o_av = new NetReviewsModel(); $stats_product = !isset($this->stats_product) || empty($this->stats_product) ? $o_av->getStatsProduct($id_product, $this->group_name, $this->context->shop->getContextShopID()) : $this->stats_product; if ($stats_product['nb_reviews'] == 0) { return ''; } $lang_id = (int) $this->context->language->id; if (empty($lang_id)) { $lang_id = 1; } $product = new Product((int) $id_product); $link = new LinkCore(); $a_image = Image::getCover($id_product); $smarty->assign(array('count_reviews' => $stats_product['nb_reviews'], 'average_rate' => round($stats_product['rate'], 1), 'average_rate_percent' => $stats_product['rate'] * 20, 'product_name' => $this->getProductName($id_product, $lang_id), 'product_description' => $product->description_short[$lang_id], 'product_price' => $product->getPrice(true, null, 2), 'product_quantity' => $product->quantity, 'url_image' => !empty($a_image) ? $link->getImageLink($product->link_rewrite[(int) Configuration::get('PS_LANG_DEFAULT')], $id_product . '-' . $a_image['id_image']) : '')); if (version_compare(_PS_VERSION_, '1.5', '>') && ($return = $this->display(__FILE__, '/views/templates/hook/footer_av.tpl')) || version_compare(_PS_VERSION_, '1.5', '<') && ($return = $this->display(__FILE__, 'footer_av.tpl'))) { return $return; } else { return ''; } }
public function ajaxProcessDeleteProductImage() { $this->display = 'content'; $res = true; /* Delete product image */ $image = new Image((int) Tools::getValue('id_image')); $this->content['id'] = $image->id; $res &= $image->delete(); // if deleted image was the cover, change it to the first one if (!Image::getCover($image->id_product)) { $res &= Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'image` SET `cover` = 1 WHERE `id_product` = ' . (int) $image->id_product . ' LIMIT 1'); } if (file_exists(_PS_TMP_IMG_DIR_ . 'product_' . $image->id_product . '.jpg')) { $res &= @unlink(_PS_TMP_IMG_DIR_ . 'product_' . $image->id_product . '.jpg'); } if (file_exists(_PS_TMP_IMG_DIR_ . 'product_mini_' . $image->id_product . '.jpg')) { $res &= @unlink(_PS_TMP_IMG_DIR_ . 'product_mini_' . $image->id_product . '.jpg'); } if ($res) { $this->jsonConfirmation($this->_conf[7]); } else { $this->jsonError(Tools::displayError('Error on deleting product image')); } }
/** * @param \Payin7\Models\QuoteModel $quote * @param null $cart * @param bool $full_data * @return \Payin7\Models\QuoteModel */ public function prepareCartQuote(\Payin7\Models\QuoteModel $quote = null, $full_data = false, $cart = null) { /** @var \Payin7\Models\QuoteModel $quote */ $quote = $quote ? $quote : $this->getModelInstance('quote'); $cart = $cart ? $cart : $this->context->cart; if (!$cart) { return null; } /** @noinspection PhpUndefinedMethodInspection */ $products = $cart->getProducts(); /** @noinspection PhpUndefinedClassInspection */ $carrier = new Carrier($cart->id_carrier); /** @noinspection PhpUndefinedClassInspection */ $cust = new Customer($cart->id_customer); /** @noinspection PhpUndefinedMethodInspection */ $shipping_cost = $this->_is14 ? $cart->getOrderShippingCost() : $cart->getTotalShippingCost(null, true, null); // order $quote->setQuoteId($cart->id); /** @noinspection PhpUndefinedFieldInspection */ $quote->setCurrencyCode($this->context->currency->iso_code); /** @noinspection PhpUndefinedFieldInspection */ $quote->setShippingMethodCode('carrier_' . (property_exists($carrier, 'id_reference') ? $carrier->id_reference : $carrier->id)); /** @noinspection PhpUndefinedFieldInspection */ $quote->setShippingMethodTitle($carrier->name); $quote->setCreatedAt($cart->date_add); $quote->setUpdatedAt($cart->date_upd); $quote->setShippingAmount($this->roundPrice($shipping_cost)); /** @noinspection PhpUndefinedMethodInspection */ $quote->setGrandTotal($this->roundPrice($cart->getOrderTotal())); $quote->setOrderedItems($products ? count($products) : null); /** @noinspection PhpUndefinedFieldInspection */ $quote->setCustomerIsGuest((bool) $cust->is_guest); // billing address /** @noinspection PhpUndefinedClassInspection */ $address = new Address($this->context->cart->id_address_invoice); /** @noinspection PhpUndefinedClassInspection */ /** @noinspection PhpUndefinedFieldInspection */ $user_state = new State($address->id_state); /** @noinspection PhpUndefinedClassInspection */ /** @noinspection PhpUndefinedFieldInspection */ $user_country = new Country($address->id_country); $billing_addr = $quote->getBillingAddress(); $billing_addr->setCustomerAddressId($this->context->cart->id_address_invoice); /** @noinspection PhpUndefinedFieldInspection */ $billing_addr->setFirstname($address->firstname); /** @noinspection PhpUndefinedFieldInspection */ $billing_addr->setLastname($address->lastname); /** @noinspection PhpUndefinedFieldInspection */ $billing_addr->setCompany($address->company); /** @noinspection PhpUndefinedFieldInspection */ $billing_addr->setStreet1($address->address1); /** @noinspection PhpUndefinedFieldInspection */ $billing_addr->setStreet2($address->address2); /** @noinspection PhpUndefinedFieldInspection */ $billing_addr->setCity($address->city); /** @noinspection PhpUndefinedFieldInspection */ $billing_addr->setCountry($user_country->iso_code); /** @noinspection PhpUndefinedFieldInspection */ $billing_addr->setCountryState($user_state->name); /** @noinspection PhpUndefinedFieldInspection */ $billing_addr->setPostcode($address->postcode); /** @noinspection PhpUndefinedFieldInspection */ $billing_addr->setTelephone1($address->phone); /** @noinspection PhpUndefinedFieldInspection */ $billing_addr->setTelephone2($address->phone_mobile); /** @noinspection PhpUndefinedFieldInspection */ $billing_addr->setTaxVATNumber($address->vat_number); if (!$full_data) { return $quote; } // shipping address /** @noinspection PhpUndefinedClassInspection */ $address = new Address($this->context->cart->id_address_delivery); /** @noinspection PhpUndefinedClassInspection */ /** @noinspection PhpUndefinedFieldInspection */ $user_state = new State($address->id_state); /** @noinspection PhpUndefinedClassInspection */ /** @noinspection PhpUndefinedFieldInspection */ $user_country = new Country($address->id_country); $shipping_addr = $quote->getShippingAddress(); $shipping_addr->setCustomerAddressId($this->context->cart->id_address_delivery); /** @noinspection PhpUndefinedFieldInspection */ $shipping_addr->setFirstname($address->firstname); /** @noinspection PhpUndefinedFieldInspection */ $shipping_addr->setLastname($address->lastname); /** @noinspection PhpUndefinedFieldInspection */ $shipping_addr->setCompany($address->company); /** @noinspection PhpUndefinedFieldInspection */ $shipping_addr->setStreet1($address->address1); /** @noinspection PhpUndefinedFieldInspection */ $shipping_addr->setStreet2($address->address2); /** @noinspection PhpUndefinedFieldInspection */ $shipping_addr->setCity($address->city); /** @noinspection PhpUndefinedFieldInspection */ $shipping_addr->setCountry($user_country->iso_code); /** @noinspection PhpUndefinedFieldInspection */ $shipping_addr->setCountryState($user_state->name); /** @noinspection PhpUndefinedFieldInspection */ $shipping_addr->setPostcode($address->postcode); /** @noinspection PhpUndefinedFieldInspection */ $shipping_addr->setTelephone1($address->phone); /** @noinspection PhpUndefinedFieldInspection */ $shipping_addr->setTelephone2($address->phone_mobile); /** @noinspection PhpUndefinedFieldInspection */ $shipping_addr->setTaxVATNumber($address->vat_number); // products if ($products) { foreach ($products as $product) { /** @noinspection PhpUndefinedClassInspection */ $link = new Link(); /** @noinspection PhpUndefinedMethodInspection */ $url = $link->getProductLink($product); /** @noinspection PhpUndefinedClassInspection */ /** @noinspection PhpUndefinedMethodInspection */ $image = Image::getCover($product['id_product']); /** @noinspection PhpUndefinedMethodInspection */ $imagePath = $image ? $link->getImageLink($product['link_rewrite'], $image['id_image'], 'home_default') : null; $imagePath = $imagePath ? 'http://' . $imagePath : $imagePath; /** @var \Payin7\Models\OrderItemModel $pm */ $pm = $this->getModelInstance('order_item'); $pm->setId($product['id_product']); $pm->setProductId($product['id_product']); $pm->setName($product['name']); $pm->setProductUrl($url); $pm->setImageUrl($imagePath); $pm->setShortDescription(isset($product['description_short']) ? $product['description_short'] : null); $pm->setFullDescription(isset($product['attributes']) ? $product['attributes'] : null); $pm->setIsVirtual(isset($product['is_virtual']) ? $product['is_virtual'] : null); $pm->setQtyOrdered($product['cart_quantity']); $pm->setPriceInclTax($this->roundPrice($product['price_wt'])); $pm->setPrice($this->roundPrice($product['price'])); $pm->setTaxAmount($product['price_wt'] - $product['price']); $pm->setPriceBeforeDiscount($this->roundPrice(isset($product['price_without_reduction']) ? $product['price_without_reduction'] : null)); $pm->setDiscountAmount($this->roundPrice(isset($product['price_with_reduction_without_tax']) ? $product['price_with_reduction_without_tax'] : null)); $pm->setDiscountAmountWithTax($this->roundPrice(isset($product['price_with_reduction']) ? $product['price_with_reduction'] : null)); $pm->setShippingAmountWithTax($this->roundPrice(isset($product['additional_shipping_cost']) ? $product['additional_shipping_cost'] : null)); $pm->setShippingAmount($this->roundPrice($pm->getShippingAmountWithTax())); $pm->setRowTotal($this->roundPrice($product['price'])); $pm->setRowTotalInclTax($this->roundPrice($product['price_wt'])); $pm->setTaxRate(isset($product['rate']) ? $product['rate'] : null); $quote->addItem($pm); unset($product); } } // customer /** @noinspection PhpUndefinedClassInspection */ $cust = new Customer($cart->id_customer); /** @noinspection PhpUndefinedClassInspection */ $custlang = new Language($cart->id_lang); /** @noinspection PhpUndefinedFieldInspection */ $gender = $cust->id_gender == 1 ? \Payin7\Models\CustomerModel::GENDER_MALE : ($cust->id_gender == 2 ? \Payin7\Models\CustomerModel::GENDER_FEMALE : null); /** @var \Payin7\Models\CustomerModel $customer */ $customer = $this->getModelInstance('customer'); $customer->setCustomerId($cart->id_customer); $customer->setGender($gender); /** @noinspection PhpUndefinedFieldInspection */ $customer->setPreferredLanguageCode($custlang->iso_code); /** @noinspection PhpUndefinedFieldInspection */ $customer->setCreatedAt($cust->date_add); /** @noinspection PhpUndefinedFieldInspection */ $customer->setUpdatedAt($cust->date_upd); /** @noinspection PhpUndefinedFieldInspection */ $customer->setDob($cust->birthday); /** @noinspection PhpUndefinedFieldInspection */ $customer->setEmail($cust->email); /** @noinspection PhpUndefinedFieldInspection */ $customer->setFirstName($cust->firstname); /** @noinspection PhpUndefinedFieldInspection */ $customer->setLastName($cust->lastname); // missing on 1.4 if (property_exists($cust, 'company')) { /** @noinspection PhpUndefinedFieldInspection */ $customer->setCompany($cust->company); } $quote->setCustomer($customer); return $quote; }
/** * getProductImage() method returns product image * * @param obj $oProduct * @param string $sImageType * @return obj */ public static function getProductImage(Product &$oProduct, $sImageType) { $sImgUrl = ''; if (Validate::isLoadedObject($oProduct)) { // use case - get Image $aImage = Image::getCover($oProduct->id); if (!empty($aImage)) { // get image url $sImgUrl = self::getLinkObj()->getImageLink($oProduct->link_rewrite, $oProduct->id . '-' . $aImage['id_image'], $sImageType); // use case - get valid IMG URI before Prestashop 1.4 $sImgUrl = self::detectHttpUri($sImgUrl); } } return $sImgUrl; }
/** * @param \Product $product * * @return string * @throws \Exception * @author Panagiotis Vagenas <*****@*****.**> * @since 150213 */ protected function getProductImageLink(\Product &$product) { $link = new \Link(); $imageLink = null; if ($this->Options->getValue('map_image') == 1) { $images = $product->getImages($this->defaultLang); if (!empty($images)) { shuffle($images); $imageLink = $link->getImageLink($product->link_rewrite, end($images)['id_image']); } } else { $coverImage = \Image::getCover($product->id); if ($coverImage && !empty($coverImage) && isset($coverImage['id_image'])) { $imageLink = $link->getImageLink($product->link_rewrite, $coverImage['id_image']); } } return empty($imageLink) ? '' : urldecode($this->addHttp($imageLink)); }
public static function getUrlsProduct($product_id) { $product_exist = Db::getInstance()->getRow('SELECT * FROM ' . _DB_PREFIX_ . 'product WHERE id_product =' . (int) $product_id); if ($product_exist) { $o_product = new Product($product_id, false, (int) Configuration::get('PS_LANG_DEFAULT')); $protocol_link = Configuration::get('PS_SSL_ENABLED') || Tools::usingSecureMode() ? 'https://' : 'http://'; $use_ssl = Configuration::get('PS_SSL_ENABLED') || Tools::usingSecureMode() ? true : false; $protocol_content = $use_ssl ? 'https://' : 'http://'; $link = new Link($protocol_link, $protocol_content); $id_cover_image = Image::getCover($product_id); $image_path = $link->getImageLink($o_product->link_rewrite[(int) Configuration::get('PS_LANG_DEFAULT')], $id_cover_image['id_image']); $url_product = $link->getProductLink($product_id); return array('url_product' => $url_product, 'url_image_product' => $image_path); } }
/** * 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)); } }
/** * postProcess handle every checks before saving products information * * @param mixed $token * @return void */ public function postProcess($token = null) { global $cookie, $currentIndex; // Add a new product if (Tools::isSubmit('submitAddproduct') || Tools::isSubmit('submitAddproductAndStay') || Tools::isSubmit('submitAddProductAndPreview')) { if (Tools::getValue('id_product') && $this->tabAccess['edit'] === '1' || $this->tabAccess['add'] === '1' && !Tools::isSubmit('id_product')) { $this->submitAddproduct($token); } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } /* Delete a product in the download folder */ if (Tools::getValue('deleteVirtualProduct')) { if ($this->tabAccess['delete'] === '1') { $this->deleteVirtualProduct(); } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } elseif (Tools::isSubmit('submitAddAttachments')) { if ($this->tabAccess['add'] === '1') { $languages = Language::getLanguages(false); $is_attachment_name_valid = false; foreach ($languages as $language) { $attachment_name_lang = Tools::getValue('attachment_name_' . (int) $language['id_lang']); if (strlen($attachment_name_lang) > 0) { $is_attachment_name_valid = true; } if (!Validate::isGenericName(Tools::getValue('attachment_name_' . (int) $language['id_lang']))) { $this->_errors[] = Tools::displayError('Invalid Name'); } elseif (Tools::strlen(Tools::getValue('attachment_name_' . (int) $language['id_lang'])) > 32) { $this->_errors[] = Tools::displayError('Name is too long'); } if (!Validate::isCleanHtml(Tools::getValue('attachment_description_' . (int) $language['id_lang']))) { $this->_errors[] = Tools::displayError('Invalid description'); } } if (!$is_attachment_name_valid) { $this->_errors[] = Tools::displayError('Attachment Name Required'); } if (empty($this->_errors)) { if (isset($_FILES['attachment_file']) && is_uploaded_file($_FILES['attachment_file']['tmp_name'])) { if ($_FILES['attachment_file']['size'] > Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024) { $this->_errors[] = $this->l('File too large, maximum size allowed:') . ' ' . Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 . ' ' . $this->l('kb') . '. ' . $this->l('File size you\'re trying to upload is:') . number_format($_FILES['attachment_file']['size'] / 1024, 2, '.', '') . $this->l('kb'); } else { do { $uniqid = sha1(microtime()); } while (file_exists(_PS_DOWNLOAD_DIR_ . $uniqid)); if (!copy($_FILES['attachment_file']['tmp_name'], _PS_DOWNLOAD_DIR_ . $uniqid)) { $this->_errors[] = $this->l('File copy failed'); } @unlink($_FILES['attachment_file']['tmp_name']); } } elseif ((int) $_FILES['attachment_file']['error'] === 1) { $max_upload = (int) ini_get('upload_max_filesize'); $max_post = (int) ini_get('post_max_size'); $upload_mb = min($max_upload, $max_post); $this->_errors[] = $this->l('the File') . ' <b>' . $_FILES['attachment_file']['name'] . '</b> ' . $this->l('exceeds the size allowed by the server, this limit is set to') . ' <b>' . $upload_mb . $this->l('Mb') . '</b>'; } if (empty($this->_errors) && isset($uniqid)) { $attachment = new Attachment(); foreach ($languages as $language) { if (isset($_POST['attachment_name_' . (int) $language['id_lang']])) { $attachment->name[(int) $language['id_lang']] = pSQL($_POST['attachment_name_' . (int) $language['id_lang']]); } if (isset($_POST['attachment_description_' . (int) $language['id_lang']])) { $attachment->description[(int) $language['id_lang']] = pSQL($_POST['attachment_description_' . (int) $language['id_lang']]); } } $attachment->file = $uniqid; $attachment->mime = $_FILES['attachment_file']['type']; $attachment->file_name = pSQL($_FILES['attachment_file']['name']); if (empty($attachment->mime) or Tools::strlen($attachment->mime) > 128) { $this->_errors[] = Tools::displayError('Invalid file extension'); } if (!Validate::isGenericName($attachment->file_name)) { $this->_errors[] = Tools::displayError('Invalid file name'); } if (Tools::strlen($attachment->file_name) > 128) { $this->_errors[] = Tools::displayError('File name too long'); } if (!sizeof($this->_errors)) { $attachment->add(); Tools::redirectAdmin($currentIndex . '&id_product=' . (int) Tools::getValue($this->identifier) . '&id_category=' . (int) Tools::getValue('id_category') . '&addproduct&conf=4&tabs=6&token=' . ($token ? $token : $this->token)); } else { $this->_errors[] = Tools::displayError('Invalid file'); } } } } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } elseif (Tools::isSubmit('submitAttachments')) { if ($this->tabAccess['edit'] === '1') { if ($id = (int) Tools::getValue($this->identifier)) { if (Attachment::attachToProduct($id, $_POST['attachments'])) { Tools::redirectAdmin($currentIndex . '&id_product=' . (int) $id . (isset($_POST['id_category']) ? '&id_category=' . (int) $_POST['id_category'] : '') . '&conf=4&add' . $this->table . '&tabs=6&token=' . ($token ? $token : $this->token)); } } } } elseif (isset($_GET['duplicate' . $this->table])) { if ($this->tabAccess['add'] === '1') { if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) { $id_product_old = $product->id; unset($product->id); unset($product->id_product); $product->indexed = 0; $product->active = 0; if ($product->add() and Category::duplicateProductCategories($id_product_old, $product->id) and ($combinationImages = Product::duplicateAttributes($id_product_old, $product->id)) !== false and GroupReduction::duplicateReduction($id_product_old, $product->id) and Product::duplicateAccessories($id_product_old, $product->id) and Product::duplicateFeatures($id_product_old, $product->id) and Product::duplicateSpecificPrices($id_product_old, $product->id) and Pack::duplicate($id_product_old, $product->id) and Product::duplicateCustomizationFields($id_product_old, $product->id) and Product::duplicateTags($id_product_old, $product->id) and Product::duplicateDownload($id_product_old, $product->id)) { if ($product->hasAttributes()) { Product::updateDefaultAttribute($product->id); } if (!Tools::getValue('noimage') and !Image::duplicateProductImages($id_product_old, $product->id, $combinationImages)) { $this->_errors[] = Tools::displayError('An error occurred while copying images.'); } else { Hook::addProduct($product); Search::indexation(false, $product->id); Tools::redirectAdmin($currentIndex . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&conf=19&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('An error occurred while creating object.'); } } } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } elseif (isset($_GET['status']) and Tools::getValue($this->identifier)) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($object = $this->loadObject())) { if ($object->toggleStatus()) { Tools::redirectAdmin($currentIndex . '&conf=5' . (($id_category = !empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1' and Tools::getValue('id_product')) ? '&id_category=' . $id_category : '') . '&token=' . $token); } else { $this->_errors[] = Tools::displayError('An error occurred while updating status.'); } } else { $this->_errors[] = Tools::displayError('An error occurred while updating status for object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } elseif (isset($_GET['delete' . $this->table])) { if ($this->tabAccess['delete'] === '1') { if (Validate::isLoadedObject($object = $this->loadObject()) and isset($this->fieldImageSettings)) { // check if request at least one object with noZeroObject if (isset($object->noZeroObject) and sizeof($taxes = call_user_func(array($this->className, $object->noZeroObject))) <= 1) { $this->_errors[] = Tools::displayError('You need at least one object.') . ' <b>' . $this->table . '</b><br />' . Tools::displayError('You cannot delete all of the items.'); } else { $id_category = Tools::getValue('id_category'); $category_url = empty($id_category) ? '' : '&id_category=' . $id_category; if ($this->deleted) { $object->deleteImages(); $object->deleted = 1; if ($object->update()) { Tools::redirectAdmin($currentIndex . '&conf=1&token=' . ($token ? $token : $this->token) . $category_url); } } elseif ($object->delete()) { Tools::redirectAdmin($currentIndex . '&conf=1&token=' . ($token ? $token : $this->token) . $category_url); } $this->_errors[] = Tools::displayError('An error occurred during deletion.'); } } else { $this->_errors[] = Tools::displayError('An error occurred while deleting object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } elseif (Tools::getValue('submitDel' . $this->table)) { if ($this->tabAccess['delete'] === '1') { if (isset($_POST[$this->table . 'Box'])) { $object = new $this->className(); if (isset($object->noZeroObject) and (sizeof(call_user_func(array($this->className, $object->noZeroObject))) <= 1 or sizeof($_POST[$this->table . 'Box']) == sizeof(call_user_func(array($this->className, $object->noZeroObject))))) { $this->_errors[] = Tools::displayError('You need at least one object.') . ' <b>' . $this->table . '</b><br />' . Tools::displayError('You cannot delete all of the items.'); } else { $result = true; if ($this->deleted) { foreach (Tools::getValue($this->table . 'Box') as $id) { $toDelete = new $this->className($id); $toDelete->deleted = 1; $result = $result and $toDelete->update(); } } else { $result = $object->deleteSelection(Tools::getValue($this->table . 'Box')); } if ($result) { $id_category = Tools::getValue('id_category'); $category_url = empty($id_category) ? '' : '&id_category=' . $id_category; Tools::redirectAdmin($currentIndex . '&conf=2&token=' . $token . $category_url); } $this->_errors[] = Tools::displayError('An error occurred while deleting selection.'); } } else { $this->_errors[] = Tools::displayError('You must select at least one element to delete.'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } elseif ($id_image = (int) Tools::getValue('id_image') and Validate::isUnsignedId($id_image) and Validate::isLoadedObject($image = new Image($id_image))) { /* PrestaShop demo mode */ if (_PS_MODE_DEMO_) { $this->_errors[] = Tools::displayError('This functionnality has been disabled.'); return; } /* PrestaShop demo mode*/ if ($this->tabAccess['edit'] === '1') { /* Delete product image */ if (isset($_GET['deleteImage'])) { $image->delete(); if (!Image::getCover($image->id_product)) { $first_img = Db::getInstance()->getRow(' SELECT `id_image` FROM `' . _DB_PREFIX_ . 'image` WHERE `id_product` = ' . (int) $image->id_product); Db::getInstance()->Execute(' UPDATE `' . _DB_PREFIX_ . 'image` SET `cover` = 1 WHERE `id_image` = ' . (int) $first_img['id_image']); } @unlink(_PS_TMP_IMG_DIR_ . '/product_' . $image->id_product . '.jpg'); @unlink(_PS_TMP_IMG_DIR_ . '/product_mini_' . $image->id_product . '.jpg'); Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=1' . '&token=' . ($token ? $token : $this->token)); } elseif (isset($_GET['editImage'])) { if ($image->cover) { $_POST['cover'] = 1; } $languages = Language::getLanguages(false); foreach ($languages as $language) { if (isset($image->legend[$language['id_lang']])) { $_POST['legend_' . $language['id_lang']] = $image->legend[$language['id_lang']]; } } $_POST['id_image'] = $image->id; $this->displayForm(); } elseif (isset($_GET['coverImage'])) { Image::deleteCover($image->id_product); $image->cover = 1; if (!$image->update()) { $this->_errors[] = Tools::displayError('Cannot change the product cover'); } else { $productId = (int) Tools::getValue('id_product'); @unlink(_PS_TMP_IMG_DIR_ . '/product_' . $productId . '.jpg'); @unlink(_PS_TMP_IMG_DIR_ . '/product_mini_' . $productId . '.jpg'); Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&addproduct&tabs=1' . '&token=' . ($token ? $token : $this->token)); } } elseif (isset($_GET['imgPosition']) and isset($_GET['imgDirection'])) { $image->positionImage((int) Tools::getValue('imgPosition'), (int) Tools::getValue('imgDirection')); Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=1&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } elseif (Tools::isSubmit('submitProductAttribute')) { if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) { if (!isset($_POST['attribute_price']) or $_POST['attribute_price'] == NULL) { $this->_errors[] = Tools::displayError('Attribute price required.'); } if (!isset($_POST['attribute_combinaison_list']) or !sizeof($_POST['attribute_combinaison_list'])) { $this->_errors[] = Tools::displayError('You must add at least one attribute.'); } if (!sizeof($this->_errors)) { if (!isset($_POST['attribute_wholesale_price'])) { $_POST['attribute_wholesale_price'] = 0; } if (!isset($_POST['attribute_price_impact'])) { $_POST['attribute_price_impact'] = 0; } if (!isset($_POST['attribute_weight_impact'])) { $_POST['attribute_weight_impact'] = 0; } if (!isset($_POST['attribute_ecotax'])) { $_POST['attribute_ecotax'] = 0; } if (Tools::getValue('attribute_default')) { $product->deleteDefaultAttributes(); } // Change existing one if ($id_product_attribute = (int) Tools::getValue('id_product_attribute')) { if ($this->tabAccess['edit'] === '1') { if ($product->productAttributeExists($_POST['attribute_combinaison_list'], $id_product_attribute)) { $this->_errors[] = Tools::displayError('This attribute already exists.'); } else { $product->updateProductAttribute($id_product_attribute, Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'), Tools::getValue('attribute_ecotax'), false, Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_supplier_reference'), Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), Tools::getValue('attribute_minimal_quantity')); if ($id_reason = (int) Tools::getValue('id_mvt_reason') and (int) Tools::getValue('attribute_mvt_quantity') > 0 and $id_reason > 0) { $reason = new StockMvtReason((int) $id_reason); $qty = Tools::getValue('attribute_mvt_quantity') * $reason->sign; if (!$product->addStockMvt($qty, $id_reason, (int) $id_product_attribute, NULL, $cookie->id_employee)) { $this->_errors[] = Tools::displayError('An error occurred while updating qty.'); } } Hook::updateProductAttribute((int) $id_product_attribute); } } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } else { if ($this->tabAccess['add'] === '1') { if ($product->productAttributeExists($_POST['attribute_combinaison_list'])) { $this->_errors[] = Tools::displayError('This combination already exists.'); } else { $id_product_attribute = $product->addCombinationEntity(Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'), Tools::getValue('attribute_ecotax'), Tools::getValue('attribute_quantity'), Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_supplier_reference'), Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), Tools::getValue('attribute_minimal_quantity')); } } else { $this->_errors[] = Tools::displayError('You do not have permission to') . '<hr>' . Tools::displayError('Edit here.'); } } if (!sizeof($this->_errors)) { $product->addAttributeCombinaison($id_product_attribute, Tools::getValue('attribute_combinaison_list')); $product->checkDefaultAttributes(); } if (!sizeof($this->_errors)) { if (!$product->cache_default_attribute) { Product::updateDefaultAttribute($product->id); } Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=3&token=' . ($token ? $token : $this->token)); } } } } elseif (Tools::isSubmit('deleteProductAttribute')) { if ($this->tabAccess['delete'] === '1') { if ($id_product = (int) Tools::getValue('id_product') and Validate::isUnsignedId($id_product) and Validate::isLoadedObject($product = new Product($id_product))) { $product->deleteAttributeCombinaison((int) Tools::getValue('id_product_attribute')); $product->checkDefaultAttributes(); $product->updateQuantityProductWithAttributeQuantity(); if (!$product->hasAttributes()) { $product->cache_default_attribute = 0; $product->update(); } else { Product::updateDefaultAttribute($id_product); } Tools::redirectAdmin($currentIndex . '&add' . $this->table . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&tabs=3&id_product=' . $product->id . '&token=' . ($token ? $token : $this->token)); } else { $this->_errors[] = Tools::displayError('Cannot delete attribute'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } elseif (Tools::isSubmit('deleteAllProductAttributes')) { if ($this->tabAccess['delete'] === '1') { if ($id_product = (int) Tools::getValue('id_product') and Validate::isUnsignedId($id_product) and Validate::isLoadedObject($product = new Product($id_product))) { $product->deleteProductAttributes(); $product->updateQuantityProductWithAttributeQuantity(); if ($product->cache_default_attribute) { $product->cache_default_attribute = 0; $product->update(); } Tools::redirectAdmin($currentIndex . '&add' . $this->table . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&tabs=3&id_product=' . $product->id . '&token=' . ($token ? $token : $this->token)); } else { $this->_errors[] = Tools::displayError('Cannot delete attributes'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } elseif (Tools::isSubmit('defaultProductAttribute')) { if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) { $product->deleteDefaultAttributes(); $product->setDefaultAttribute((int) Tools::getValue('id_product_attribute')); Tools::redirectAdmin($currentIndex . '&add' . $this->table . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&tabs=3&id_product=' . $product->id . '&token=' . ($token ? $token : $this->token)); } else { $this->_errors[] = Tools::displayError('Cannot make default attribute'); } } elseif (Tools::isSubmit('submitProductFeature')) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) { // delete all objects $product->deleteFeatures(); // add new objects $languages = Language::getLanguages(false); foreach ($_POST as $key => $val) { if (preg_match('/^feature_([0-9]+)_value/i', $key, $match)) { if ($val) { $product->addFeaturesToDB($match[1], $val); } else { if ($default_value = $this->checkFeatures($languages, $match[1])) { $id_value = $product->addFeaturesToDB($match[1], 0, 1, (int) $language['id_lang']); foreach ($languages as $language) { if ($cust = Tools::getValue('custom_' . $match[1] . '_' . (int) $language['id_lang'])) { $product->addFeaturesCustomToDB($id_value, (int) $language['id_lang'], $cust); } else { $product->addFeaturesCustomToDB($id_value, (int) $language['id_lang'], $default_value); } } } } } } if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . (int) $product->id . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=4&conf=4&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('Product must be created before adding features.'); } } $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } elseif (Tools::isSubmit('submitPricesModification')) { $_POST['tabs'] = 5; if ($this->tabAccess['edit'] === '1') { $id_specific_prices = Tools::getValue('spm_id_specific_price'); $id_shops = Tools::getValue('spm_id_shop'); $id_currencies = Tools::getValue('spm_id_currency'); $id_countries = Tools::getValue('spm_id_country'); $id_groups = Tools::getValue('spm_id_group'); $prices = Tools::getValue('spm_price'); $from_quantities = Tools::getValue('spm_from_quantity'); $reductions = Tools::getValue('spm_reduction'); $reduction_types = Tools::getValue('spm_reduction_type'); $froms = Tools::getValue('spm_from'); $tos = Tools::getValue('spm_to'); foreach ($id_specific_prices as $key => $id_specific_price) { if ($this->_validateSpecificPrice($id_shops[$key], $id_currencies[$key], $id_countries[$key], $id_groups[$key], $prices[$key], $from_quantities[$key], $reductions[$key], $reduction_types[$key], $froms[$key], $tos[$key])) { $specificPrice = new SpecificPrice((int) $id_specific_price); $specificPrice->id_shop = (int) $id_shops[$key]; $specificPrice->id_currency = (int) $id_currencies[$key]; $specificPrice->id_country = (int) $id_countries[$key]; $specificPrice->id_group = (int) $id_groups[$key]; $specificPrice->price = (double) $prices[$key]; $specificPrice->from_quantity = (int) $from_quantities[$key]; $specificPrice->reduction = (double) ($reduction_types[$key] == 'percentage' ? $reductions[$key] / 100 : $reductions[$key]); $specificPrice->reduction_type = !$reductions[$key] ? 'amount' : $reduction_types[$key]; $specificPrice->from = !$froms[$key] ? '0000-00-00 00:00:00' : $froms[$key]; $specificPrice->to = !$tos[$key] ? '0000-00-00 00:00:00' : $tos[$key]; if (!$specificPrice->update()) { $this->_errors = Tools::displayError('An error occurred while updating the specific price.'); } } } if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . (int) Tools::getValue('id_product') . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&update' . $this->table . '&tabs=2&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } elseif (Tools::isSubmit('submitPriceAddition')) { if ($this->tabAccess['add'] === '1') { $id_product = (int) Tools::getValue('id_product'); $id_shop = Tools::getValue('sp_id_shop'); $id_currency = Tools::getValue('sp_id_currency'); $id_country = Tools::getValue('sp_id_country'); $id_group = Tools::getValue('sp_id_group'); $price = Tools::getValue('sp_price'); $from_quantity = Tools::getValue('sp_from_quantity'); $reduction = (double) Tools::getValue('sp_reduction'); $reduction_type = !$reduction ? 'amount' : Tools::getValue('sp_reduction_type'); $from = Tools::getValue('sp_from'); $to = Tools::getValue('sp_to'); if ($this->_validateSpecificPrice($id_shop, $id_currency, $id_country, $id_group, $price, $from_quantity, $reduction, $reduction_type, $from, $to)) { $specificPrice = new SpecificPrice(); $specificPrice->id_product = $id_product; $specificPrice->id_shop = (int) $id_shop; $specificPrice->id_currency = (int) $id_currency; $specificPrice->id_country = (int) $id_country; $specificPrice->id_group = (int) $id_group; $specificPrice->price = (double) $price; $specificPrice->from_quantity = (int) $from_quantity; $specificPrice->reduction = (double) ($reduction_type == 'percentage' ? $reduction / 100 : $reduction); $specificPrice->reduction_type = $reduction_type; $specificPrice->from = !$from ? '0000-00-00 00:00:00' : $from; $specificPrice->to = !$to ? '0000-00-00 00:00:00' : $to; if (!$specificPrice->add()) { $this->_errors = Tools::displayError('An error occurred while updating the specific price.'); } else { Tools::redirectAdmin($currentIndex . (Tools::getValue('id_category') ? '&id_category=' . Tools::getValue('id_category') : '') . '&id_product=' . $id_product . '&add' . $this->table . '&tabs=2&conf=3&token=' . ($token ? $token : $this->token)); } } } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } elseif (Tools::isSubmit('deleteSpecificPrice')) { if ($this->tabAccess['delete'] === '1') { if (!($obj = $this->loadObject())) { return; } if (!($id_specific_price = Tools::getValue('id_specific_price')) or !Validate::isUnsignedId($id_specific_price)) { $this->_errors[] = Tools::displayError('Invalid specific price ID'); } else { $specificPrice = new SpecificPrice((int) $id_specific_price); if (!$specificPrice->delete()) { $this->_errors[] = Tools::displayError('An error occurred while deleting the specific price'); } else { Tools::redirectAdmin($currentIndex . (Tools::getValue('id_category') ? '&id_category=' . Tools::getValue('id_category') : '') . '&id_product=' . $obj->id . '&add' . $this->table . '&tabs=2&conf=1&token=' . ($token ? $token : $this->token)); } } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } elseif (Tools::isSubmit('submitSpecificPricePriorities')) { if (!($obj = $this->loadObject())) { return; } if (!($priorities = Tools::getValue('specificPricePriority'))) { $this->_errors[] = Tools::displayError('Please specify priorities'); } elseif (Tools::isSubmit('specificPricePriorityToAll')) { if (!SpecificPrice::setPriorities($priorities)) { $this->_errors[] = Tools::displayError('An error occurred while updating priorities.'); } else { Tools::redirectAdmin($currentIndex . '&id_product=' . $obj->id . '&add' . $this->table . '&tabs=2&conf=4&token=' . ($token ? $token : $this->token)); } } elseif (!SpecificPrice::setSpecificPriority((int) $obj->id, $priorities)) { $this->_errors[] = Tools::displayError('An error occurred while setting priorities.'); } else { Tools::redirectAdmin($currentIndex . (Tools::getValue('id_category') ? '&id_category=' . Tools::getValue('id_category') : '') . '&id_product=' . $obj->id . '&add' . $this->table . '&tabs=2&conf=4&token=' . ($token ? $token : $this->token)); } } elseif (Tools::isSubmit('submitCustomizationConfiguration')) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) { if (!$product->createLabels((int) $_POST['uploadable_files'] - (int) $product->uploadable_files, (int) $_POST['text_fields'] - (int) $product->text_fields)) { $this->_errors[] = Tools::displayError('An error occurred while creating customization fields.'); } if (!sizeof($this->_errors) and !$product->updateLabels()) { $this->_errors[] = Tools::displayError('An error occurred while updating customization.'); } $product->uploadable_files = (int) $_POST['uploadable_files']; $product->text_fields = (int) $_POST['text_fields']; $product->customizable = ((int) $_POST['uploadable_files'] > 0 or (int) $_POST['text_fields'] > 0) ? 1 : 0; if (!sizeof($this->_errors) and !$product->update()) { $this->_errors[] = Tools::displayError('An error occurred while updating customization configuration.'); } if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=5&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('Product must be created before adding customization possibilities.'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } elseif (Tools::isSubmit('submitProductCustomization')) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) { foreach ($_POST as $field => $value) { if (strncmp($field, 'label_', 6) == 0 and !Validate::isLabel($value)) { $this->_errors[] = Tools::displayError('Label fields are invalid'); } } if (!sizeof($this->_errors) and !$product->updateLabels()) { $this->_errors[] = Tools::displayError('An error occurred while updating customization.'); } if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=5&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('Product must be created before adding customization possibilities.'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } elseif (isset($_GET['position'])) { if ($this->tabAccess['edit'] !== '1') { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } elseif (!Validate::isLoadedObject($object = $this->loadObject())) { $this->_errors[] = Tools::displayError('An error occurred while updating status for object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)'); } if (!$object->updatePosition((int) Tools::getValue('way'), (int) Tools::getValue('position'))) { $this->_errors[] = Tools::displayError('Failed to update the position.'); } else { Tools::redirectAdmin($currentIndex . '&' . $this->table . 'Orderby=position&' . $this->table . 'Orderway=asc&conf=5' . (($id_category = !empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') ? '&id_category=' . $id_category : '') . '&token=' . Tools::getAdminTokenLite('AdminCatalog')); } } else { parent::postProcess(true); } }
public function postProcess($token = NULL) { global $currentIndex; /* Add a new product */ if (Tools::isSubmit('submitAddproduct') or Tools::isSubmit('submitAddproductAndStay')) { if ($this->tabAccess['add'] === '1') { $this->submitAddproduct($token); } elseif (Tools::getValue('id_product') and $this->tabAccess['edit'] === '1') { $this->submitAddproduct($token); } else { $this->_errors[] = Tools::displayError('You do not have permission to add anything here.'); } } /* Delete a product in the download folder */ if (Tools::getValue('deleteVirtualProduct')) { if ($this->tabAccess['delete'] === '1') { $this->deleteVirtualProduct(); } else { $this->_errors[] = Tools::displayError('You do not have permission to delete anything here.'); } } elseif (Tools::isSubmit('submitAttachments')) { if ($this->tabAccess['edit'] === '1') { if ($id = intval(Tools::getValue($this->identifier))) { if (Attachment::attachToProduct($id, $_POST['attachments'])) { Tools::redirectAdmin($currentIndex . '&id_product=' . $id . '&conf=4&add' . $this->table . '&tabs=6&token=' . ($token ? $token : $this->token)); } } } } elseif (isset($_GET['duplicate' . $this->table])) { if ($this->tabAccess['add'] === '1') { if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) { $id_product_old = $product->id; unset($product->id); unset($product->id_product); $product->indexed = 0; if ($product->add() and Category::duplicateProductCategories($id_product_old, $product->id) and ($combinationImages = Product::duplicateAttributes($id_product_old, $product->id)) !== false and Product::duplicateAccessories($id_product_old, $product->id) and Product::duplicateFeatures($id_product_old, $product->id) and Product::duplicateQuantityDiscount($id_product_old, $product->id) and Pack::duplicate($id_product_old, $product->id) and Product::duplicateCustomizationFields($id_product_old, $product->id) and Product::duplicateTags($id_product_old, $product->id)) { if (!Tools::getValue('noimage') and !Image::duplicateProductImages($id_product_old, $product->id, $combinationImages)) { $this->_errors[] = Tools::displayError('an error occurred while copying images'); } else { Hook::addProduct($product); Search::indexation(false); Tools::redirectAdmin($currentIndex . '&id_category=' . intval(Tools::getValue('id_category')) . '&conf=19&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('an error occurred while creating object'); } } } else { $this->_errors[] = Tools::displayError('You do not have permission to add anything here.'); } } elseif ($id_image = intval(Tools::getValue('id_image')) and Validate::isUnsignedId($id_image) and Validate::isLoadedObject($image = new Image($id_image))) { if ($this->tabAccess['edit'] === '1') { /* Delete product image */ if (isset($_GET['deleteImage'])) { $image->delete(); deleteImage($image->id_product, $image->id); if (!Image::getCover($image->id_product)) { $first_img = Db::getInstance()->getRow(' SELECT `id_image` FROM `' . _DB_PREFIX_ . 'image` WHERE `id_product` = ' . intval($image->id_product)); Db::getInstance()->Execute(' UPDATE `' . _DB_PREFIX_ . 'image` SET `cover` = 1 WHERE `id_image` = ' . intval($first_img['id_image'])); } @unlink(dirname(__FILE__) . '/../../img/tmp/product_' . $image->id_product . '.jpg'); @unlink(dirname(__FILE__) . '/../../img/tmp/product_mini_' . $image->id_product . '.jpg'); Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=1' . '&token=' . ($token ? $token : $this->token)); } elseif (isset($_GET['editImage'])) { if ($image->cover) { $_POST['cover'] = 1; } $languages = Language::getLanguages(); foreach ($languages as $language) { if (isset($image->legend[$language['id_lang']])) { $_POST['legend_' . $language['id_lang']] = $image->legend[$language['id_lang']]; } } $_POST['id_image'] = $image->id; $this->displayForm($token ? $token : $this->token); } elseif (isset($_GET['coverImage'])) { Image::deleteCover($image->id_product); $image->cover = 1; if (!$image->update()) { $this->_errors[] = Tools::displayError('Impossible to change the product cover'); } else { $productId = intval(Tools::getValue('id_product')); @unlink(dirname(__FILE__) . '/../../img/tmp/product_' . $productId . '.jpg'); @unlink(dirname(__FILE__) . '/../../img/tmp/product_mini_' . $productId . '.jpg'); Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . intval(Tools::getValue('id_category')) . '&addproduct&tabs=1' . '&token=' . ($token ? $token : $this->token)); } } elseif (isset($_GET['imgPosition']) and isset($_GET['imgDirection'])) { $image->positionImage(intval(Tools::getValue('imgPosition')), intval(Tools::getValue('imgDirection'))); Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=1&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.'); } } elseif (Tools::isSubmit('submitProductAttribute')) { if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) { if (!isset($_POST['attribute_quantity']) or $_POST['attribute_quantity'] == NULL) { $this->_errors[] = Tools::displayError('attribute quantity is required'); } if (!isset($_POST['attribute_price']) or $_POST['attribute_price'] == NULL) { $this->_errors[] = Tools::displayError('attribute price is required'); } if (!isset($_POST['attribute_combinaison_list']) or !sizeof($_POST['attribute_combinaison_list'])) { $this->_errors[] = Tools::displayError('you must add at least one attribute'); } if (!sizeof($this->_errors)) { if (!isset($_POST['attribute_wholesale_price'])) { $_POST['attribute_wholesale_price'] = 0; } if (!isset($_POST['attribute_price_impact'])) { $_POST['attribute_price_impact'] = 0; } if (!isset($_POST['attribute_weight_impact'])) { $_POST['attribute_weight_impact'] = 0; } if (!isset($_POST['attribute_ecotax'])) { $_POST['attribute_ecotax'] = 0; } if (Tools::getValue('attribute_default')) { $product->deleteDefaultAttributes(); } // Change existing one if ($id_product_attribute = intval(Tools::getValue('id_product_attribute'))) { if ($this->tabAccess['edit'] === '1') { if ($product->productAttributeExists($_POST['attribute_combinaison_list'], $id_product_attribute)) { $this->_errors[] = Tools::displayError('This attribute already exists.'); } else { $product->updateProductAttribute($id_product_attribute, Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_ecotax'), Tools::getValue('attribute_quantity'), Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_supplier_reference'), Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location')); } } else { $this->_errors[] = Tools::displayError('You do not have permission to add anything here.'); } } else { if ($this->tabAccess['add'] === '1') { if ($product->productAttributeExists($_POST['attribute_combinaison_list'])) { $this->_errors[] = Tools::displayError('This combination already exists.'); } else { $id_product_attribute = $product->addCombinationEntity(Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_ecotax'), Tools::getValue('attribute_quantity'), Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_supplier_reference'), Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location')); } } else { $this->_errors[] = Tools::displayError('You do not have permission to') . '<hr>' . Tools::displayError('edit something here.'); } } if (!sizeof($this->_errors)) { $product->addAttributeCombinaison($id_product_attribute, Tools::getValue('attribute_combinaison_list')); $product->checkDefaultAttributes(); } if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=2&token=' . ($token ? $token : $this->token)); } } } } elseif (isset($_GET['deleteProductAttribute'])) { if ($this->tabAccess['delete'] === '1') { if ($id_product = intval(Tools::getValue('id_product')) and Validate::isUnsignedId($id_product) and Validate::isLoadedObject($product = new Product($id_product))) { $product->deleteAttributeCombinaison(intval(Tools::getValue('id_product_attribute'))); $product->checkDefaultAttributes(); Tools::redirectAdmin($currentIndex . '&add' . $this->table . '&id_category=' . intval(Tools::getValue('id_category')) . '&tabs=2&id_product=' . $product->id . '&token=' . ($token ? $token : $this->token)); } else { $this->_errors[] = Tools::displayError('impossible to delete attribute'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } elseif (Tools::isSubmit('submitProductFeature')) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) { // delete all objects $product->deleteFeatures(); // add new objects $languages = Language::getLanguages(); foreach ($_POST as $key => $val) { if (preg_match("/^feature_([0-9]+)_value/i", $key, $match)) { if ($val) { $product->addFeaturesToDB($match[1], $val); } else { if ($default_value = $this->checkFeatures($languages, $match[1])) { $id_value = $product->addFeaturesToDB($match[1], 0, 1, $language['id_lang']); foreach ($languages as $language) { if ($cust = Tools::getValue('custom_' . $match[1] . '_' . $language['id_lang'])) { $product->addFeaturesCustomToDB($id_value, $language['id_lang'], $cust); } else { $product->addFeaturesCustomToDB($id_value, $language['id_lang'], $default_value); } } } } } } if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=3&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('product must be created before adding features'); } } $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.'); } elseif (Tools::isSubmit('submitQuantityDiscount')) { $_POST['tabs'] = 5; if ($this->tabAccess['add'] === '1') { if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) { if (!($id_discount_type = intval(Tools::getValue('id_discount_type')))) { $this->_errors[] = Tools::displayError('discount type not selected'); } else { if (!($quantity_discount = intval(Tools::getValue('quantity_discount')))) { $this->_errors[] = Tools::displayError('quantity is required'); } else { if (!($value_discount = floatval(Tools::getValue('value_discount')))) { $this->_errors[] = Tools::displayError('value is required'); } else { $qD = new QuantityDiscount(); $qD->id_product = $product->id; $qD->id_discount_type = $id_discount_type; $qD->quantity = $quantity_discount; $qD->value = $value_discount; if ($qD->add() and !sizeof($this->_errors) and $qD->validateFields()) { Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=5&conf=3&token=' . ($token ? $token : $this->token)); } $this->_errors[] = Tools::displayError('an error occurred while creating object'); } } } } else { $this->_errors[] = Tools::displayError('product must be created before adding quantity discounts'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to add anything here.'); } } elseif (isset($_GET['deleteQuantityDiscount'])) { if ($this->tabAccess['delete'] === '1') { if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) { if (Validate::isLoadedObject($qD = new QuantityDiscount(intval(Tools::getValue('id_quantity_discount'))))) { $qD->delete(); if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=5&conf=1&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('not a valid quantity discount'); } } else { $this->_errors[] = Tools::displayError('product must be created before delete quantity discounts'); } $qD = new QuantityDiscount(); } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } elseif (Tools::isSubmit('submitCustomizationConfiguration')) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) { if (!$product->createLabels(intval($_POST['uploadable_files']) - intval($product->uploadable_files), intval($_POST['text_fields']) - intval($product->text_fields))) { $this->_errors[] = Tools::displayError('an error occured while creating customization fields'); } if (!sizeof($this->_errors) and !$product->updateLabels()) { $this->_errors[] = Tools::displayError('an error occured while updating customization'); } $product->uploadable_files = intval($_POST['uploadable_files']); $product->text_fields = intval($_POST['text_fields']); $product->customizable = (intval($_POST['uploadable_files']) > 0 or intval($_POST['text_fields']) > 0) ? 1 : 0; if (!sizeof($this->_errors) and !$product->update()) { $this->_errors[] = Tools::displayError('an error occured while updating customization configuration'); } if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=4&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('product must be created before adding customization possibilities'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.'); } } elseif (Tools::isSubmit('submitProductCustomization')) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) { foreach ($_POST as $field => $value) { if (strncmp($field, 'label_', 6) == 0 and !Validate::isLabel($value)) { $this->_errors[] = Tools::displayError('label fields are invalid'); } } if (!sizeof($this->_errors) and !$product->updateLabels()) { $this->_errors[] = Tools::displayError('an error occured while updating customization'); } if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=4&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('product must be created before adding customization possibilities'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.'); } } elseif (isset($_GET['delete' . $this->table])) { if ($this->tabAccess['delete'] === '1') { if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) { if (!$this->deleteImage($product->id)) { $this->_errors[] = Tools::displayError('an error occurred during product image deletion'); } if ($product->delete()) { Tools::redirectAdmin($currentIndex . '&id_category=' . intval(Tools::getValue('id_category')) . '&conf=1&token=' . ($token ? $token : $this->token)); } $this->_errors[] = Tools::displayError('an error occurred during product deletion'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } else { parent::postProcess(true); } }
public function postProduct($iId, $type, $id_attribute = 0, $title = '', $overrideCategories = false) { $mResult = false; $product = new Product((int) $iId, true, (int) $this->_configuration['FBWALLPOSTS_LANG_ID']); if ($product && Validate::isLoadedObject($product)) { // use case - post in FB now for active product or forced product if ($product->active || $overrideCategories) { if (!$overrideCategories) { if (!$this->productIsInModuleCategories((int) $product->id)) { return $mResult; } } if (version_compare(_PS_VERSION_, '1.5', '>')) { $link = Context::getContext()->link; } else { $link = new Link(); } /* Image */ $image = Image::getCover((int) $product->id); if ($image) { if ($this->_configuration['FBWALLPOSTS_IMG_SIZE']) { $image_link = $link->getImageLink($product->link_rewrite, (int) $product->id . '-' . (int) $image['id_image'], $this->_configuration['FBWALLPOSTS_IMG_SIZE']); } else { $image_link = $link->getImageLink($product->link_rewrite, (int) $product->id . '-' . (int) $image['id_image']); } /* Before version 1.4 */ if (strpos($image_link, 'http://') === FALSE && strpos($image_link, 'https://') === FALSE && version_compare(_PS_VERSION_, '1.4', '<')) { $image_link = 'http://' . $_SERVER['HTTP_HOST'] . $image_link; } } else { $image_link = false; } /* Product URL */ $category = new Category((int) $product->id_category_default, (int) $this->_configuration['FBWALLPOSTS_LANG_ID']); if (version_compare(_PS_VERSION_, '1.5.5', '>=')) { $product_url = $link->getProductLink((int) $product->id, null, null, null, (int) $this->_configuration['FBWALLPOSTS_LANG_ID'], null, 0, false); } elseif (version_compare(_PS_VERSION_, '1.5', '>')) { if (Configuration::get('PS_REWRITING_SETTINGS')) { $product_url = $link->getProductLink((int) $product->id, null, null, null, (int) $this->_configuration['FBWALLPOSTS_LANG_ID'], null, 0, true); } else { $product_url = $link->getProductLink((int) $product->id, null, null, null, (int) $this->_configuration['FBWALLPOSTS_LANG_ID'], null, 0, false); } } else { $product_url = $link->getProductLink((int) $product->id, $product->link_rewrite, $category->link_rewrite, $product->ean13, (int) $this->_configuration['FBWALLPOSTS_LANG_ID']); } /* Product description */ $product_description = strip_tags($product->{$this->_configuration['FBWALLPOSTS_P_DESCR_TYPE']}); if ($type == 'free') { $mResult = $this->createFBPost($title, $product->name, $product_url, $product_description, $image_link); } elseif ($type == 'new') { $mResult = $this->createFBPost($this->_configuration['FBWALLPOSTS_NEW_PROD_TXT'], $product->name, $product_url, $product_description, $image_link); } elseif ($type == 'stock' && (int) $id_attribute == 0) { $this->deleteProductFromOOS((int) $product->id, 0); $mResult = $this->createFBPost($this->_configuration['FBWALLPOSTS_STOCK_PROD_TXT'], $product->name, $product_url, $product_description, $image_link); } elseif ($type == 'stock' && (int) $id_attribute != 0) { // Version 1.x to 1.4 if (version_compare(_PS_VERSION_, '1.5', '<')) { /* Attribute names */ if (Tools::getValue('attribute_combinaison_list') || Tools::getValue('attribute_combination_list')) { if (Tools::getValue('attribute_combinaison_list')) { $combo_list = Tools::getValue('attribute_combinaison_list'); } elseif (Tools::getValue('attribute_combination_list')) { $combo_list = Tools::getValue('attribute_combination_list'); } $attributes_txt = ' -'; $combo_labels = $this->getProductComboAttributes($combo_list, (int) $this->_configuration['FBWALLPOSTS_LANG_ID']); if ($combo_labels && is_array($combo_labels) && sizeof($combo_labels)) { foreach ($combo_labels as $c) { $attributes_txt .= ' ' . stripslashes($c['name']); } } } else { $attributes_txt = ''; } } else { /* Attribute names */ $attributes_txt = ' -'; $combination = new Combination((int) $id_attribute); $combo_labels = $combination->getAttributesName((int) $this->_configuration['FBWALLPOSTS_LANG_ID']); if ($combo_labels && is_array($combo_labels) && sizeof($combo_labels)) { foreach ($combo_labels as $c) { $attributes_txt .= ' ' . stripslashes($c['name']); } } else { $attributes_txt = ''; } } $this->deleteProductFromOOS((int) $product->id, (int) $id_attribute); $mResult = $this->createFBPost($this->_configuration['FBWALLPOSTS_STOCK_PROD_TXT'], $product->name . $attributes_txt, $product_url, $product_description, $image_link); } } } unset($product); return $mResult; }