当前位置: 首页>>代码示例>>PHP>>正文


PHP StockAvailable::getQuantityAvailableByProduct方法代码示例

本文整理汇总了PHP中StockAvailable::getQuantityAvailableByProduct方法的典型用法代码示例。如果您正苦于以下问题:PHP StockAvailable::getQuantityAvailableByProduct方法的具体用法?PHP StockAvailable::getQuantityAvailableByProduct怎么用?PHP StockAvailable::getQuantityAvailableByProduct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StockAvailable的用法示例。


在下文中一共展示了StockAvailable::getQuantityAvailableByProduct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: hookHeader

 public function hookHeader($params)
 {
     $shop_id = $this->getShopId();
     $buttons_code = $this->client->getButtonsCode();
     if (Configuration::get('ADDSHOPPERS_OPENGRAPH') == '1') {
         $this->context->smarty->assign('buttons_opengraph', $buttons_code['buttons']['open-graph']);
     }
     if (Configuration::get('ADDSHOPPERS_BUTTONS') == '1') {
         $this->context->smarty->assign('buttons_social', $buttons_code['buttons']['button2']);
     }
     $id_lang = (int) Tools::getValue('id_lang', (int) Configuration::get('PS_LANG_DEFAULT'));
     $this->context->smarty->assign(array('shop_id' => Tools::safeOutput($shop_id), 'default_account' => $shop_id == $this->client->getDefaultShopId(), 'social' => Tools::safeOutput(Configuration::get('ADDSHOPPERS_BUTTONS')), 'opengraph' => Tools::safeOutput(Configuration::get('ADDSHOPPERS_OPENGRAPH')), 'actual_url' => Tools::safeOutput($this->_getCurrentUrl()), 'absolute_base_url' => Tools::safeOutput($this->_getAbsoluteBaseUrl()), 'id_lang' => (int) $id_lang));
     if (Tools::isSubmit('id_product')) {
         $product = new Product((int) Tools::getValue('id_product'));
         if (Validate::isLoadedObject($product)) {
             $currency = new Currency((int) $this->context->cookie->id_currency);
             $this->context->smarty->assign(array('id_product' => (int) $product->id, 'stock' => isset($product->available_now) ? Tools::safeOutput(AddshoppersClient::WIDGET_STOCK_IN_STOCK) : Tools::safeOutput(AddshoppersClient::WIDGET_STOCK_OUT_OF_STOCK), 'price' => Tools::safeOutput($currency->sign) . number_format((double) $product->getPrice(), 2), 'product_name' => Tools::safeOutput($product->name[$id_lang]), 'product_description' => Tools::safeOutput($product->description[$id_lang]), 'is_product_page' => true));
             $quantity = (int) StockAvailable::getQuantityAvailableByProduct((int) $product->id);
             if ($quantity > 0) {
                 $this->context->smarty->assign('instock', (int) $quantity);
             }
             $images = Image::getImages((int) $id_lang, (int) $product->id);
             if (is_array($images) && isset($images[0])) {
                 $this->context->smarty->assign('id_image', (int) $images[0]['id_image']);
             }
         } else {
             $this->context->smarty->assign('is_product_page', false);
         }
     } else {
         $this->context->smarty->assign('is_product_page', false);
     }
     return $this->display(__FILE__, 'header.tpl');
 }
开发者ID:rtajmahal,项目名称:PrestaShop-modules,代码行数:33,代码来源:addshoppers.php

示例2: getAttributeCombinations

    public function getAttributeCombinations($id_lang)
    {
        if (!Combination::isFeatureActive()) {
            return array();
        }
        $sql = 'SELECT pa.*, product_attribute_shop.*, ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, al.`name` AS attribute_name,
					a.`id_attribute`, pa.`unit_price_impact`
				FROM `' . _DB_PREFIX_ . 'product_attribute` pa
				' . Shop::addSqlAssociation('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) $this->id . '
				GROUP BY pa.`id_product_attribute`, ag.`id_attribute_group`
				ORDER BY pa.`id_product_attribute`';
        $res = Db::getInstance()->executeS($sql);
        //Get quantity of each variations
        foreach ($res as $key => $row) {
            $cache_key = $row['id_product'] . '_' . $row['id_product_attribute'] . '_quantity';
            if (!Cache::isStored($cache_key)) {
                Cache::store($cache_key, StockAvailable::getQuantityAvailableByProduct($row['id_product'], $row['id_product_attribute']));
            }
            $res[$key]['quantity'] = Cache::retrieve($cache_key);
        }
        return $res;
    }
开发者ID:TheTypoMaster,项目名称:neotienda,代码行数:28,代码来源:giveit.php

示例3: ajaxProcessSearchProducts

 public function ajaxProcessSearchProducts()
 {
     Context::getContext()->customer = new Customer((int) Tools::getValue('id_customer'));
     $currency = new Currency((int) Tools::getValue('id_currency'));
     if ($products = Product::searchByName((int) $this->context->language->id, pSQL(Tools::getValue('product_search')))) {
         foreach ($products as &$product) {
             // Formatted price
             $product['formatted_price'] = Tools::displayPrice(Tools::convertPrice($product['price_tax_incl'], $currency), $currency);
             // Concret price
             $product['price_tax_incl'] = Tools::ps_round(Tools::convertPrice($product['price_tax_incl'], $currency), 2);
             $product['price_tax_excl'] = Tools::ps_round(Tools::convertPrice($product['price_tax_excl'], $currency), 2);
             $productObj = new Product((int) $product['id_product'], false, (int) $this->context->language->id);
             $combinations = array();
             $attributes = $productObj->getAttributesGroups((int) $this->context->language->id);
             // Tax rate for this customer
             if (Tools::isSubmit('id_address')) {
                 $product['tax_rate'] = $productObj->getTaxesRate(new Address(Tools::getValue('id_address')));
             }
             $product['warehouse_list'] = array();
             foreach ($attributes as $attribute) {
                 if (!isset($combinations[$attribute['id_product_attribute']]['attributes'])) {
                     $combinations[$attribute['id_product_attribute']]['attributes'] = '';
                 }
                 $combinations[$attribute['id_product_attribute']]['attributes'] .= $attribute['attribute_name'] . ' - ';
                 $combinations[$attribute['id_product_attribute']]['id_product_attribute'] = $attribute['id_product_attribute'];
                 $combinations[$attribute['id_product_attribute']]['default_on'] = $attribute['default_on'];
                 if (!isset($combinations[$attribute['id_product_attribute']]['price'])) {
                     $price_tax_incl = Product::getPriceStatic((int) $product['id_product'], true, $attribute['id_product_attribute']);
                     $price_tax_excl = Product::getPriceStatic((int) $product['id_product'], false, $attribute['id_product_attribute']);
                     $combinations[$attribute['id_product_attribute']]['price_tax_incl'] = Tools::ps_round(Tools::convertPrice($price_tax_incl, $currency), 2);
                     $combinations[$attribute['id_product_attribute']]['price_tax_excl'] = Tools::ps_round(Tools::convertPrice($price_tax_excl, $currency), 2);
                     $combinations[$attribute['id_product_attribute']]['formatted_price'] = Tools::displayPrice(Tools::convertPrice($price_tax_excl, $currency), $currency);
                 }
                 if (!isset($combinations[$attribute['id_product_attribute']]['qty_in_stock'])) {
                     $combinations[$attribute['id_product_attribute']]['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct((int) $product['id_product'], $attribute['id_product_attribute'], (int) $this->context->shop->id);
                 }
                 if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) $product['advanced_stock_management'] == 1) {
                     $product['warehouse_list'][$attribute['id_product_attribute']] = Warehouse::getProductWarehouseList($product['id_product'], $attribute['id_product_attribute']);
                 } else {
                     $product['warehouse_list'][$attribute['id_product_attribute']] = array();
                 }
                 $product['stock'][$attribute['id_product_attribute']] = Product::getRealQuantity($product['id_product'], $attribute['id_product_attribute']);
             }
             if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) $product['advanced_stock_management'] == 1) {
                 $product['warehouse_list'][0] = Warehouse::getProductWarehouseList($product['id_product']);
             } else {
                 $product['warehouse_list'][0] = array();
             }
             $product['stock'][0] = StockAvailable::getQuantityAvailableByProduct((int) $product['id_product'], 0, (int) $this->context->shop->id);
             foreach ($combinations as &$combination) {
                 $combination['attributes'] = rtrim($combination['attributes'], ' - ');
             }
             $product['combinations'] = $combinations;
             if ($product['customizable']) {
                 $product_instance = new Product((int) $product['id_product']);
                 $product['customization_fields'] = $product_instance->getCustomizationFields($this->context->language->id);
             }
         }
         $to_return = array('products' => $products, 'found' => true);
     } else {
         $to_return = array('found' => false);
     }
     $this->content = Tools::jsonEncode($to_return);
 }
开发者ID:,项目名称:,代码行数:64,代码来源:

示例4: getPackageList

 /**
  * Get products grouped by package and by addresses to be sent individualy (one package = one shipping cost).
  *
  * @return array array(
  *                   0 => array( // First address
  *                       0 => array(  // First package
  *                           'product_list' => array(...),
  *                           'carrier_list' => array(...),
  *                           'id_warehouse' => array(...),
  *                       ),
  *                   ),
  *               );
  * @todo Add avaibility check
  */
 public function getPackageList($flush = false)
 {
     static $cache = array();
     if (isset($cache[(int) $this->id . '_' . (int) $this->id_address_delivery]) && $cache[(int) $this->id . '_' . (int) $this->id_address_delivery] !== false && !$flush) {
         return $cache[(int) $this->id . '_' . (int) $this->id_address_delivery];
     }
     $product_list = $this->getProducts();
     // Step 1 : Get product informations (warehouse_list and carrier_list), count warehouse
     // Determine the best warehouse to determine the packages
     // For that we count the number of time we can use a warehouse for a specific delivery address
     $warehouse_count_by_address = array();
     $warehouse_carrier_list = array();
     $stock_management_active = Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT');
     foreach ($product_list as &$product) {
         if ((int) $product['id_address_delivery'] == 0) {
             $product['id_address_delivery'] = (int) $this->id_address_delivery;
         }
         if (!isset($warehouse_count_by_address[$product['id_address_delivery']])) {
             $warehouse_count_by_address[$product['id_address_delivery']] = array();
         }
         $product['warehouse_list'] = array();
         if ($stock_management_active && ((int) $product['advanced_stock_management'] == 1 || Pack::usesAdvancedStockManagement((int) $product['id_product']))) {
             $warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute'], $this->id_shop);
             if (count($warehouse_list) == 0) {
                 $warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute']);
             }
             // Does the product is in stock ?
             // If yes, get only warehouse where the product is in stock
             $warehouse_in_stock = array();
             $manager = StockManagerFactory::getManager();
             foreach ($warehouse_list as $key => $warehouse) {
                 $product_real_quantities = $manager->getProductRealQuantities($product['id_product'], $product['id_product_attribute'], array($warehouse['id_warehouse']), true);
                 if ($product_real_quantities > 0 || Pack::isPack((int) $product['id_product'])) {
                     $warehouse_in_stock[] = $warehouse;
                 }
             }
             if (!empty($warehouse_in_stock)) {
                 $warehouse_list = $warehouse_in_stock;
                 $product['in_stock'] = true;
             } else {
                 $product['in_stock'] = false;
             }
         } else {
             //simulate default warehouse
             $warehouse_list = array(0);
             $product['in_stock'] = StockAvailable::getQuantityAvailableByProduct($product['id_product'], $product['id_product_attribute']) > 0;
         }
         foreach ($warehouse_list as $warehouse) {
             if (!isset($warehouse_carrier_list[$warehouse['id_warehouse']])) {
                 $warehouse_object = new Warehouse($warehouse['id_warehouse']);
                 $warehouse_carrier_list[$warehouse['id_warehouse']] = $warehouse_object->getCarriers();
             }
             $product['warehouse_list'][] = $warehouse['id_warehouse'];
             if (!isset($warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']])) {
                 $warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']] = 0;
             }
             $warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']]++;
         }
     }
     unset($product);
     arsort($warehouse_count_by_address);
     // Step 2 : Group product by warehouse
     $grouped_by_warehouse = array();
     foreach ($product_list as &$product) {
         if (!isset($grouped_by_warehouse[$product['id_address_delivery']])) {
             $grouped_by_warehouse[$product['id_address_delivery']] = array('in_stock' => array(), 'out_of_stock' => array());
         }
         $product['carrier_list'] = array();
         $id_warehouse = 0;
         foreach ($warehouse_count_by_address[$product['id_address_delivery']] as $id_war => $val) {
             if (in_array((int) $id_war, $product['warehouse_list'])) {
                 $product['carrier_list'] = array_merge($product['carrier_list'], Carrier::getAvailableCarrierList(new Product($product['id_product']), $id_war, $product['id_address_delivery'], null, $this));
                 if (!$id_warehouse) {
                     $id_warehouse = (int) $id_war;
                 }
             }
         }
         if (!isset($grouped_by_warehouse[$product['id_address_delivery']]['in_stock'][$id_warehouse])) {
             $grouped_by_warehouse[$product['id_address_delivery']]['in_stock'][$id_warehouse] = array();
             $grouped_by_warehouse[$product['id_address_delivery']]['out_of_stock'][$id_warehouse] = array();
         }
         if (!$this->allow_seperated_package) {
             $key = 'in_stock';
         } else {
             $key = $product['in_stock'] ? 'in_stock' : 'out_of_stock';
         }
//.........这里部分代码省略.........
开发者ID:dev-lav,项目名称:htdocs,代码行数:101,代码来源:Cart.php

示例5: setProductCurrentStock

 /**
  *
  * This method allow to add stock information on a product detail
  *
  * If advanced stock management is active, get physical stock of this product in the warehouse associated to the ptoduct for the current order
  * Else get the available quantity of the product in fucntion of the shop associated to the order
  *
  * @param array &$product
  */
 protected function setProductCurrentStock(&$product)
 {
     if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) $product['advanced_stock_management'] == 1 && (int) $product['id_warehouse'] > 0) {
         $product['current_stock'] = StockManagerFactory::getManager()->getProductPhysicalQuantities($product['product_id'], $product['product_attribute_id'], (int) $product['id_warehouse'], true);
     } else {
         $product['current_stock'] = StockAvailable::getQuantityAvailableByProduct($product['product_id'], $product['product_attribute_id'], (int) $this->id_shop);
     }
 }
开发者ID:TheTypoMaster,项目名称:neotienda,代码行数:17,代码来源:NeoExchanges.php

示例6: formatEntityToXML

 /**
  * Convert the entities data into an xml object and return the xml object as a string
  *
  * @param array $aEntity Entity data
  */
 public function formatEntityToXML($aEntity)
 {
     $sReturn = '';
     $dom = new DOMDocument('1.0', 'utf-8');
     $bUseRoutes = (bool) Configuration::get('PS_REWRITING_SETTINGS');
     $oDispatcher = Dispatcher::getInstance();
     // Force the dispatcher to use custom routes because the use of custom routes is disabled in the BO Context
     foreach ($oDispatcher->default_routes as $route_id => $route_data) {
         if ($custom_route = Configuration::get('PS_ROUTE_' . $route_id)) {
             foreach (Language::getLanguages() as $lang) {
                 $oDispatcher->addRoute($route_id, $custom_route, $route_data['controller'], $lang['id_lang'], $route_data['keywords'], isset($route_data['params']) ? $route_data['params'] : array());
             }
         }
     }
     $oPrediggoConfig = $this->aPrediggoConfigs[(int) $aEntity['id_shop']];
     $link = $oPrediggoConfig->getContext()->link;
     $oProduct = new Product((int) $aEntity['id_product'], true, null, (int) $aEntity['id_shop'], $oPrediggoConfig->getContext());
     if ((int) StockAvailable::getQuantityAvailableByProduct((int) $aEntity['id_product'], 0, (int) $aEntity['id_shop']) < (int) $oPrediggoConfig->export_product_min_quantity) {
         $this->nbEntitiesTreated--;
         $this->nbEntities--;
         return ' ';
     }
     $ps_tax = (int) Configuration::get('PS_TAX');
     foreach ($this->aLanguages as $aLanguage) {
         $id_lang = (int) $aLanguage['id_lang'];
         // Set the root of the XML
         $root = $dom->createElement($this->sEntity);
         $dom->appendChild($root);
         $root->setAttribute('timestamp', (int) strtotime($oProduct->date_add));
         $id = $dom->createElement('id', (int) $oProduct->id);
         $root->appendChild($id);
         $profile = $dom->createElement('profile', (int) $aEntity['id_shop']);
         $root->appendChild($profile);
         $name = $dom->createElement('name');
         $name->appendChild($dom->createCDATASection($oProduct->name[$id_lang]));
         $root->appendChild($name);
         $oCategory = new Category((int) $oProduct->id_category_default);
         $aCategories = $oCategory->getParentsCategories($id_lang);
         if (is_array($aCategories) && count($aCategories) > 0) {
             foreach ($aCategories as $aCategory) {
                 $oCategoryTmp = new Category((int) $aCategory['id_category'], $id_lang);
                 if (!empty($oCategoryTmp->name)) {
                     $genre = $dom->createElement('genre');
                     $genre->appendChild($dom->createCDATASection($oCategoryTmp->name));
                     $root->appendChild($genre);
                 }
                 unset($oCategoryTmp);
             }
         }
         unset($aCategories);
         unset($oCategory);
         if (!empty($oProduct->ean13)) {
             $ean = $dom->createElement('ean');
             $ean->appendChild($dom->createCDATASection($oProduct->ean13));
             $root->appendChild($ean);
         }
         $price = $dom->createElement('price', number_format($oProduct->getPrice($ps_tax), 2, '.', ''));
         $root->appendChild($price);
         if (isset($oProduct->tags[$id_lang]) && ($aTags = $oProduct->tags[$id_lang])) {
             $tag = $dom->createElement('tag');
             $tag->appendChild($dom->createCDATASection(join(',', $aTags)));
             $root->appendChild($tag);
         }
         $sDesc = trim(strip_tags($oProduct->description[$id_lang]));
         if ($oPrediggoConfig->export_product_description && !empty($sDesc)) {
             $description = $dom->createElement('description');
             $description->appendChild($dom->createCDATASection($sDesc));
             $root->appendChild($description);
         }
         if (!empty($oProduct->id_manufacturer)) {
             $supplierid = $dom->createElement('supplierid', (int) $oProduct->id_manufacturer);
             $root->appendChild($supplierid);
         }
         $recommendable = $dom->createElement('recommendable', in_array((int) $oProduct->id, explode(',', $oPrediggoConfig->products_ids_not_recommendable)) ? 'false' : 'true');
         $root->appendChild($recommendable);
         $searchable = $dom->createElement('searchable', in_array((int) $oProduct->id, explode(',', $oPrediggoConfig->products_ids_not_searchable)) ? 'false' : 'true');
         $root->appendChild($searchable);
         // Set product URL
         $attribute = $dom->createElement('attribute');
         $root->appendChild($attribute);
         $attName = $dom->createElement('attName', 'producturl');
         $attribute->appendChild($attName);
         $attValue = $dom->createElement('attValue');
         $attValue->appendChild($dom->createCDATASection($link->getProductLink((int) $oProduct->id, $oProduct->link_rewrite[$id_lang], Category::getLinkRewrite((int) $oProduct->id_category_default, $id_lang), NULL, $id_lang, (int) $aEntity['id_shop'], 0, $bUseRoutes)));
         $attribute->appendChild($attValue);
         // Set product picture
         if ($oPrediggoConfig->export_product_image) {
             $attribute = $dom->createElement('attribute');
             $root->appendChild($attribute);
             $attName = $dom->createElement('attName', 'imageurl');
             $attribute->appendChild($attName);
             $aCover = $oProduct->getCover((int) $oProduct->id);
             $attValue = $dom->createElement('attValue');
             $attValue->appendChild($dom->createCDATASection($link->getImageLink($oProduct->link_rewrite[$id_lang], (int) $aCover['id_image'], 'large')));
             $attribute->appendChild($attValue);
//.........这里部分代码省略.........
开发者ID:ventsiwad,项目名称:presta_addons,代码行数:101,代码来源:ProductExtractorToXML.php

示例7: initFormQuantities

 public function initFormQuantities($obj)
 {
     if (!$this->default_form_language) {
         $this->getLanguages();
     }
     $data = $this->createTemplate($this->tpl_form);
     $data->assign('default_form_language', $this->default_form_language);
     if ($obj->id) {
         if ($this->product_exists_in_shop) {
             // Get all id_product_attribute
             $attributes = $obj->getAttributesResume($this->context->language->id);
             if (empty($attributes)) {
                 $attributes[] = array('id_product_attribute' => 0, 'attribute_designation' => '');
             }
             // Get available quantities
             $available_quantity = array();
             $product_designation = array();
             foreach ($attributes as $attribute) {
                 // Get available quantity for the current product attribute in the current shop
                 $available_quantity[$attribute['id_product_attribute']] = StockAvailable::getQuantityAvailableByProduct((int) $obj->id, $attribute['id_product_attribute']);
                 // Get all product designation
                 $product_designation[$attribute['id_product_attribute']] = rtrim($obj->name[$this->context->language->id] . ' - ' . $attribute['attribute_designation'], ' - ');
             }
             $show_quantities = true;
             $shop_context = Shop::getContext();
             $shop_group = new ShopGroup((int) Shop::getContextShopGroupID());
             // if we are in all shops context, it's not possible to manage quantities at this level
             if (Shop::isFeatureActive() && $shop_context == Shop::CONTEXT_ALL) {
                 $show_quantities = false;
             } elseif (Shop::isFeatureActive() && $shop_context == Shop::CONTEXT_GROUP) {
                 // if quantities are not shared between shops of the group, it's not possible to manage them at group level
                 if (!$shop_group->share_stock) {
                     $show_quantities = false;
                 }
             } else {
                 // if quantities are shared between shops of the group, it's not possible to manage them for a given shop
                 if ($shop_group->share_stock) {
                     $show_quantities = false;
                 }
             }
             $data->assign('ps_stock_management', Configuration::get('PS_STOCK_MANAGEMENT'));
             $data->assign('has_attribute', $obj->hasAttributes());
             // Check if product has combination, to display the available date only for the product or for each combination
             if (Combination::isFeatureActive()) {
                 $data->assign('countAttributes', (int) Db::getInstance()->getValue('SELECT COUNT(id_product) FROM ' . _DB_PREFIX_ . 'product_attribute WHERE id_product = ' . (int) $obj->id));
             } else {
                 $data->assign('countAttributes', false);
             }
             // if advanced stock management is active, checks associations
             $advanced_stock_management_warning = false;
             if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $obj->advanced_stock_management) {
                 $p_attributes = Product::getProductAttributesIds($obj->id);
                 $warehouses = array();
                 if (!$p_attributes) {
                     $warehouses[] = Warehouse::getProductWarehouseList($obj->id, 0);
                 }
                 foreach ($p_attributes as $p_attribute) {
                     $ws = Warehouse::getProductWarehouseList($obj->id, $p_attribute['id_product_attribute']);
                     if ($ws) {
                         $warehouses[] = $ws;
                     }
                 }
                 $warehouses = Tools::arrayUnique($warehouses);
                 if (empty($warehouses)) {
                     $advanced_stock_management_warning = true;
                 }
             }
             if ($advanced_stock_management_warning) {
                 $this->displayWarning($this->l('If you wish to use the advanced stock management, you must:'));
                 $this->displayWarning('- ' . $this->l('associate your products with warehouses.'));
                 $this->displayWarning('- ' . $this->l('associate your warehouses with carriers.'));
                 $this->displayWarning('- ' . $this->l('associate your warehouses with the appropriate shops.'));
             }
             $pack_quantity = null;
             // if product is a pack
             if (Pack::isPack($obj->id)) {
                 $items = Pack::getItems((int) $obj->id, Configuration::get('PS_LANG_DEFAULT'));
                 // gets an array of quantities (quantity for the product / quantity in pack)
                 $pack_quantities = array();
                 foreach ($items as $item) {
                     if (!$item->isAvailableWhenOutOfStock((int) $item->out_of_stock)) {
                         $pack_id_product_attribute = Product::getDefaultAttribute($item->id, 1);
                         $pack_quantities[] = Product::getQuantity($item->id, $pack_id_product_attribute) / ($item->pack_quantity !== 0 ? $item->pack_quantity : 1);
                     }
                 }
                 // gets the minimum
                 if (count($pack_quantities)) {
                     $pack_quantity = $pack_quantities[0];
                     foreach ($pack_quantities as $value) {
                         if ($pack_quantity > $value) {
                             $pack_quantity = $value;
                         }
                     }
                 }
                 if (!Warehouse::getPackWarehouses((int) $obj->id)) {
                     $this->displayWarning($this->l('You must have a common warehouse between this pack and its product.'));
                 }
             }
             $data->assign(array('attributes' => $attributes, 'available_quantity' => $available_quantity, 'pack_quantity' => $pack_quantity, 'stock_management_active' => Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'), 'product_designation' => $product_designation, 'product' => $obj, 'show_quantities' => $show_quantities, 'order_out_of_stock' => Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'token_preferences' => Tools::getAdminTokenLite('AdminPPreferences'), 'token' => $this->token, 'languages' => $this->_languages, 'id_lang' => $this->context->language->id));
         } else {
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例8: ajaxProcessDeleteProductAttribute

 public function ajaxProcessDeleteProductAttribute()
 {
     if (!Combination::isFeatureActive()) {
         return;
     }
     if ($this->tabAccess['delete'] === '1') {
         $id_product = (int) Tools::getValue('id_product');
         $id_product_attribute = (int) Tools::getValue('id_product_attribute');
         if ($id_product && Validate::isUnsignedId($id_product) && Validate::isLoadedObject($product = new Product($id_product))) {
             if (($depends_on_stock = StockAvailable::dependsOnStock($id_product)) && StockAvailable::getQuantityAvailableByProduct($id_product, $id_product_attribute)) {
                 $json = array('status' => 'error', 'message' => $this->l('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) $id_product_attribute);
                 $product->checkDefaultAttributes();
                 Tools::clearColorListCache((int) $product->id);
                 if (!$product->hasAttributes()) {
                     $product->cache_default_attribute = 0;
                     $product->update();
                 } else {
                     Product::updateDefaultAttribute($id_product);
                 }
                 if ($depends_on_stock && !Stock::deleteStockByIds($id_product, $id_product_attribute)) {
                     $json = array('status' => 'error', 'message' => $this->l('Error while deleting the stock'));
                 } else {
                     $json = array('status' => 'ok', 'message' => $this->_conf[1], 'id_product_attribute' => (int) $id_product_attribute);
                 }
             }
         } else {
             $json = array('status' => 'error', 'message' => $this->l('You cannot delete this attribute.'));
         }
     } else {
         $json = array('status' => 'error', 'message' => $this->l('You do not have permission to delete this.'));
     }
     die(Tools::jsonEncode($json));
 }
开发者ID:Rohit-jn,项目名称:hotelcommerce,代码行数:35,代码来源:AdminProductsController.php

示例9: foreach

							 <th>' . $erpip->l('Usable Stock') . '</th>
							 <th>' . $erpip->l('Real Stock') . '</th>';
            } else {
                $message .= '<th>' . $erpip->l('Stock') . '</th>';
            }
            $message .= '</tr>';
            foreach ($produits as &$prod) {
                $objProd = new Product($prod['product_id']);
                $message .= '<tr>';
                /*  If order neither sent nor cancelled nor current order */
                $message .= '<td>' . $objProd->reference . '</td><td>' . $objProd->getProductName($prod['product_id'], $prod['product_attribute_id']) . '</td><td>' . $prod['product_quantity'] . '</td>';
                if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
                    $manager = StockManagerFactory::getManager();
                    $message .= '<td>' . $manager->getProductPhysicalQuantities($prod['product_id'], $prod['product_attribute_id']) . '</td>' . '<td>' . $manager->getProductPhysicalQuantities($prod['product_id'], $prod['product_attribute_id'], null, true) . '</td>' . '<td>' . $manager->getProductRealQuantities($prod['product_id'], $prod['product_attribute_id']) . '</td>';
                } else {
                    $message .= '<td>' . StockAvailable::getQuantityAvailableByProduct($prod['product_id'], $prod['product_attribute_id']) . '</td>';
                }
                $message .= '</tr>';
            }
            $message .= '</table>';
            print $message;
        }
        break;
    case 'productSupplierPrice':
        /*  If we have called the script with a term to search */
        if (Tools::isSubmit('id_product') && Tools::isSubmit('id_product_attribute')) {
            $id_product = Tools::getValue('id_product');
            $id_product_attribute = Tools::getValue('id_product_attribute');
            $id_currency = Tools::getValue('id_currency', false) ? Tools::getValue('id_currency') : Configuration::get('PS_CURRENCY_DEFAULT');
            /* Prices of all suppliers for the product */
            $supplier_prices = ErpProductSupplier::getAllProductSupplierPrice($id_product, $id_product_attribute, true);
开发者ID:prestamodule,项目名称:erpillicopresta,代码行数:31,代码来源:ajax.php

示例10: getProductProperties

 public static function getProductProperties($id_lang, $row)
 {
     if (!$row['id_product']) {
         return false;
     }
     // Product::getDefaultAttribute is only called if id_product_attribute is missing from the SQL query at the origin of it: consider adding it in order to avoid unnecessary queries
     $row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']);
     if ((!isset($row['id_product_attribute']) or !$row['id_product_attribute']) and (isset($row['cache_default_attribute']) and ($ipa_default = $row['cache_default_attribute']) !== NULL or $ipa_default = Product::getDefaultAttribute($row['id_product'], !$row['allow_oosp']))) {
         $row['id_product_attribute'] = $ipa_default;
     }
     if (!isset($row['id_product_attribute'])) {
         $row['id_product_attribute'] = 0;
     }
     // Tax
     $usetax = Tax::excludeTaxeOption();
     $cacheKey = $row['id_product'] . '-' . $row['id_product_attribute'] . '-' . $id_lang . '-' . (int) $usetax;
     if (array_key_exists($cacheKey, self::$producPropertiesCache)) {
         return self::$producPropertiesCache[$cacheKey];
     }
     // Datas
     $row['category'] = Category::getLinkRewrite((int) $row['id_category_default'], (int) $id_lang);
     if (!preg_match("/^1.3.*/", _PS_VERSION_)) {
         // Not available in Prestashop 1.3.x
         $row['reduction'] = Product::getPriceStatic((int) $row['id_product'], (bool) $usetax, (int) $row['id_product_attribute'], 6, NULL, true, true, 1, true, NULL, NULL, NULL, $specific_prices);
         $row['specific_prices'] = $specific_prices;
     }
     if ($row['id_product_attribute']) {
         $row['quantity_all_versions'] = $row['quantity'];
         $row['quantity'] = Product::getQuantity((int) $row['id_product'], $row['id_product_attribute'], isset($row['cache_is_pack']) ? $row['cache_is_pack'] : NULL);
     }
     $row['id_image'] = Product::defineProductImage($row, $id_lang);
     $row['features'] = Product::getFrontFeaturesStatic((int) $id_lang, $row['id_product']);
     // Pack management
     $row['pack'] = !isset($row['cache_is_pack']) ? Pack::isPack($row['id_product']) : (int) $row['cache_is_pack'];
     $row['packItems'] = $row['pack'] ? Pack::getItemTable($row['id_product'], $id_lang) : array();
     $row['nopackprice'] = $row['pack'] ? Pack::noPackPrice($row['id_product']) : 0;
     if ($row['pack'] and !Pack::isInStock($row['id_product'])) {
         $row['quantity'] = 0;
     }
     $sql_combination = '
   SELECT pa.id_product_attribute, pa.price, pa.quantity, pa.id_product
   FROM `' . _DB_PREFIX_ . 'product` p
   LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (p.`id_product` = pa.`id_product`)
   WHERE p.`id_product` =' . $row['id_product'];
     $result_combination = ProductExtended::getDbInstance()->ExecuteS($sql_combination);
     $row['combinations'] = array();
     if ($result_combination) {
         foreach ($result_combination as $combination) {
             $combination['attributes'] = array();
             /* New combinations system Prestashop 1.5.x */
             if (!preg_match("/^1.(3|4).*/", _PS_VERSION_)) {
                 $combination['quantity'] = StockAvailable::getQuantityAvailableByProduct($row['id_product'], $combination['id_product_attribute']);
             }
             if (isset($combination['id_product_attribute'])) {
                 $sql_attribute = '
         SELECT pa.id_product_attribute, agl.id_attribute_group, al.name as name_value, agl.name as name_option
         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_lang` al ON (al.`id_attribute` = a.`id_attribute` AND al.`id_lang` = ' . $id_lang . ')
         LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group` ag ON (ag.`id_attribute_group` = a.`id_attribute_group`)
         LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON (agl.`id_attribute_group` = ag.`id_attribute_group` AND agl.`id_lang` = ' . $id_lang . ')
         WHERE pa.`id_product_attribute` =' . $combination['id_product_attribute'];
                 $result_attribute = ProductExtended::getDbInstance()->ExecuteS($sql_attribute);
                 if ($result_attribute) {
                     foreach ($result_attribute as $attribute) {
                         array_push($combination['attributes'], $attribute);
                     }
                 }
                 array_push($row['combinations'], $combination);
             }
         }
     }
     $sql_image = '
   SELECT DISTINCT i.*, pl.link_rewrite
   FROM `' . _DB_PREFIX_ . 'product` p
   LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (p.`id_product` = i.`id_product`)
   LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product`)
   WHERE p.`id_product` =' . $row['id_product'];
     $result_image = ProductExtended::getDbInstance()->ExecuteS($sql_image);
     $row['images'] = array();
     $lang = new Language($id_lang);
     $row['url_locale'] = $lang->iso_code;
     if ($result_image) {
         $link = preg_match("/^1.(3|4).*/", _PS_VERSION_) ? new Link() : Context::getContext()->link;
         foreach ($result_image as $image) {
             if (!preg_match("/^1.3.*/", _PS_VERSION_)) {
                 // Image URL gives relative version using 1.3.x-
                 $image['image_url'] = $link->getImageLink($image['link_rewrite'], $image['id_product'] . '-' . $image['id_image']);
             }
             array_push($row['images'], $image);
         }
     }
     self::$producPropertiesCache[$cacheKey] = $row;
     return self::$producPropertiesCache[$cacheKey];
 }
开发者ID:Oelan,项目名称:PrestaShop,代码行数:96,代码来源:product-extended.php

示例11: startImport

 public function startImport()
 {
     global $cookie;
     @ini_set('max_execution_time', 0);
     ini_set('memory_limit', '256M');
     self::$_exportStartTime = time();
     $this->_header = self::$_serviceData['header'] == 1;
     self::$_sef = (int) Configuration::get('PS_REWRITING_SETTINGS');
     self::$_exportStore = (int) self::$_serviceData['id_store'];
     self::$_exportShop = (int) self::$_serviceData['id_shop'];
     self::$_exportGroup = (int) self::$_serviceData['id_group'];
     self::$_exportLanguage = (int) self::$_serviceData['id_lang'];
     self::$_carrierId = (int) self::$_serviceData['id_carrier'];
     self::$_carrierTax = self::getShippingTax(self::$_carrierId);
     $carrier = new Carrier((int) self::$_carrierId);
     self::$_carrierMethod = $carrier->getShippingMethod();
     self::$_exportCountry = (int) self::$_serviceData['id_country'];
     self::$_exportCurrency = (int) self::getCurrencyByCountry(self::$_exportCountry);
     self::$_exportState = (int) self::$_serviceData['id_state'];
     self::$_exportCondition = self::$_serviceData['condition'];
     self::$_zone = Country::getIdZone(self::$_exportCountry);
     self::$_billingMode = (int) Configuration::get('PS_SHIPPING_METHOD');
     self::$_shippingCarrierData = self::getCarrierShippingRanges();
     self::$_existingPictures = self::getExistingPictures();
     self::$_existingCategories = self::getExistingCategories(self::$_exportLanguage);
     self::$_specificPrices = self::getSpecificPrices(self::$_exportShop);
     self::$_productPriorities = self::getProductsPriorities();
     self::$_taxRates = self::getTaxes();
     self::$_exportCategories = MoussiqFreeService::getCategories($this->service_id);
     self::$_productCategories = self::getProductCategories();
     self::$_exportLanguageObj = new Language(self::$_exportLanguage);
     if (self::$_exportCurrency == 0) {
         self::$_exportCurrency = (int) Configuration::get('PS_CURRENCY_DEFAULT');
     }
     if (sizeof(self::$_productCategories)) {
         $chunk_size = 3000;
         $current_size = 0;
         $this->beforeImport(self::$_serviceData['template'], array());
         do {
             $products = self::getProducts(self::$_exportLanguage, $current_size, $chunk_size, 'date_add', 'ASC', false, self::$_serviceData['export_inactive'] == true ? false : true, self::$_exportCountry, self::$_exportShop, self::$_exportCondition);
             $current_size += $chunk_size;
             $fileName = $this->filename;
             $fileDir = dirname(__FILE__) . '/../export/';
             if (!self::checkDir($fileDir)) {
                 $this->_errors[] = Tools::displayError('The directory is not writeable');
                 return false;
             }
             foreach ($products as $product) {
                 if (array_key_exists($product['id_product'], self::$_productCategories)) {
                     $product['categories'] = self::$_productCategories[$product['id_product']];
                     $product['reduction'] = self::getProductSpecificPrice($product['id_product'], self::$_exportStore, Configuration::get('PS_CURRENCY_DEFAULT'), self::$_exportCountry, self::$_exportGroup);
                     $product['quantity'] = (int) StockAvailable::getQuantityAvailableByProduct($product['id_product'], null, self::$_exportShop);
                     //to fix, get cover id_image
                     $product['id_image'] = self::getProductCoverWs($product['id_product']);
                     $product['id_product_image'] = $product['id_product'];
                     $features = self::collectFeatures(self::$_exportLanguage, $product['id_product']);
                     if (is_array($features)) {
                         foreach ($features as $id_feature => $feature) {
                             $product['ft' . $id_feature] = trim($feature);
                         }
                     }
                     $this->addProductLine($product, self::$_serviceData['template']);
                 }
             }
         } while ($chunk_size == count($products));
         $this->postProcess();
         return $this->saveFile();
     }
 }
开发者ID:pedalracer,项目名称:free_modules_1.5,代码行数:69,代码来源:Export.php

示例12: dirname

include dirname(__FILE__) . '/../../../init.php';
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
$now = date("Y-m-d");
$period = Configuration::get('PS_COLLECT_REVIEW_PERIOD_DAY');
$minus = date('Y-m-d', strtotime($now . ' - ' . $period . ' day'));
if ($orders = CollectReview::getAllOrderByDay($minus)) {
    $link = new Link();
    foreach ($orders as $value) {
        $order = new Order($value);
        $customer = new Customer($order->id_customer);
        $emailTo = $customer->email;
        $products_order = $order->getProducts();
        $products = array();
        foreach ($products_order as $item) {
            $cover = Product::getCover($item['product_id']);
            array_push($products, array('name' => $item['product_name'], 'price' => Tools::displayPrice($item['price']), 'quantity' => StockAvailable::getQuantityAvailableByProduct($item['product_id']), 'link' => $link->getProductLink($item['product_id']) . '#reviews', 'image' => $link->getImageLink($item['image']->id, $cover['id_image'], 'large_default')));
        }
        $template = 'collectReview';
        $subject = 'Оставьте отзыв';
        $product_list_html = CollectReview::getEmailTemplateContent('collectReview.tpl', Mail::TYPE_HTML, $products);
        $templateVars = array('{products}' => $product_list_html);
        $admin_mails = Configuration::get('PS_SHOP_EMAIL');
        $te = Mail::Send(1, $template, $subject, $templateVars, $emailTo);
    }
    $r = CollectReview::deactivate($orders);
    echo 'Письма отправлены';
} else {
    echo 'Не кому отправлять письма';
}
开发者ID:WhisperingTree,项目名称:etagerca,代码行数:31,代码来源:taskCollectReview.php

示例13: checkStock

 /**
  * @param ShopgateCart $cart
  * @return array
  */
 public function checkStock(ShopgateCart $cart)
 {
     $result = array();
     foreach ($cart->getItems() as $item) {
         $cartItem = new ShopgateCartItem();
         $cartItem->setItemNumber($item->getItemNumber());
         list($productId, $attributeId) = ShopgateHelper::getProductIdentifiers($item);
         /** @var ProductCore $product */
         if (version_compare(_PS_VERSION_, '1.5.2.0', '<')) {
             $product = new BWProduct($productId, true, $this->getPlugin()->getLanguageId());
         } else {
             $product = new Product($productId, $this->getPlugin()->getLanguageId());
         }
         if (empty($attributeId) && !empty($productId) && $product->hasAttributes()) {
             $result[] = $cartItem;
             continue;
         }
         $product->loadStockData();
         /**
          * validate attributes
          */
         if ($product->hasAttributes()) {
             $invalidAttribute = false;
             $message = '';
             if (!$attributeId) {
                 $cartItem->setError(ShopgateLibraryException::UNKNOWN_ERROR_CODE);
                 $cartItem->setErrorText('attributeId required');
                 $message = 'attributeId required';
                 $invalidAttribute = true;
             } else {
                 $validAttributeId = false;
                 if (version_compare(_PS_VERSION_, '1.5.0', '<')) {
                     $attributeIds = BWProduct::getProductAttributesIds($productId);
                 } else {
                     $attributeIds = $product->getProductAttributesIds($productId, true);
                 }
                 foreach ($attributeIds as $attribute) {
                     if ($attributeId == $attribute['id_product_attribute']) {
                         $validAttributeId = true;
                         continue;
                     }
                 }
                 if (!$validAttributeId) {
                     $invalidAttribute = true;
                     $message = 'invalid attributeId';
                 }
             }
             if ($invalidAttribute) {
                 $cartItem->setError(ShopgateLibraryException::UNKNOWN_ERROR_CODE);
                 $cartItem->setErrorText($message);
                 $result[] = $cartItem;
                 continue;
             }
         }
         if ($product->id) {
             if (version_compare(_PS_VERSION_, '1.5.0', '<')) {
                 $quantity = $product->getStockAvailable();
                 //getQuantityAvailableByProduct($productId, $attributeId, $this->getPlugin()->getContext()->shop->id);
             } else {
                 $quantity = StockAvailable::getQuantityAvailableByProduct($productId, $attributeId, $this->getPlugin()->getContext()->shop->id);
             }
             $cartItem->setStockQuantity($quantity);
             $cartItem->setIsBuyable($product->available_for_order && ($attributeId ? Attribute::checkAttributeQty($attributeId, ShopgateItemsCartExportJson::DEFAULT_QTY_TO_CHECK) : $product->checkQty(ShopgateItemsCartExportJson::DEFAULT_QTY_TO_CHECK)) || Product::isAvailableWhenOutOfStock($product->out_of_stock) ? 1 : 0);
         } else {
             $cartItem->setError(ShopgateLibraryException::CART_ITEM_PRODUCT_NOT_FOUND);
             $cartItem->setErrorText(ShopgateLibraryException::getMessageFor($cartItem->getError()));
         }
         $result[] = $cartItem;
     }
     return $result;
 }
开发者ID:pankajshoffex,项目名称:shoffex_prestashop,代码行数:75,代码来源:Json.php

示例14: getItemXML

 private function getItemXML($product, $lang, $id_curr, $id_shop, $combination = false)
 {
     $xml_googleshopping = '';
     $id_lang = (int) $lang['id_lang'];
     $title_limit = 70;
     $description_limit = 4990;
     $languages = Language::getLanguages();
     $tailleTabLang = sizeof($languages);
     $this->context->language->id = $id_lang;
     $this->context->shop->id = $id_shop;
     $p = new Product($product['id_product'], true, $id_lang, $id_shop, $this->context);
     // Get module configuration for this shop
     if (!$combination) {
         $product['quantity'] = StockAvailable::getQuantityAvailableByProduct($product['id_product'], 0, $id_shop);
     }
     // Exclude non-available products
     if ($this->module_conf['export_nap'] === 0 && $product['quantity'] < 1) {
         $this->nb_not_exported_products++;
         return;
     }
     // Check minimum product price
     $price = Product::getPriceStatic((int) $product['id_product'], true);
     if ((double) $this->module_conf['export_min_price'] > 0 && (double) $this->module_conf['export_min_price'] > (double) $price) {
         return;
     }
     $cat_link_rew = Category::getLinkRewrite($product['id_gcategory'], (int) $lang);
     $product_link = $this->context->link->getProductLink((int) $product['id_product'], $product['link_rewrite'], $cat_link_rew, $product['ean13'], (int) $product['id_lang'], $id_shop, $combination, true);
     // Product name
     $title_crop = $product['name'];
     //  Product color attribute, if any
     if (!empty($product['color'])) {
         $title_crop .= ' ' . $product['color'];
     }
     if (!empty($product['material'])) {
         $title_crop .= ' ' . $product['material'];
     }
     if (!empty($product['pattern'])) {
         $title_crop .= ' ' . $product['pattern'];
     }
     if (!empty($product['size'])) {
         $title_crop .= ' ' . $product['size'];
     }
     if (Tools::strlen($product['name']) > $title_limit) {
         $title_crop = Tools::substr($title_crop, 0, $title_limit - 1);
         $title_crop = Tools::substr($title_crop, 0, strrpos($title_crop, " "));
     }
     // Description type
     if ($this->module_conf['description'] == 'long') {
         $description_crop = $product['description'];
     } else {
         if ($this->module_conf['description'] == 'short') {
             $description_crop = $product['description_short'];
         } else {
             if ($this->module_conf['description'] == 'meta') {
                 $description_crop = $product['meta_description'];
             }
         }
     }
     $description_crop = $this->rip_tags($description_crop);
     if (Tools::strlen($description_crop) > $description_limit) {
         $description_crop = Tools::substr($description_crop, 0, $description_limit - 1);
         $description_crop = Tools::substr($description_crop, 0, strrpos($description_crop, " ")) . ' ...';
     }
     $xml_googleshopping .= '<item>' . "\n";
     $xml_googleshopping .= '<g:id>' . $product['gid'] . '</g:id>' . "\n";
     $xml_googleshopping .= '<title><![CDATA[' . $title_crop . ']]></title>' . "\n";
     $xml_googleshopping .= '<description><![CDATA[' . $description_crop . ']]></description>' . "\n";
     $xml_googleshopping .= '<link><![CDATA[' . htmlspecialchars($product_link, self::REPLACE_FLAGS, self::CHARSET, false) . ']]></link>' . "\n";
     // Image links
     $images = Image::getImages($lang['id_lang'], $product['id_product'], $combination);
     $indexTabLang = 0;
     if ($tailleTabLang > 1) {
         while (sizeof($images) < 1 && $indexTabLang < $tailleTabLang) {
             if ($languages[$indexTabLang]['id_lang'] != $lang['id_lang']) {
                 $images = Image::getImages($languages[$indexTabLang]['id_lang'], $product['id_product']);
             }
             $indexTabLang++;
         }
     }
     $nbimages = 0;
     $image_type = $this->module_conf['img_type'];
     if ($image_type == '') {
         $image_type = 'large_default';
     }
     foreach ($images as $im) {
         $image = $this->context->link->getImageLink($product['link_rewrite'], $product['id_product'] . '-' . $im['id_image'], $image_type);
         $image = preg_replace('*http://' . Tools::getHttpHost() . '/*', $this->uri, $image);
         if ($im['cover'] == 1) {
             $xml_googleshopping .= '<g:image_link><![CDATA[' . $image . ']]></g:image_link>' . "\n";
         } else {
             $xml_googleshopping .= '<g:additional_image_link><![CDATA[' . $image . ']]></g:additional_image_link>' . "\n";
         }
         // max images by product
         if (++$nbimages == 10) {
             break;
         }
     }
     // Product condition, or category's condition attribute, or its parent one...
     // Product condition = new, used, refurbished
     if (empty($product['condition'])) {
//.........这里部分代码省略.........
开发者ID:ecommercebox,项目名称:gshoppingflux,代码行数:101,代码来源:gshoppingflux.php

示例15: generateFile

 private function generateFile($lang)
 {
     $path_parts = pathinfo(__FILE__);
     if (Configuration::get('GENERATE_FILE_IN_ROOT')) {
         $generate_file_path = dirname(__FILE__) . '/../../' . $this->_getOutputFileName($lang['iso_code']);
     } else {
         $generate_file_path = dirname(__FILE__) . '/file_exports/' . $this->_getOutputFileName($lang['iso_code']);
     }
     //Google Shopping XML
     $xml = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
     $xml .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0" encoding="UTF-8" >' . "\n";
     $xml .= '<title>' . Configuration::get('PS_SHOP_NAME') . '</title>' . "\n";
     $xml .= '<link href="' . htmlspecialchars($this->uri, self::REPLACE_FLAGS, self::CHARSET, false) . '" rel="alternate" type="text/html"/>' . "\n";
     $xml .= '<modified>' . date('Y-m-d') . 'T01:01:01Z</modified><author><name>' . Configuration::get('PS_SHOP_NAME') . '</name></author>' . "\n";
     $googleshoppingfile = fopen($generate_file_path, 'w');
     // add UTF-8 byte order mark
     fwrite($googleshoppingfile, pack("CCC", 0xef, 0xbb, 0xbf));
     //file header
     fwrite($googleshoppingfile, $xml);
     $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'product p' . ' LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON p.id_product = pl.id_product' . ' WHERE p.active = 1 AND pl.id_lang=' . $lang['id_lang'];
     $products = Db::getInstance()->ExecuteS($sql);
     $title_limit = 70;
     $description_limit = 10000;
     $languages = Language::getLanguages();
     $tailleTabLang = sizeof($languages);
     foreach ($products as $product) {
         $xml_googleshopping = '';
         $cat_link_rew = Category::getLinkRewrite($product['id_category_default'], intval($lang));
         //continue if product not have price
         $price = Product::getPriceStatic($product['id_product'], true, NULL, 2);
         if (empty($price)) {
             continue;
         }
         $product_link = $this->context->link->getProductLink((int) $product['id_product'], $product['link_rewrite'], $cat_link_rew, $product['ean13'], (int) $product['id_lang'], 1, 0, true);
         $title_crop = $product['name'];
         if (strlen($product['name']) > $title_limit) {
             $title_crop = substr($title_crop, 0, $title_limit - 1);
             $title_crop = substr($title_crop, 0, strrpos($title_crop, " "));
         }
         if (intval(Configuration::get('DESCRIPTION')) === intval(2)) {
             $description_crop = $product['description'];
         } else {
             $description_crop = $product['description_short'];
         }
         $description_crop = $this->rip_tags($description_crop);
         if (strlen($description_crop) > $description_limit) {
             $description_crop = substr($description_crop, 0, $description_limit - 1);
             $description_crop = substr($description_crop, 0, strrpos($description_crop, " "));
         }
         $xml_googleshopping .= '<entry>' . "\n";
         $xml_googleshopping .= '<g:id>' . $product['id_product'] . '-' . $lang['iso_code'] . '</g:id>' . "\n";
         $xml_googleshopping .= '<title>' . htmlentities(ucfirst(mb_strtolower($title_crop, self::CHARSET)), self::REPLACE_FLAGS, self::CHARSET) . '</title>' . "\n";
         $xml_googleshopping .= '<link>' . htmlspecialchars($product_link, self::REPLACE_FLAGS, self::CHARSET, false) . '</link>' . "\n";
         $xml_googleshopping .= '<g:price>' . $price . '</g:price>' . "\n";
         $xml_googleshopping .= '<g:description>' . htmlentities($description_crop, self::REPLACE_FLAGS, self::CHARSET) . '</g:description>' . "\n";
         $xml_googleshopping .= '<g:condition>new</g:condition>' . "\n";
         // condition = new, used, refurbished
         $images = Image::getImages($lang['id_lang'], $product['id_product']);
         $indexTabLang = 0;
         if ($tailleTabLang > 1) {
             while (sizeof($images) < 1 && $indexTabLang < $tailleTabLang) {
                 if ($languages[$indexTabLang]['id_lang'] != $lang['id_lang']) {
                     $images = Image::getImages($languages[$indexTabLang]['id_lang'], $product['id_product']);
                 }
                 $indexTabLang++;
             }
         }
         $nbimages = 0;
         $image_type = Configuration::get('GS_IMAGE');
         if ($image_type == '') {
             $image_type = 'large_default';
         }
         /* create image links */
         foreach ($images as $im) {
             $image = $this->context->link->getImageLink($product['link_rewrite'], $product['id_product'] . '-' . $im['id_image'], $image_type);
             $xml_googleshopping .= '<g:image_link>' . $image . '</g:image_link>' . "\n";
             //max images by product
             if (++$nbimages == 10) {
                 break;
             }
         }
         if (Configuration::get('QUANTITY') == 1) {
             $quantity = StockAvailable::getQuantityAvailableByProduct($product['id_product'], 0);
             if ($quantity > 0) {
                 $xml_googleshopping .= '<g:quantity>' . $quantity . '</g:quantity>' . "\n";
                 $xml_googleshopping .= '<g:availability>in stock</g:availability>' . "\n";
             } else {
                 $xml_googleshopping .= '<g:quantity>0</g:quantity>' . "\n";
                 $xml_googleshopping .= '<g:availability>out of stock</g:availability>' . "\n";
             }
         }
         // Brand
         $identifier_exists = false;
         if (Configuration::get('BRAND') && $product['id_manufacturer'] != '0') {
             $xml_googleshopping .= '<g:brand>' . htmlspecialchars(Manufacturer::getNameById(intval($product['id_manufacturer'])), self::REPLACE_FLAGS, self::CHARSET, false) . '</g:brand>' . "\n";
             $identifier_exists = true;
         }
         if (Configuration::get('MPN') && $product['supplier_reference'] != '') {
             $xml_googleshopping .= '<g:mpn>' . $product['supplier_reference'] . '</g:mpn>';
             $identifier_exists = true;
//.........这里部分代码省略.........
开发者ID:ocean123,项目名称:ps_googleshopping,代码行数:101,代码来源:googleshopping.php


注:本文中的StockAvailable::getQuantityAvailableByProduct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。