/** * Delete a product attribute * * @param int $idAttribute The attribute ID * @param int $idProduct The product ID * * @return array */ public function ajaxProcessDeleteProductAttribute($idAttribute, $idProduct) { if (!\CombinationCore::isFeatureActive()) { return false; } if ($idProduct && \ValidateCore::isUnsignedId($idProduct) && \ValidateCore::isLoadedObject($product = new \ProductCore($idProduct))) { if (($depends_on_stock = \StockAvailableCore::dependsOnStock($idProduct)) && \StockAvailableCore::getQuantityAvailableByProduct($idProduct, $idAttribute)) { return array('status' => 'error', 'message' => 'It is not possible to delete a combination while it still has some quantities in the Advanced Stock Management. You must delete its stock first.'); } else { $product->deleteAttributeCombination((int) $idAttribute); $product->checkDefaultAttributes(); \ToolsCore::clearColorListCache((int) $product->id); if (!$product->hasAttributes()) { $product->cache_default_attribute = 0; $product->update(); } else { \ProductCore::updateDefaultAttribute($idProduct); } if ($depends_on_stock && !\StockCore::deleteStockByIds($idProduct, $idAttribute)) { return array('status' => 'error', 'message' => 'Error while deleting the stock'); } else { return array('status' => 'ok', 'message' => 'Successful deletion'); } } } else { return array('status' => 'error', 'message' => 'You cannot delete this attribute.'); } }
public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null) { parent::__construct($id_product, $full, $id_lang, $id_shop, $context); if (self::$amend) { $this->amend($full && $this->id); } }
function disableDeletedProducts(){ global $webService, $product_added; $allproducts= ProductCore::getAllProductsIdAddedByWebservice(); //var_dump($allproducts); try { $opt = array('resource' => 'products'); $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/products/'.'322')); $resources = $xml->children()->children(); unset($resources->manufacturer_name); unset($resources->quantity); $resources->active = 0; $resources->id=322; $opt['putXml'] = $xml->asXML(); $opt['id'] = 322; $xml = $webService->edit($opt); } catch (PrestaShopWebserviceException $e) { // Here we are dealing with errors $trace = $e->getTrace(); if ($trace[0]['args'][0] == 404) echo 'Bad ID'; else if ($trace[0]['args'][0] == 401) echo 'Bad auth key'; else echo 'Other error<br />'.$e->getMessage(); } }
public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null) { parent::__construct($id_product, $full, $id_lang, $id_shop, $context); require_once _PS_MODULE_DIR_ . "ag_viewhelper/ag_viewhelper.php"; $this->description = ag_viewhelper::getHtmlCode($this->description); $this->description_short = ag_viewhelper::getHtmlCode($this->description_short); }
public static function checkAccessStatic($id_product, $id_customer) { if (!egms_shop::getEgmsAccess($id_product)) { return false; } return parent::checkAccessStatic($id_product, $id_customer); /* if (!Group::isFeatureActive()) return true; $cache_id = 'Product::checkAccess_'.(int)$id_product.'-'.(int)$id_customer.(!$id_customer ? '-'.(int)Group::getCurrent()->id : ''); if (!Cache::isStored($cache_id)) { if (!$id_customer) $result = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT ctg.`id_group` FROM `'._DB_PREFIX_.'category_product` cp INNER JOIN `'._DB_PREFIX_.'category_group` ctg ON (ctg.`id_category` = cp.`id_category`) WHERE cp.`id_product` = '.(int)$id_product.' AND ctg.`id_group` = '.(int)Group::getCurrent()->id); else $result = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT cg.`id_group` FROM `'._DB_PREFIX_.'category_product` cp INNER JOIN `'._DB_PREFIX_.'category_group` ctg ON (ctg.`id_category` = cp.`id_category`) INNER JOIN `'._DB_PREFIX_.'customer_group` cg ON (cg.`id_group` = ctg.`id_group`) WHERE cp.`id_product` = '.(int)$id_product.' AND cg.`id_customer` = '.(int)$id_customer); Cache::store($cache_id, $result); } return Cache::retrieve($cache_id); */ }
/** * Permet d'ajouter des propriété supplémentaires * @param $id_lang * @param $query_result * @return array * @module now_product_type */ public static function getProductsProperties($id_lang, $query_result) { $products = parent::getProductsProperties($id_lang, $query_result); require_once _PS_MODULE_DIR_ . 'now_product_type/classes/NowProductType.php'; require_once _PS_MODULE_DIR_ . 'now_product_type/classes/NowProductTypeProduct.php'; if ((int) count($products) > 0) { $aProductsTypesProducts = NowProductTypeProduct::getProductsById(); $aProductsTypes = NowProductType::getByIdProductTypes($aProductsTypesProducts); foreach ($products as &$aProduct) { if (array_key_exists($aProduct['id_product'], $aProductsTypesProducts) && array_key_exists($aProductsTypesProducts[$aProduct['id_product']], $aProductsTypes)) { $aProduct['product_type'] = $aProductsTypes[$aProductsTypesProducts[$aProduct['id_product']]]; } } } return $products; }
/** * Get all features, which has values for product * * @param int $is_lang Language on which we should return labels and values of features * @param bool $withGroups whether we should return features with groups or not * @return array of features. @see parent::getFrontFeatures() */ public function getFrontFeatures($id_lang, $withGroups = true) { if (!$withGroups) { return parent::getFrontFeatures($id_lang); } $id_product = $this->id; if (!array_key_exists($this->id . '-' . $id_lang, self::$_frontFeaturesCache)) { self::$_frontFeaturesCache[$this->id . '-' . $id_lang] = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT fl.name AS feature_name, value, pf.id_feature, fgl.id_group, fgl.name AS feature_group_name, fg.position AS group_position, f.position AS feature_position FROM ' . _DB_PREFIX_ . 'feature_product pf LEFT JOIN ' . _DB_PREFIX_ . 'feature f ON pf.id_feature=f.id_feature LEFT JOIN ' . _DB_PREFIX_ . 'feature_group fg ON f.id_group=fg.id_group LEFT JOIN ' . _DB_PREFIX_ . 'feature_group_lang fgl ON (fg.id_group=fgl.id_group AND fgl.id_lang = ' . (int) $id_lang . ') LEFT JOIN ' . _DB_PREFIX_ . 'feature_lang fl ON (fl.id_feature = pf.id_feature AND fl.id_lang = ' . (int) $id_lang . ') LEFT JOIN ' . _DB_PREFIX_ . 'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = ' . (int) $id_lang . ') WHERE pf.id_product = ' . intval($this->id)); } $result = array(); foreach (self::$_frontFeaturesCache[$id_product . '-' . $id_lang] as $frecord) { if (!$frecord['id_group'] || !$frecord['id_feature']) { continue; } if (!array_key_exists($frecord["id_group"], $result)) { $result[$frecord["id_group"]] = array("name" => $frecord['feature_group_name'], "position" => $frecord["group_position"], 'features' => array()); } $result[$frecord['id_group']]['features'][$frecord['id_feature']] = array("name" => $frecord['feature_name'], "position" => $frecord["feature_position"], 'value' => $frecord["value"]); } uasort($result, array($this, 'sortFeaturesGroupsByPositionCallback')); foreach ($result as $group_id => &$group_data) { uasort($group_data["features"], array($this, 'sortFeaturesByPositionCallback')); } return $result; }
/** * prepare attribute groups * * @return array */ protected function prepareAttributeGroups() { $result = array(); if ($this->currentProduct->hasAttributes()) { //function getAttributesInformationsByProduct available from version 1.5.0.1 if (version_compare(_PS_VERSION_, '1.5.0.1', '<')) { $attributes = BWProduct::getAttributesInformationsByProduct($this->currentProduct->id, $this->getPlugin()->getLanguageId()); } else { $attributes = Product::getAttributesInformationsByProduct($this->currentProduct->id); } $addedGroup = array(); foreach ($attributes as $attribute) { if (!in_array($attribute['id_attribute_group'], $addedGroup)) { $attributeItem = new Shopgate_Model_Catalog_AttributeGroup(); $attributeItem->setUid($attribute['id_attribute_group']); $attributeItem->setLabel($attribute['group']); $result[] = $attributeItem; $addedGroup[] = $attribute['id_attribute_group']; } } } return $result; }
function deleteDeletedProducts(){ global $webService, $product_added; $allproducts= ProductCore::getAllProductsId(); //var_dump($product_added); try { foreach($allproducts as $product){ if (!in_array($product['id_product'], $product_added)) { $opt = array('resource' => 'products'); $opt['id'] = $product['id_product']; $xml = $webService->delete($opt); } } } catch (PrestaShopWebserviceException $e) { // Here we are dealing with errors $trace = $e->getTrace(); if ($trace[0]['args'][0] == 404) echo 'Bad ID'; else if ($trace[0]['args'][0] == 401) echo 'Bad auth key'; else echo 'Other error<br />'.$e->getMessage(); } }
/** * Returns the absolute product image url of the primary image. * * @param Product|ProductCore $product the product model. * @param Link|LinkCore $link optional link instance to use instead of the one in current context. * @return string the url or empty string if could not be generated. */ public function getProductImageUrl($product, $link = null) { if (is_null($link)) { $link = Context::getContext()->link; } $image_id = $product->getCoverWs(); if ((int) $image_id > 0) { $image_type = $this->chooseOptimalImageType(); if (!empty($image_type)) { return $link->getImageLink($product->link_rewrite, $product->id . '-' . $image_id, $image_type); } } return ''; }
public function duplicateProduct($productId, $namePattern = 'copy of %s') { //TODO : use the $namePattern var to input translated version of 'copy of %s', if translation requested. $product = new \ProductCore($productId); if (!\ValidateCore::isLoadedObject($product)) { throw new \Exception('AdminProductDataUpdater->duplicateProduct() received an unknown ID.', 5005); } $id_product_old = $product->id; if (empty($product->price) && \ShopCore::getContext() == \ShopCore::CONTEXT_GROUP) { $shops = \ShopGroupCore::getShopsFromGroup(\ShopCore::getContextShopGroupID()); foreach ($shops as $shop) { if ($product->isAssociatedToShop($shop['id_shop'])) { $product_price = new \ProductCore($id_product_old, false, null, $shop['id_shop']); $product->price = $product_price->price; } } } unset($product->id); unset($product->id_product); $product->indexed = 0; $product->active = 0; // change product name to prefix it foreach ($product->name as $langKey => $oldName) { if (!preg_match('/^' . str_replace('%s', '.*', preg_quote($namePattern, '/') . '$/'), $oldName)) { $newName = sprintf($namePattern, $oldName); if (mb_strlen($newName, 'UTF-8') <= 127) { $product->name[$langKey] = $newName; } } } if ($product->add() && \CategoryCore::duplicateProductCategories($id_product_old, $product->id) && \ProductCore::duplicateSuppliers($id_product_old, $product->id) && ($combination_images = \ProductCore::duplicateAttributes($id_product_old, $product->id)) !== false && \GroupReductionCore::duplicateReduction($id_product_old, $product->id) && \ProductCore::duplicateAccessories($id_product_old, $product->id) && \ProductCore::duplicateFeatures($id_product_old, $product->id) && \ProductCore::duplicateSpecificPrices($id_product_old, $product->id) && \PackCore::duplicate($id_product_old, $product->id) && \ProductCore::duplicateCustomizationFields($id_product_old, $product->id) && \ProductCore::duplicateTags($id_product_old, $product->id) && \ProductCore::duplicateDownload($id_product_old, $product->id)) { if ($product->hasAttributes()) { \ProductCore::updateDefaultAttribute($product->id); } if (!\Image::duplicateProductImages($id_product_old, $product->id, $combination_images)) { throw new DataUpdateException('product', $id_product_old, 'An error occurred while copying images.', 5008); } else { $this->hookDispatcher->dispatchForParameters('actionProductAdd', array('id_product' => (int) $product->id, 'product' => $product)); if (in_array($product->visibility, array('both', 'search')) && \Configuration::get('PS_SEARCH_INDEXATION')) { \SearchCore::indexation(false, $product->id); } return $product->id; } } else { throw new \Exception('An error occurred while creating an object.', 5009); } }
/** * {@inheritdoc} */ public function getCatalogProductList($offset, $limit, $orderBy, $sortOrder, $post = array(), $avoidPersistence = false, $formatCldr = true) { $filterParams = $this->combinePersistentCatalogProductFilter(array_merge($post, ['last_offset' => $offset, 'last_limit' => $limit, 'last_orderBy' => $orderBy, 'last_sortOrder' => $sortOrder]), $avoidPersistence); $filterParams = AdminFilter::sanitizeFilterParameters($filterParams); $showPositionColumn = $this->isCategoryFiltered(); if ($orderBy == 'position_ordering' && $showPositionColumn) { foreach ($filterParams as $key => $param) { if (strpos($key, 'filter_column_') === 0) { $filterParams[$key] = ''; } } } if ($orderBy == 'position_ordering') { $orderBy = 'position'; } $idShop = \ContextCore::getContext()->shop->id; $idLang = \ContextCore::getContext()->language->id; $sqlSelect = array('id_product' => array('table' => 'p', 'field' => 'id_product', 'filtering' => ' %s '), 'reference' => array('table' => 'p', 'field' => 'reference', 'filtering' => self::FILTERING_LIKE_BOTH), 'price' => array('table' => 'p', 'field' => 'price', 'filtering' => ' %s '), 'id_shop_default' => array('table' => 'p', 'field' => 'id_shop_default'), 'is_virtual' => array('table' => 'p', 'field' => 'is_virtual'), 'name' => array('table' => 'pl', 'field' => 'name', 'filtering' => self::FILTERING_LIKE_BOTH), 'active' => array('table' => 'sa', 'field' => 'active', 'filtering' => self::FILTERING_EQUAL_NUMERIC), 'shopname' => array('table' => 'shop', 'field' => 'name'), 'id_image' => array('table' => 'image_shop', 'field' => 'id_image'), 'name_category' => array('table' => 'cl', 'field' => 'name', 'filtering' => self::FILTERING_LIKE_BOTH), 'price_final' => '0', 'nb_downloadable' => array('table' => 'pd', 'field' => 'nb_downloadable'), 'sav_quantity' => array('table' => 'sav', 'field' => 'quantity', 'filtering' => ' %s '), 'badge_danger' => array('select' => 'IF(sav.`quantity`<=0, 1, 0)', 'filtering' => 'IF(sav.`quantity`<=0, 1, 0) = %s')); $sqlTable = array('p' => 'product', 'pl' => array('table' => 'product_lang', 'join' => 'LEFT JOIN', 'on' => 'pl.`id_product` = p.`id_product` AND pl.`id_lang` = ' . $idLang . ' AND pl.`id_shop` = ' . $idShop), 'sav' => array('table' => 'stock_available', 'join' => 'LEFT JOIN', 'on' => 'sav.`id_product` = p.`id_product` AND sav.`id_product_attribute` = 0 AND sav.id_shop = ' . $idShop), 'sa' => array('table' => 'product_shop', 'join' => 'JOIN', 'on' => 'p.`id_product` = sa.`id_product` AND sa.id_shop = ' . $idShop), 'cl' => array('table' => 'category_lang', 'join' => 'LEFT JOIN', 'on' => 'sa.`id_category_default` = cl.`id_category` AND cl.`id_lang` = ' . $idLang . ' AND cl.id_shop = ' . $idShop), 'c' => array('table' => 'category', 'join' => 'LEFT JOIN', 'on' => 'c.`id_category` = cl.`id_category`'), 'shop' => array('table' => 'shop', 'join' => 'LEFT JOIN', 'on' => 'shop.id_shop = ' . $idShop), 'image_shop' => array('table' => 'image_shop', 'join' => 'LEFT JOIN', 'on' => 'image_shop.`id_product` = p.`id_product` AND image_shop.`cover` = 1 AND image_shop.id_shop = ' . $idShop), 'i' => array('table' => 'image', 'join' => 'LEFT JOIN', 'on' => 'i.`id_image` = image_shop.`id_image`'), 'pd' => array('table' => 'product_download', 'join' => 'LEFT JOIN', 'on' => 'pd.`id_product` = p.`id_product`')); $sqlWhere = array('AND', 1); foreach ($filterParams as $filterParam => $filterValue) { if (!$filterValue && $filterValue !== '0') { continue; } if (strpos($filterParam, 'filter_column_') === 0) { $filterValue = \Db::getInstance()->escape($filterValue, in_array($filterParam, ['filter_column_id_product', 'filter_column_sav_quantity', 'filter_column_price']), true); $field = substr($filterParam, 14); // 'filter_column_' takes 14 chars if (isset($sqlSelect[$field]['table'])) { $sqlWhere[] = $sqlSelect[$field]['table'] . '.`' . $sqlSelect[$field]['field'] . '` ' . sprintf($sqlSelect[$field]['filtering'], $filterValue); } else { $sqlWhere[] = '(' . sprintf($sqlSelect[$field]['filtering'], $filterValue) . ')'; } } // for 'filter_category', see next if($showPositionColumn) block. } $sqlWhere[] = 'state = ' . \Product::STATE_SAVED; $sqlOrder = array($orderBy . ' ' . $sortOrder); if ($orderBy != 'id_product') { $sqlOrder[] = 'id_product asc'; // secondary order by (useful when ordering by active, quantity, price, etc...) } $sqlLimit = $offset . ', ' . $limit; // Column 'position' added if filtering by category if ($showPositionColumn) { $filteredCategoryId = (int) $filterParams['filter_category']; $sqlSelect['position'] = array('table' => 'cp', 'field' => 'position'); $sqlTable['cp'] = array('table' => 'category_product', 'join' => 'INNER JOIN', 'on' => 'cp.`id_product` = p.`id_product` AND cp.`id_category` = ' . $filteredCategoryId); } elseif ($orderBy == 'position') { // We do not show position column, so we do not join the table, so we do not order by position! $sqlOrder = array('id_product ASC'); } // exec legacy hook but with different parameters (retro-compat < 1.7 is broken here) \HookCore::exec('actionAdminProductsListingFieldsModifier', array('_ps_version' => _PS_VERSION_, 'sql_select' => &$sqlSelect, 'sql_table' => &$sqlTable, 'sql_where' => &$sqlWhere, 'sql_order' => &$sqlOrder, 'sql_limit' => &$sqlLimit)); $sql = $this->compileSqlQuery($sqlSelect, $sqlTable, $sqlWhere, $sqlOrder, $sqlLimit); $products = \Db::getInstance()->executeS($sql, true, false); $total = \Db::getInstance()->executeS('SELECT FOUND_ROWS();', true, false); $total = $total[0]['FOUND_ROWS()']; // post treatment $currency = new \CurrencyCore(\Configuration::get('PS_CURRENCY_DEFAULT')); foreach ($products as &$product) { $product['total'] = $total; // total product count (filtered) $product['price_final'] = \ProductCore::getPriceStatic($product['id_product'], true, null, (int) \Configuration::get('PS_PRICE_DISPLAY_PRECISION'), null, false, true, 1, true, null, null, null, $nothing, true, true); if ($formatCldr) { $product['price'] = \ToolsCore::displayPrice($product['price'], $currency); $product['price_final'] = \ToolsCore::displayPrice($product['price_final'], $currency); } $product['image'] = $this->imageManager->getThumbnailForListing($product['id_image']); } // post treatment by hooks // exec legacy hook but with different parameters (retro-compat < 1.7 is broken here) \HookCore::exec('actionAdminProductsListingResultsModifier', array('_ps_version' => _PS_VERSION_, 'products' => &$products, 'total' => $total)); return $products; }
public static function getSpecificPrice($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity, $id_product_attribute = null, $id_customer = 0, $id_cart = 0, $real_quantity = 0) { if (!SpecificPrice::isFeatureActive()) { return array(); } /* ** The date is not taken into account for the cache, but this is for the better because it keeps the consistency for the whole script. ** The price must not change between the top and the bottom of the page */ $key = (int) $id_product . '-' . (int) $id_shop . '-' . (int) $id_currency . '-' . (int) $id_country . '-' . (int) $id_group . '-' . (int) $quantity . '-' . (int) $id_product_attribute . '-' . (int) $id_cart . '-' . (int) $id_customer . '-' . (int) $real_quantity; if (!array_key_exists($key, SpecificPrice::$_specificPriceCache)) { $now = date('Y-m-d H:i:s'); $query = ' SELECT *, ' . SpecificPrice::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group, $id_customer) . ' FROM `' . _DB_PREFIX_ . 'specific_price` WHERE `id_product` IN (0, ' . (int) $id_product . ') AND `id_product_attribute` IN (0, ' . (int) $id_product_attribute . ') AND `id_shop` IN (0, ' . (int) $id_shop . ') AND `id_currency` IN (0, ' . (int) $id_currency . ') AND `id_country` IN (0, ' . (int) $id_country . ') AND `id_group` IN (0, ' . (int) $id_group . ') AND `id_customer` IN (0, ' . (int) $id_customer . ') AND ( (`from` = \'0000-00-00 00:00:00\' OR \'' . $now . '\' >= `from`) AND (`to` = \'0000-00-00 00:00:00\' OR \'' . $now . '\' <= `to`) ) AND id_cart IN (0, ' . (int) $id_cart . ') AND IF(`from_quantity` > 1, `from_quantity`, 0) <= '; $query .= Configuration::get('PS_QTY_DISCOUNT_ON_COMBINATION') || !$id_cart || !$real_quantity ? (int) $quantity : max(1, (int) $real_quantity); $query .= ' ORDER BY `id_product_attribute` DESC, `from_quantity` DESC, `id_specific_price_rule` ASC, `score` DESC'; SpecificPrice::$_specificPriceCache[$key] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($query); $getProductMargin = ProductCore::getProfitMargin($id_product); $getProductMargin = floatval($getProductMargin[0]['profit_margin']); // var_dump($getProductMargin); if ($getProductMargin > 0) { $margin = $getProductMargin; } else { $margin = floatval(Configuration::get('PROFIT_MARGIN')); } $price_type = Configuration::get('PRODUCT_DYNAMIC_PRICE'); if (isset($margin) && $price_type == 1) { if (isset(SpecificPrice::$_specificPriceCache[$key]['reduction'])) { $reduction = SpecificPrice::$_specificPriceCache[$key]['reduction']; $original_price = SpecificPrice::$_specificPriceCache[$key]['price']; $price_with_discount = $original_price - $reduction; $margin1 = floatval($margin) / 100; $margin1 = 1 - $margin1; $original_price = $original_price / $margin1; $price_with_discount = $price_with_discount / $margin1; SpecificPrice::$_specificPriceCache[$key]['reduction'] = $original_price - $price_with_discount; } if (isset(SpecificPrice::$_specificPriceCache[$key]['price'])) { $price = SpecificPrice::$_specificPriceCache[$key]['price']; $margin = floatval($margin) / 100; $margin = 1 - $margin; $price = $price / $margin; SpecificPrice::$_specificPriceCache[$key]['price'] = $price; } } } return SpecificPrice::$_specificPriceCache[$key]; }
public function update($null_values = false) { $res = parent::update($null_values); if (Module::isInstalled('agilesellerlistoptions') and $res) { require_once _PS_ROOT_DIR_ . "/modules/agilesellerlistoptions/agilesellerlistoptions.php"; $aslo = new AgileSellerListOptions(); $aslo->processProductExtenstions(array('product' => $this)); } return $res; }
if (!isset($resources->date_add) || empty($resources->date_add)) $resources->date_add = date('Y-m-d H:i:s'); $resources->date_upd = date('Y-m-d H:i:s'); try { $opt = array('resource' => 'products'); if ($_GET['Create'] == 'Creating') { $opt['postXml'] = $xml->asXML(); $xml = $webService->add($opt); set_price_rule($xml->product->id, $product_xml->ItemNumber, $list); save_product_combination($xml->product->id, $product_xml->ItemNumber,$list, $decoration,$product_xml->Color); ProductCore::addCustomField($xml->product->id,1,0,1,'Upload Logo'); ProductCore::addAttachments($xml->product->id, 1); ProductCore::updateCacheAttachment((int)$xml->product->id); echo "Successfully added."; } } catch (PrestaShopWebserviceException $ex) { // Here we are dealing with errors $trace = $ex->getTrace(); if ($trace[0]['args'][0] == 404) echo 'Bad ID'; else if ($trace[0]['args'][0] == 401) echo 'Bad auth key'; else echo 'Other error<br />'.$ex->getMessage(); } } } catch (PrestaShopWebserviceException $e) {
/** * Get product quantity * * @param int $id_product * @param int|null $id_product_attribute * @param bool|null $cache_is_pack * * @return int stock */ public function getQuantity($id_product, $id_product_attribute = null, $cache_is_pack = null) { return \ProductCore::getQuantity($id_product, $id_product_attribute, $cache_is_pack); }
public static function getProductProperties($id_lang, $row, Context $context = null) { /* * EU-Legal * get standard shipping time from database pl. */ if (!$row['id_product']) { return false; } $row = parent::getProductProperties($id_lang, $row, $context); /* * EU-Legal * get standard shipping time from database */ $row['delivery_now'] = !empty($row['delivery_now']) ? $row['delivery_now'] : Configuration::get('LEGAL_DELIVERY_NOW', (int) $id_lang); $row['delivery_later'] = !empty($row['delivery_later']) ? $row['delivery_later'] : Configuration::get('LEGAL_DELIVERY_LATER', (int) $id_lang); return $row; }
public function hookOrderConfirmation($params) { $context = Context::getContext(); $id_card = $context->cart->id; $id_order = Order::getOrderByCartId(intval($id_cart)); $order = $params['objOrder']; $products = $order->getProducts(); $dl = '<script> $(window).load(function() { window.dataLayer.push({ "ecommerce": { "purchase": { "actionField": { "id" : "' . $order->id . '", }, "products": ['; foreach ($products as $product) { //id_manufacturer //id_category_default //product_attribute_id $price = $product['total_price']; $revenue = $price / 100 * 20; $brand = ManufacturerCore::getNameById($product['id_manufacturer']); $name = ProductCore::getProductName($product['product_id']); $category = CategoryCore::getUrlRewriteInformations($product['id_category_default']); $variant = $this->getAttributeName($product['product_attribute_id']); $dl .= '{ "id": "' . $product['product_id'] . '", "name": "' . $name . '", "price": ' . $price . ', "brand": "' . $brand . '", "category": "' . $category[0]['link_rewrite'] . '", "variant": "' . $variant . '", "quantity": ' . $product['product_quantity'] . ', "revenue": ' . $revenue . ', "shipping": ' . $order->total_shipping . ' },'; } $dl .= '] } } }); '; foreach ($products as $product) { $price = $product['total_price']; $revenue = $price / 100 * 20; $name = ProductCore::getProductName($product['product_id']); $category = CategoryCore::getUrlRewriteInformations($product['id_category_default']); $brand = ManufacturerCore::getNameById($product['id_manufacturer']); $variant = $this->getAttributeName($product['product_attribute_id']); $dl .= '/* ga("ec:addProduct", { "id": "' . $product['product_id'] . '", "name": "' . $name . '", "category": "' . $category[0]['link_rewrite'] . '", "brand": "' . $brand . '", "variant": "' . $variant . '", "price": "' . $price . '", "quantity": ' . $product['product_quantity'] . ' }); '; } $dl .= 'ga("ec:setAction", "purchase", { "id" : "' . $order->id . '", "affiliation": location.hosts, "revenue": "' . $order->total_paid_real . '", "shipping": "' . $order->total_shipping . '" }); ga("send", "pageview"); })*/; </script>'; return $dl; }
/** * This method allows to flush price cache * @static * @since 1.5.0 */ public static function flushPriceCache() { self::$_prices = array(); self::$_pricesLevel2 = array(); }
public static function initPricesComputation($id_customer = NULL) { global $cookie; if ($id_customer) { $customer = new Customer((int) $id_customer); if (!Validate::isLoadedObject($customer)) { die(Tools::displayError()); } self::$_taxCalculationMethod = Group::getPriceDisplayMethod((int) $customer->id_default_group); } elseif ($cookie->id_customer) { $customer = new Customer((int) $cookie->id_customer); self::$_taxCalculationMethod = Group::getPriceDisplayMethod((int) $customer->id_default_group); } else { self::$_taxCalculationMethod = Group::getDefaultPriceDisplayMethod(); } }
/** * processProductAttribute * Update a combination * * @param object $product * @param array $combinationValues the posted values * * @return \AdminProductsControllerCore instance */ public function processProductAttribute($product, $combinationValues) { $id_product_attribute = (int) $combinationValues['id_product_attribute']; $images = []; if (!\CombinationCore::isFeatureActive() || $id_product_attribute == 0) { return; } if (!isset($combinationValues['attribute_wholesale_price'])) { $combinationValues['attribute_wholesale_price'] = 0; } if (!isset($combinationValues['attribute_price_impact'])) { $combinationValues['attribute_price_impact'] = 0; } if (!isset($combinationValues['attribute_weight_impact'])) { $combinationValues['attribute_weight_impact'] = 0; } if (!isset($combinationValues['attribute_ecotax'])) { $combinationValues['attribute_ecotax'] = 0; } if (isset($combinationValues['attribute_default']) && $combinationValues['attribute_default'] == 1) { $product->deleteDefaultAttributes(); } if (!empty($combinationValues['id_image_attr'])) { $images = $combinationValues['id_image_attr']; } $product->updateAttribute($id_product_attribute, $combinationValues['attribute_wholesale_price'], $combinationValues['attribute_price'] * $combinationValues['attribute_price_impact'], $combinationValues['attribute_weight'] * $combinationValues['attribute_weight_impact'], $combinationValues['attribute_unity'] * $combinationValues['attribute_unit_impact'], $combinationValues['attribute_ecotax'], $images, $combinationValues['attribute_reference'], $combinationValues['attribute_ean13'], isset($combinationValues['attribute_default']) && $combinationValues['attribute_default'] == 1, isset($combinationValues['attribute_location']) ? $combinationValues['attribute_location'] : null, $combinationValues['attribute_upc'], $combinationValues['attribute_minimal_quantity'], $combinationValues['available_date_attribute'], false, array(), $combinationValues['attribute_isbn']); \StockAvailableCore::setProductDependsOnStock((int) $product->id, $product->depends_on_stock, null, $id_product_attribute); \StockAvailableCore::setProductOutOfStock((int) $product->id, $product->out_of_stock, null, $id_product_attribute); $product->checkDefaultAttributes(); if (isset($combinationValues['attribute_default']) && $combinationValues['attribute_default'] == 1) { \ProductCore::updateDefaultAttribute((int) $product->id); if (isset($id_product_attribute)) { $product->cache_default_attribute = (int) $id_product_attribute; } if ($available_date = $combinationValues['available_date_attribute']) { $product->setAvailableDate($available_date); } else { $product->setAvailableDate(); } } $this->processQuantityUpdate($product, $combinationValues['attribute_quantity'], $id_product_attribute); }
* PrestaShop Webservice Library * @package PrestaShopWebservice */ // Here we define constants /!\ You need to replace this parameters require_once('../config/config.inc.php'); require_once('../PSWebServiceLibrary.php'); $count = 1; $product_added=array(); $webservice_exi = new SoapClient('http://www2.promoshop.com.mx/ws_store/service.asmx?WSDL') ; $list = Configuration::get('PRODUCTUPDATE_LIST'); // Here we use the WebService to get the schema of "customers" resource Configuration::updateValue('PRODUCTUPDATE_STATUS', '0'); $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); $count=1; $allproducts= ProductCore::getAllProductsInfoAddedByWebservice(); foreach($allproducts as $product){ $parameter = array("ItemNumber"=>$product['reference'], "key"=>EXIMAGEN_KEY); $decoration = $webservice_exi->GetDecoration($parameter); $decoration = $decoration->GetDecorationResult; save_product_combination($product['id_product'], $product['reference'],$list, $decoration); $count++; Configuration::updateValue('PRODUCTUPDATE_STATUS', $count/4); } Configuration::updateValue('PRODUCTUPDATE_STATUS', 100); function set_product_quantity($ProductId, $StokId, $AttributeId, $quantity, $intransit, $intransit_avail_date, $color_id){ global $webService; $xml = $webService -> get(array('url' => PS_SHOP_PATH . '/api/stock_availables?schema=blank')); $resources = $xml -> children() -> children();
public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null) { parent::__construct($id_product, $id_lang, $id_shop); self::$definition['fields'] = array('auteur' => array('type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 255), 'date_de_parution' => array('type' => self::TYPE_DATE, 'shop' => true, 'validate' => 'isDateFormat'), 'dimension' => array('type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 50), 'editeur' => array('type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 255), 'page' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId')); }
public function getAccessories($id_lang, $active = true, Context $context = null) { if (!isset(Context::getContext()->accessories_displayed)) { return parent::getAccessories($id_lang, $active, $context); } }
/** * Returns the product attribute combination by id_product_attribute. * * For PS 1.4 we need to query the combinations manually, while newer version of PS provide a handy getter. * * @param Product|ProductCore $product the product model. * @param int $id_product_attribute the product attribute ID. * @param int $id_lang the language ID. * @return array the attribute combinations. */ protected function getProductAttributeCombinationsById($product, $id_product_attribute, $id_lang) { if (_PS_VERSION_ >= '1.5') { return $product->getAttributeCombinationsById($id_product_attribute, $id_lang); } return Db::getInstance()->ExecuteS(' SELECT pa.*, ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` group_name, al.`name` attribute_name, a.`id_attribute`, pa.`unit_price_impact` FROM `' . _DB_PREFIX_ . 'product_attribute` pa LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute` LEFT JOIN `' . _DB_PREFIX_ . 'attribute` a ON a.`id_attribute` = pac.`id_attribute` LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group` LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = ' . (int) $id_lang . ') LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = ' . (int) $id_lang . ') WHERE pa.`id_product` = ' . (int) $product->id . ' AND pa.`id_product_attribute` = ' . (int) $id_product_attribute . ' GROUP BY pa.`id_product_attribute`, ag.`id_attribute_group` ORDER BY pa.`id_product_attribute`'); }