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


PHP Product::getProductCategories方法代码示例

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


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

示例1: getCategoriesNames

 protected static function getCategoriesNames($product, $ps_product, $id_lang, $iso_code)
 {
     $product->{"categories_{$iso_code}"} = array();
     $id_categories = Product::getProductCategories($ps_product->id);
     foreach ($id_categories as $id_category) {
         $category = new Category($id_category, $id_lang);
         array_push($product->{"categories_{$iso_code}"}, $category->name);
     }
     return $product;
 }
开发者ID:matiasmenker,项目名称:algoliasearch-prestashop,代码行数:10,代码来源:AlgoliaProduct.php

示例2: setProductReduction

 public static function setProductReduction($id_product, $id_group = null, $id_category = null, $reduction = null)
 {
     $res = true;
     GroupReduction::deleteProductReduction((int) $id_product);
     $categories = Product::getProductCategories((int) $id_product);
     if ($categories) {
         foreach ($categories as $category) {
             $reductions = GroupReduction::getGroupsByCategoryId((int) $category);
             if ($reductions) {
                 foreach ($reductions as $reduction) {
                     $current_group_reduction = new GroupReduction((int) $reduction['id_group_reduction']);
                     $res &= $current_group_reduction->_setCache();
                 }
             }
         }
     }
     return $res;
 }
开发者ID:jpodracky,项目名称:dogs,代码行数:18,代码来源:GroupReduction.php

示例3: getCategories

 /**
  * getCategories return an array of categories which this product belongs to
  *
  * @return array of categories
  */
 public function getCategories()
 {
     return Product::getProductCategories($this->id);
 }
开发者ID:srikanthash09,项目名称:codetestdatld,代码行数:9,代码来源:Product.php

示例4: productImportOne

    protected function productImportOne($info, $default_language_id, $id_lang, $force_ids, $regenerate, $shop_is_feature_active, $shop_ids, $match_ref, &$accessories, $validateOnly = false)
    {
        if ($force_ids && isset($info['id']) && (int) $info['id']) {
            $product = new Product((int) $info['id']);
        } elseif ($match_ref && array_key_exists('reference', $info)) {
            $datas = Db::getInstance()->getRow('
					SELECT p.`id_product`
					FROM `' . _DB_PREFIX_ . 'product` p
					' . Shop::addSqlAssociation('product', 'p') . '
					WHERE p.`reference` = "' . pSQL($info['reference']) . '"
				', false);
            if (isset($datas['id_product']) && $datas['id_product']) {
                $product = new Product((int) $datas['id_product']);
            } else {
                $product = new Product();
            }
        } elseif (array_key_exists('id', $info) && (int) $info['id'] && Product::existsInDatabase((int) $info['id'], 'product')) {
            $product = new Product((int) $info['id']);
        } else {
            $product = new Product();
        }
        $update_advanced_stock_management_value = false;
        if (isset($product->id) && $product->id && Product::existsInDatabase((int) $product->id, 'product')) {
            $product->loadStockData();
            $update_advanced_stock_management_value = true;
            $category_data = Product::getProductCategories((int) $product->id);
            if (is_array($category_data)) {
                foreach ($category_data as $tmp) {
                    if (!isset($product->category) || !$product->category || is_array($product->category)) {
                        $product->category[] = $tmp;
                    }
                }
            }
        }
        AdminImportController::setEntityDefaultValues($product);
        AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $product);
        if (!$shop_is_feature_active) {
            $product->shop = (int) Configuration::get('PS_SHOP_DEFAULT');
        } elseif (!isset($product->shop) || empty($product->shop)) {
            $product->shop = implode($this->multiple_value_separator, Shop::getContextListShopID());
        }
        if (!$shop_is_feature_active) {
            $product->id_shop_default = (int) Configuration::get('PS_SHOP_DEFAULT');
        } else {
            $product->id_shop_default = (int) Context::getContext()->shop->id;
        }
        // link product to shops
        $product->id_shop_list = array();
        foreach (explode($this->multiple_value_separator, $product->shop) as $shop) {
            if (!empty($shop) && !is_numeric($shop)) {
                $product->id_shop_list[] = Shop::getIdByName($shop);
            } elseif (!empty($shop)) {
                $product->id_shop_list[] = $shop;
            }
        }
        if ((int) $product->id_tax_rules_group != 0) {
            if (Validate::isLoadedObject(new TaxRulesGroup($product->id_tax_rules_group))) {
                $address = $this->context->shop->getAddress();
                $tax_manager = TaxManagerFactory::getManager($address, $product->id_tax_rules_group);
                $product_tax_calculator = $tax_manager->getTaxCalculator();
                $product->tax_rate = $product_tax_calculator->getTotalRate();
            } else {
                $this->addProductWarning('id_tax_rules_group', $product->id_tax_rules_group, $this->trans('Unknown tax rule group ID. You need to create a group with this ID first.', array(), 'Admin.Parameters.Notification'));
            }
        }
        if (isset($product->manufacturer) && is_numeric($product->manufacturer) && Manufacturer::manufacturerExists((int) $product->manufacturer)) {
            $product->id_manufacturer = (int) $product->manufacturer;
        } elseif (isset($product->manufacturer) && is_string($product->manufacturer) && !empty($product->manufacturer)) {
            if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) {
                $product->id_manufacturer = (int) $manufacturer;
            } else {
                $manufacturer = new Manufacturer();
                $manufacturer->name = $product->manufacturer;
                $manufacturer->active = true;
                if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $manufacturer->add()) {
                    $product->id_manufacturer = (int) $manufacturer->id;
                    $manufacturer->associateTo($product->id_shop_list);
                } else {
                    if (!$validateOnly) {
                        $this->errors[] = sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), $manufacturer->name, isset($manufacturer->id) && !empty($manufacturer->id) ? $manufacturer->id : 'null');
                    }
                    if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) {
                        $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                    }
                }
            }
        }
        if (isset($product->supplier) && is_numeric($product->supplier) && Supplier::supplierExists((int) $product->supplier)) {
            $product->id_supplier = (int) $product->supplier;
        } elseif (isset($product->supplier) && is_string($product->supplier) && !empty($product->supplier)) {
            if ($supplier = Supplier::getIdByName($product->supplier)) {
                $product->id_supplier = (int) $supplier;
            } else {
                $supplier = new Supplier();
                $supplier->name = $product->supplier;
                $supplier->active = true;
                if (($field_error = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $supplier->add()) {
                    $product->id_supplier = (int) $supplier->id;
                    $supplier->associateTo($product->id_shop_list);
                } else {
//.........这里部分代码省略.........
开发者ID:M03G,项目名称:PrestaShop,代码行数:101,代码来源:AdminImportController.php

示例5: buildXMLOrder

 private function buildXMLOrder($id_order)
 {
     CertissimLogger::insertLog(__METHOD__ . ' : ' . __LINE__, 'construction du flux pour order ' . $id_order);
     $order = new Order($id_order);
     //gets back the delivery address
     $address_delivery = new Address((int) $order->id_address_delivery);
     //gets back the invoice address
     $address_invoice = new Address((int) $order->id_address_invoice);
     //gets back the customer
     $customer = new Customer((int) $order->id_customer);
     //initializatino of the XML root: <control>
     $xml_element_control = new CertissimControl();
     //gets the lang used in the order
     $id_lang = $order->id_lang;
     //sets the gender, depends on PS version
     if (_PS_VERSION_ < '1.5') {
         $gender = $customer->id_gender == 2 ? $this->l('Ms.') : $this->l('Mr.');
     } else {
         $customer_gender = new Gender($customer->id_gender);
         $lang_id = Language::getIdByIso('en');
         if (empty($lang_id)) {
             $lang_id = Language::getIdByIso('fr');
         }
         CertissimLogger::insertLog(__METHOD__ . ' : ' . __LINE__, "id_gender = " . $customer->id_gender . ", gender name =" . $customer_gender->name[$lang_id]);
         $gender = $this->l($customer_gender->name[$lang_id]);
     }
     //initialization of the element <utilisateur type='facturation'...>
     $xml_element_invoice_customer = new CertissimUtilisateur('facturation', $gender, $address_invoice->lastname, $address_invoice->firstname, $address_invoice->company, $address_invoice->phone, $address_invoice->phone_mobile, null, $customer->email);
     //gets customer stats
     $customer_stats = $customer->getStats();
     //gets already existing orders for the customer
     $all_orders = Order::getCustomerOrders((int) $customer->id);
     //initialization of the element <siteconso>
     $xml_element_invoice_customer_stats = new CertissimSiteconso($customer_stats['total_orders'], $customer_stats['nb_orders'], $all_orders[count($all_orders) - 1]['date_add'], count($all_orders) > 1 ? $all_orders[1]['date_add'] : null);
     //gets back the invoice country
     $country = new Country((int) $address_invoice->id_country);
     //initialization of the element <adresse type="facturation" ...>
     $xml_element_invoice_address = new CertissimAdresse('facturation', $address_invoice->address1, $address_invoice->address2, $address_invoice->postcode, $address_invoice->city, $country->name[$id_lang]);
     //gets back the carrier used for this order
     $carrier = new Carrier((int) $order->id_carrier);
     //gets the carrier certissim type
     if (_PS_VERSION_ >= '1.5' && Shop::isFeatureActive()) {
         $carrier_type = Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_TYPE', null, null, $order->id_shop);
     } else {
         $carrier_type = Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_TYPE');
     }
     //if the order is to be delivered at home: element <utilisateur type="livraison"...> has to be added
     if ($carrier_type == 4) {
         //initialization of the element <utilisateur type="livraison" ...>
         $xml_element_delivery_customer = new CertissimUtilisateur('livraison', $customer->id_gender == 2 ? $this->l('Miss') : $this->l('Mister'), $address_delivery->lastname, $address_delivery->firstname, $address_delivery->company, $address_delivery->phone, $address_delivery->phone_mobile, null, $customer->email);
         //gets back the delivery country
         $country = new Country((int) $address_delivery->id_country);
         //initialization of the element <adresse type="livraison" ...>
         $xml_element_delivery_address = new CertissimAdresse('livraison', $address_delivery->address1, $address_delivery->address2, $address_delivery->postcode, $address_delivery->city, $country->name[$id_lang], null);
     }
     //gets the used currency
     $currency = new Currency((int) $order->id_currency);
     if (_PS_VERSION_ >= '1.5' && Shop::isFeatureActive()) {
         $siteid = Configuration::get('CERTISSIM_SITEID', null, null, $order->id_shop);
     } else {
         $siteid = Configuration::get('CERTISSIM_SITEID');
     }
     //initialize the element <infocommande>
     $xml_element_order_details = new CertissimInfocommande($siteid, $order->id, (string) $order->total_paid, self::getIpByOrder((int) $order->id), date('Y-m-d H:i:s'), $currency->iso_code);
     //gets the order products
     $products = $order->getProducts();
     //define the default product type (depends on PS version)
     if (_PS_VERSION_ >= '1.5' && Shop::isFeatureActive()) {
         $default_product_type = Configuration::get('CERTISSIM_DEFAULT_PRODUCT_TYPE', null, null, $order->id_shop);
     } else {
         $default_product_type = Configuration::get('CERTISSIM_DEFAULT_PRODUCT_TYPE');
     }
     //initialization of the element <list ...>
     $xml_element_products_list = new CertissimProductList();
     //initialize the boolean that says if all the products in the order are downloadables
     $alldownloadables = true;
     foreach ($products as $product) {
         //check if the visited product is downloadable and update the boolean value
         $alldownloadables = $alldownloadables && strlen($product['download_hash']) > 0;
         //gets the main product category
         $product_categories = Product::getProductCategories((int) $product['product_id']);
         $product_category = array_pop($product_categories);
         //initilization of the element <produit ...>
         $xml_element_product = new CertissimXMLElement("<produit></produit>");
         //gets the product certissim category (depends on PS version)
         if (_PS_VERSION_ >= '1.5' && Shop::isFeatureActive()) {
             $product_type = Configuration::get('CERTISSIM' . $product_category . '_PRODUCT_TYPE', null, null, $order->id_shop);
         } else {
             $product_type = Configuration::get('CERTISSIM' . $product_category . '_PRODUCT_TYPE');
         }
         //if a certissim category is set: the type attribute takes the product certissim type value
         if ($product_type) {
             $xml_element_product->addAttribute('type', Configuration::get('CERTISSIM' . $product_category . '_PRODUCT_TYPE', null, null, $order->id_shop));
         } else {
             //if certissim category not set: the type attribute takes the default value
             $xml_element_product->addAttribute('type', $default_product_type);
         }
         //sets the product reference that will be inserted into the XML stream
         //uses the product name by default
         $product_ref = $product['product_name'];
//.........这里部分代码省略.........
开发者ID:juniorhq88,项目名称:PrestaShop-modules,代码行数:101,代码来源:fianetfraud.php

示例6: utf8_encode

							<div style="overflow: auto; min-height: 300px; padding-top: 0.6em;" id="categoryList">
								<script type="text/javascript">
								$(document).ready(function() {
									$(\'div#categoryList input.categoryBox\').click(function (){
										if ($(this).is(\':not(:checked)\') && $(\'div#categoryList input.id_category_default\').val() == $(this).val())
											alert(\'' . utf8_encode(html_entity_decode($adminProducts->getL('Consider changing the default category.'))) . '\');
									});
								});
								</script>
								<table cellspacing="0" cellpadding="0" class="table">
									<tr>
										<th><input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, \'categoryBox[]\', this.checked)" /></th>
										<th>' . $adminProducts->getL('ID') . '</th>
										<th style="width: 600px">' . $adminProducts->getL('Name') . '</th>
									</tr>';
$done = array();
$index = array();
$categoryBox = Tools::getValue('categoryBox');
if ($categoryBox != '') {
    $categoryBox = @unserialize($categoryBox);
    foreach ($categoryBox as $k => $row) {
        $index[] = $row;
    }
} elseif ((int) Tools::getValue('id_product')) {
    $index = Product::getProductCategories((int) Tools::getValue('id_product'));
}
$adminProducts->recurseCategoryForInclude((int) Tools::getValue('id_product'), $index, $categories, $categories[0][1], 1, (int) Tools::getValue('id_category_default'));
echo '				</table>
								<p style="padding:0px; margin:0px 0px 10px 0px;">' . $adminProducts->getL('Mark all checkbox(es) of categories in which product is to appear') . '<sup> *</sup></p>
							</div>
					</tr>';
开发者ID:greench,项目名称:prestashop,代码行数:31,代码来源:ajax_category_list.php

示例7: productImport

    public function productImport()
    {
        $this->receiveTab();
        $handle = $this->openCsvFile();
        $default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
        AdminImportController::setLocale();
        $shop_ids = Shop::getCompleteListOfShopsID();
        for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
            if (Tools::getValue('convert')) {
                $line = $this->utf8EncodeArray($line);
            }
            $info = AdminImportController::getMaskedRow($line);
            if (Tools::getValue('forceIDs') && isset($info['id']) && (int) $info['id']) {
                $product = new Product((int) $info['id']);
            } else {
                if (array_key_exists('id', $info) && (int) $info['id'] && Product::existsInDatabase((int) $info['id'], 'product')) {
                    $product = new Product((int) $info['id']);
                } else {
                    $product = new Product();
                }
            }
            if (array_key_exists('id', $info) && (int) $info['id'] && Product::existsInDatabase((int) $info['id'], 'product')) {
                $product->loadStockData();
                $category_data = Product::getProductCategories((int) $product->id);
                foreach ($category_data as $tmp) {
                    $product->category[] = $tmp;
                }
            }
            AdminImportController::setEntityDefaultValues($product);
            AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $product);
            if (!Shop::isFeatureActive()) {
                $product->shop = 1;
            } elseif (!isset($product->shop) || empty($product->shop)) {
                $product->shop = implode($this->multiple_value_separator, Shop::getContextListShopID());
            }
            if (!Shop::isFeatureActive()) {
                $product->id_shop_default = 1;
            } else {
                $product->id_shop_default = (int) Context::getContext()->shop->id;
            }
            // link product to shops
            $product->id_shop_list = array();
            foreach (explode($this->multiple_value_separator, $product->shop) as $shop) {
                if (!is_numeric($shop)) {
                    $product->id_shop_list[] = Shop::getIdByName($shop);
                } else {
                    $product->id_shop_list[] = $shop;
                }
            }
            if ((int) $product->id_tax_rules_group != 0) {
                if (Validate::isLoadedObject(new TaxRulesGroup($product->id_tax_rules_group))) {
                    $address = $this->context->shop->getAddress();
                    $tax_manager = TaxManagerFactory::getManager($address, $product->id_tax_rules_group);
                    $product_tax_calculator = $tax_manager->getTaxCalculator();
                    $product->tax_rate = $product_tax_calculator->getTotalRate();
                } else {
                    $this->addProductWarning('id_tax_rules_group', $product->id_tax_rules_group, Tools::displayError('Invalid tax rule group ID. You first need to create a group with this ID.'));
                }
            }
            if (isset($product->manufacturer) && is_numeric($product->manufacturer) && Manufacturer::manufacturerExists((int) $product->manufacturer)) {
                $product->id_manufacturer = (int) $product->manufacturer;
            } else {
                if (isset($product->manufacturer) && is_string($product->manufacturer) && !empty($product->manufacturer)) {
                    if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) {
                        $product->id_manufacturer = (int) $manufacturer;
                    } else {
                        $manufacturer = new Manufacturer();
                        $manufacturer->name = $product->manufacturer;
                        if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $manufacturer->add()) {
                            $product->id_manufacturer = (int) $manufacturer->id;
                        } else {
                            $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $manufacturer->name, isset($manufacturer->id) ? $manufacturer->id : 'null');
                            $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                        }
                    }
                }
            }
            if (isset($product->supplier) && is_numeric($product->supplier) && Supplier::supplierExists((int) $product->supplier)) {
                $product->id_supplier = (int) $product->supplier;
            } else {
                if (isset($product->supplier) && is_string($product->supplier) && !empty($product->supplier)) {
                    if ($supplier = Supplier::getIdByName($product->supplier)) {
                        $product->id_supplier = (int) $supplier;
                    } else {
                        $supplier = new Supplier();
                        $supplier->name = $product->supplier;
                        $supplier->active = true;
                        if (($field_error = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $supplier->add()) {
                            $product->id_supplier = (int) $supplier->id;
                            $supplier->associateTo($product->id_shop_list);
                        } else {
                            $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $supplier->name, isset($supplier->id) ? $supplier->id : 'null');
                            $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                        }
                    }
                }
            }
            if (isset($product->price_tex) && !isset($product->price_tin)) {
                $product->price = $product->price_tex;
            } else {
//.........这里部分代码省略.........
开发者ID:FAVHYAN,项目名称:a3workout,代码行数:101,代码来源:AdminImportController.php

示例8: dirname

require_once dirname(__FILE__) . '/categorysearch.php';
$module = new CategorySearch();
$context = Context::getContext();
$query = Tools::replaceAccentedChars(urldecode(Tools::getValue('q')));
$original_query = Tools::getValue('q');
$id_category = Tools::getValue('id_category');
if ($id_category == 'all') {
    $searchResults = Search::find((int) Tools::getValue('id_lang'), $query, 1, (int) Tools::getValue('limit', 10), 'position', 'desc', true);
    $results = array();
    foreach ($searchResults as $product) {
        $cover = Product::getCover($product['id_product']);
        $product['product_link'] = $context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']);
        $product['product_image'] = $context->link->getImageLink($product['prewrite'], $cover['id_image'], 'home_default');
        $product['id_category'] = $id_category;
        $results[] = $product;
    }
} else {
    $searchResults = Search::find((int) Tools::getValue('id_lang'), $query, 1, (int) Tools::getValue('limit', 10), 'position', 'desc', true);
    $results = array();
    foreach ($searchResults as $product) {
        $allCategories = Product::getProductCategories($product['id_product']);
        if (in_array((int) $id_category, $allCategories)) {
            $cover = Product::getCover($product['id_product']);
            $product['product_link'] = $context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']);
            $product['product_image'] = $context->link->getImageLink($product['prewrite'], $cover['id_image'], 'home_default');
            $product['id_category'] = $id_category;
            $results[] = $product;
        }
    }
}
die(Tools::jsonEncode($results));
开发者ID:abdoumej,项目名称:libsamy,代码行数:31,代码来源:finds.php

示例9: execImport

 public static function execImport($pdt)
 {
     if ($pdt->id_product > 0) {
         $product = new Product($pdt->id_product);
     } else {
         $product = new Product();
     }
     if (version_compare(_PS_VERSION_, '1.5', '>=')) {
         foreach (Product::$definition['fields'] as $field => $value) {
             if (isset($pdt->{$field})) {
                 if (is_object($pdt->{$field})) {
                     $fields = array();
                     foreach ($pdt->{$field} as $key => $value) {
                         $fields[$key] = $value;
                     }
                     $product->{$field} = $fields;
                 } else {
                     $product->{$field} = $pdt->{$field};
                 }
             }
         }
     } else {
         $product->id_manufacturer = $pdt->id_manufacturer;
         $product->id_supplier = $pdt->id_supplier;
         if ($pdt->reference) {
             $product->reference = $pdt->reference;
         }
         $product->supplier_reference = $pdt->supplier_reference;
         $product->weight = $pdt->weight;
         $product->id_category_default = $pdt->id_category_default;
         if ($pdt->id_tax_rules_group) {
             $product->id_tax_rules_group = $pdt->id_tax_rules_group;
         }
         if ($pdt->price) {
             $product->price = $pdt->price;
         }
         if ($pdt->wholesale_price) {
             $product->wholesale_price = $pdt->wholesale_price;
         }
         if ($pdt->active) {
             $product->active = $pdt->active;
         }
         if ($pdt->date_add) {
             $product->date_add = $pdt->date_add;
         }
         $product->date_upd = $pdt->date_upd;
         if ($pdt->link_rewrite) {
             foreach ($pdt->link_rewrite as $key => $value) {
                 $product->link_rewrite[$key] = $value;
             }
         }
         if ($pdt->name) {
             foreach ($pdt->name as $key => $value) {
                 $product->name[$key] = $value;
             }
         }
         if ($pdt->description) {
             foreach ($pdt->description as $key => $value) {
                 $product->description[$key] = $value;
             }
         }
         if ($pdt->description_short) {
             foreach ($pdt->description_short as $key => $value) {
                 $product->description_short[$key] = $value;
             }
         }
         if ($pdt->ean13) {
             $product->ean13 = $pdt->ean13;
         }
     }
     if ($pdt->upd_index == 1) {
         $product->indexed = 1;
     }
     if (version_compare(_PS_VERSION_, '1.5', '>=')) {
         $product->id_shop_list[] = $pdt->shop;
     }
     $product->id_category[] = $pdt->categories;
     $product->id_category[] = $pdt->sscategories;
     if ($pdt->id_product) {
         $category_data = Product::getProductCategories((int) $product->id);
         foreach ($category_data as $tmp) {
             $product->id_category[] = $tmp;
         }
     }
     $product->id_category = array_unique($product->id_category);
     $product->save();
     if ($pdt->upd_img == 1 || !$pdt->id_product) {
         self::execImages($pdt, $product);
         self::cleanUploadedImages($pdt, $product);
     }
     if (version_compare(_PS_VERSION_, '1.5', '>=')) {
         if (!$pdt->id_product) {
             self::insertSupplierRef($product->id, 0, $pdt->id_supplier, $pdt->supplier_reference);
         }
     }
     if ($pdt->upd_index == 1) {
         Search::indexation(false, $pdt->id_product);
     }
     $product->updateCategories(array_map('intval', $product->id_category));
     return $product->id;
//.........这里部分代码省略.........
开发者ID:ventsiwad,项目名称:presta_addons,代码行数:101,代码来源:importProduct.class.php

示例10: addSubscriber

 public function addSubscriber($params, $campaign_id, $action, $cycle_day)
 {
     $allowed = array('order', 'create');
     $prefix = 'customer';
     //add_contact
     if (!empty($action) && in_array($action, $allowed) == true && $action == 'create') {
         if (isset($params['newNewsletterContact'])) {
             $prefix = 'newNewsletterContact';
         } else {
             $prefix = 'newCustomer';
         }
         $customs = $this->mapCustoms($params[$prefix], null, 'create');
         if (isset($params[$prefix]->newsletter) && $params[$prefix]->newsletter == 1) {
             $this->addContact($campaign_id, $params[$prefix]->firstname, $params[$prefix]->lastname, $params[$prefix]->email, $cycle_day, $customs);
         }
     } else {
         //update_contact
         $contact = $this->getContacts($params[$prefix]->email, null);
         $customs = $this->mapCustoms($contact, $_POST, 'order');
         // automation
         if (!empty($params['order']->product_list)) {
             $categories = array();
             foreach ($params['order']->product_list as $products) {
                 $temp_categories = Product::getProductCategories($products['id_product']);
                 foreach ($temp_categories as $tmp) {
                     $categories[$tmp] = $tmp;
                 }
             }
             $automations = $this->getAutomationSettings('active');
             if (!empty($automations)) {
                 $default = false;
                 foreach ($automations as $automation) {
                     if (in_array($automation['category_id'], $categories)) {
                         // do automation
                         if ($automation['action'] == 'move') {
                             $this->moveContactToGr($automation['campaign_id'], $params[$prefix]->firstname, $params[$prefix]->lastname, $params[$prefix]->email, $customs, $cycle_day);
                         } elseif ($automation['action'] == 'copy') {
                             $this->addContact($automation['campaign_id'], $params[$prefix]->firstname, $params[$prefix]->lastname, $params[$prefix]->email, $cycle_day, $customs);
                         }
                     } else {
                         $default = true;
                     }
                 }
                 if ($default === true && isset($params[$prefix]->newsletter) && $params[$prefix]->newsletter == 1) {
                     $this->addContact($campaign_id, $params[$prefix]->firstname, $params[$prefix]->lastname, $params[$prefix]->email, $cycle_day, $customs);
                 }
             } else {
                 if (isset($params[$prefix]->newsletter) && $params[$prefix]->newsletter == 1) {
                     $this->addContact($campaign_id, $params[$prefix]->firstname, $params[$prefix]->lastname, $params[$prefix]->email, $cycle_day, $customs);
                 }
             }
         } else {
             if (isset($params[$prefix]->newsletter) && $params[$prefix]->newsletter == 1) {
                 $this->addContact($campaign_id, $params[$prefix]->firstname, $params[$prefix]->lastname, $params[$prefix]->email, $cycle_day, $customs);
             }
         }
     }
     return true;
 }
开发者ID:GetResponse,项目名称:GetResponse-PrestaShop-Integration,代码行数:59,代码来源:DbConnection.php

示例11: productImport

    public function productImport()
    {
        $this->receiveTab();
        $handle = $this->openCsvFile();
        $default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
        $id_lang = Language::getIdByIso(Tools::getValue('iso_lang'));
        if (!Validate::isUnsignedId($id_lang)) {
            $id_lang = $default_language_id;
        }
        AdminImportController::setLocale();
        $shop_ids = Shop::getCompleteListOfShopsID();
        for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
            if (Tools::getValue('convert')) {
                $line = $this->utf8EncodeArray($line);
            }
            $info = AdminImportController::getMaskedRow($line);
            if (self::ignoreRow($info)) {
                continue;
            }
            if (Tools::getValue('forceIDs') && isset($info['id']) && (int) $info['id']) {
                $product = new Product((int) $info['id']);
            } elseif (Tools::getValue('match_ref') && array_key_exists('reference', $info)) {
                $datas = Db::getInstance()->getRow('
						SELECT p.`id_product`
						FROM `' . _DB_PREFIX_ . 'product` p
						' . Shop::addSqlAssociation('product', 'p') . '
						WHERE p.`reference` = "' . pSQL($info['reference']) . '"
					');
                if (isset($datas['id_product']) && $datas['id_product']) {
                    $product = new Product((int) $datas['id_product']);
                } else {
                    $product = new Product();
                }
            } else {
                if (array_key_exists('id', $info) && is_string($info['id'])) {
                    $prod = self::findProductByName($default_language_id, $info['id'], $info['name']);
                    if ($prod['id_product']) {
                        $info['id'] = (int) $prod['id_product'];
                    }
                }
                if (array_key_exists('id', $info) && (int) $info['id'] && Product::existsInDatabase((int) $info['id'], 'product')) {
                    $product = new Product((int) $info['id']);
                    $product->loadStockData();
                    $category_data = Product::getProductCategories((int) $product->id);
                    if (is_array($category_data)) {
                        foreach ($category_data as $tmp) {
                            if (!isset($product->category) || !$product->category || is_array($product->category)) {
                                $product->category[] = $tmp;
                            }
                        }
                    }
                } else {
                    $product = new Product();
                }
            }
            AdminImportController::setEntityDefaultValues($product);
            AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $product);
            if (!Shop::isFeatureActive()) {
                $product->shop = 1;
            } elseif (!isset($product->shop) || empty($product->shop)) {
                $product->shop = implode($this->multiple_value_separator, Shop::getContextListShopID());
            }
            if (!Shop::isFeatureActive()) {
                $product->id_shop_default = 1;
            } else {
                $product->id_shop_default = (int) Context::getContext()->shop->id;
            }
            $product->id_shop_list = array();
            foreach (explode($this->multiple_value_separator, $product->shop) as $shop) {
                if (!empty($shop) && !is_numeric($shop)) {
                    $product->id_shop_list[] = Shop::getIdByName($shop);
                } elseif (!empty($shop)) {
                    $product->id_shop_list[] = $shop;
                }
            }
            if ((int) $product->id_tax_rules_group != 0) {
                if (Validate::isLoadedObject(new TaxRulesGroup($product->id_tax_rules_group))) {
                    $address = $this->context->shop->getAddress();
                    $tax_manager = TaxManagerFactory::getManager($address, $product->id_tax_rules_group);
                    $product_tax_calculator = $tax_manager->getTaxCalculator();
                    $product->tax_rate = $product_tax_calculator->getTotalRate();
                } else {
                    $this->addProductWarning('id_tax_rules_group', $product->id_tax_rules_group, Tools::displayError('Invalid tax rule group ID. You first need to create a group with this ID.'));
                }
            }
            if (isset($product->manufacturer) && is_numeric($product->manufacturer) && Manufacturer::manufacturerExists((int) $product->manufacturer)) {
                $product->id_manufacturer = (int) $product->manufacturer;
            } elseif (isset($product->manufacturer) && is_string($product->manufacturer) && !empty($product->manufacturer)) {
                if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) {
                    $product->id_manufacturer = (int) $manufacturer;
                } else {
                    $manufacturer = new Manufacturer();
                    $manufacturer->name = $product->manufacturer;
                    if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $manufacturer->add()) {
                        $product->id_manufacturer = (int) $manufacturer->id;
                    } else {
                        $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $manufacturer->name, isset($manufacturer->id) && !empty($manufacturer->id) ? $manufacturer->id : 'null');
                        $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                    }
                }
//.........这里部分代码省略.........
开发者ID:Oldwo1f,项目名称:yakaboutique,代码行数:101,代码来源:AdminImportController.php

示例12: assign

 /**
  * Assign search template
  */
 public function assign()
 {
     $query = Tools::replaceAccentedChars(urldecode(Tools::getValue('q')));
     $original_query = Tools::getValue('q');
     $id_category = Tools::getValue('id_category');
     if (Tools::getValue('ajax_Search')) {
         $searchResults = Search::find((int) Tools::getValue('id_lang'), $query, 1, (int) Tools::getValue('limit', 10), 'position', 'desc', true);
         $results = array();
         foreach ($searchResults as $product) {
             $cover = Product::getCover($product['id_product']);
             $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']);
             $product['product_image'] = $this->context->link->getImageLink($product['prewrite'], $cover['id_image'], 'home_default');
             $product['id_category'] = $id_category;
             $product['categories'] = Product::getProductCategories($product['id_product']);
             if ($id_category == 'all' || in_array((int) $id_category, Product::getProductCategories($product['id_product']))) {
                 $results[] = $product;
             }
         }
         die(Tools::jsonEncode($results));
     }
     if (Tools::getValue('instantSearch') && !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
         $this->p = abs((int) Tools::getValue('p', 1));
         $search = Search::find($this->context->language->id, $query, 1, 10, 'position', 'desc');
         Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total']));
         $results = array();
         $index = 0;
         foreach ($search['result'] as $product) {
             $categories_id = Product::getProductCategories($product['id_product']);
             if (in_array((int) $id_category, Product::getProductCategories($product['id_product']))) {
                 if (($this->p - 1) * $this->n <= $index && $index < $this->p * $this->n) {
                     $results[] = $product;
                 }
                 $index++;
             }
         }
         $nbProducts = $index;
         $this->pagination($nbProducts);
         $this->addColorsToProductList($results);
         $this->context->smarty->assign(array('products' => $results, 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $original_query, 'instant_search' => $this->instant_search, 'request' => $this->context->link->getModuleLink('categorysearch', 'catesearch'), 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
     } elseif (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
         $this->p = abs((int) Tools::getValue('p', 1));
         $original_query = $query;
         $query = Tools::replaceAccentedChars(urldecode($query));
         $search = Search::find($this->context->language->id, $query, $this->p, $this->n, $this->orderBy, $this->orderWay);
         //if($this->orderBy == 'price') $search['result'] = Tools::orderbyPrice($search['result'], $this->orderWay);
         //print_r($search['result']);
         //die;
         foreach ($search['result'] as &$product) {
             $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&') . 'search_query=' . urlencode($query) . '&results=' . (int) $search['total'];
         }
         $results = array();
         $id_category = Tools::getValue('search_category', 'all');
         Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total']));
         $nbProducts = $search['total'];
         $this->context->smarty->assign(array('search_query' => $original_query, 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
         if ($id_category == 'all') {
             $this->pagination($nbProducts);
             $this->addColorsToProductList($search['result']);
             $this->context->smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'nbp' => $this->p, 'nbn' => $this->n, 'orderby' => $this->orderBy, 'orderWay' => $this->orderWay, 'request' => $this->context->link->getModuleLink('categorysearch', 'catesearch')));
         } else {
             $search = Search::find($this->context->language->id, $query, 1, $nbProducts, $this->orderBy, $this->orderWay);
             $results = array();
             $index = 0;
             foreach ($search['result'] as $product) {
                 $categories_id = Product::getProductCategories($product['id_product']);
                 if (in_array((int) $id_category, Product::getProductCategories($product['id_product']))) {
                     if (($this->p - 1) * $this->n <= $index && $index < $this->p * $this->n) {
                         $results[] = $product;
                     }
                     $index++;
                 }
             }
             $nbProducts = $index;
             foreach ($results as &$product) {
                 $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&') . 'search_query=' . urlencode($query) . '&results=' . (int) $nbProducts;
             }
             $this->pagination($nbProducts);
             $this->addColorsToProductList($results);
             $this->context->smarty->assign(array('products' => $results, 'search_products' => $results, 'nbProducts' => $nbProducts, 'nbp' => $this->p, 'nbn' => $this->n, 'orderby' => $this->orderBy, 'orderWay' => $this->orderWay, 'request' => $this->context->link->getModuleLink('categorysearch', 'catesearch')));
         }
     } else {
         $this->context->smarty->assign(array('products' => array(), 'search_products' => array(), 'pages_nb' => 1, 'nbProducts' => 0));
     }
     $this->context->smarty->assign(array('add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM')));
     $this->setTemplate('searchresult.tpl');
 }
开发者ID:habypk,项目名称:zocart,代码行数:93,代码来源:catesearch.php

示例13: sendXML

 /**
  * build xml with customer's and order's data et send it to FIA-NET
  * 
  * @param int $id_order
  * @return boolean 
  */
 public function sendXML($id_order)
 {
     $order = new Order($id_order);
     $montant = $order->total_paid;
     $date = $order->date_add;
     $customer = new Customer($order->id_customer);
     $lastname = $customer->lastname;
     $firstname = $customer->firstname;
     $id_currency = $order->id_currency;
     $currency = new Currency($id_currency);
     if (_PS_VERSION_ < '1.5') {
         $civility = $customer->id_gender;
         $accepted_civility = array("1", "2", "3");
         if (!in_array($civility, $accepted_civility)) {
             $civility = '1';
         }
         $id_shop = 1;
         $fianetsceau = new Sceau();
     } else {
         $gender = new Gender($customer->id_gender);
         $id_lang = Language::getIdByIso($this->context->language->iso_code);
         $civility = $gender->name[$id_lang] == 'Mr.' ? 1 : 2;
         $id_shop = (int) $order->id_shop;
         $fianetsceau = new Sceau($id_shop);
     }
     $lang = Language::getIsoById($order->id_lang) == 'fr' ? 'fr' : 'uk';
     $sceaucontrol = new SceauControl();
     $sceaucontrol->createCustomer('', $civility, $customer->lastname, $customer->firstname, strtolower($customer->email));
     $sceaucontrol->createOrderDetails($id_order, $fianetsceau->getSiteid(), $order->total_paid, 'EUR', $this->getCustomerIP($id_order), $order->date_add, $lang);
     //get default FIA-NET category
     $default_product_type = $this->getFianetSubCategoryId(0, $id_shop);
     $products = $order->getProducts();
     $productsceau = $sceaucontrol->createOrderProducts();
     foreach ($products as $product) {
         $product_categories = Product::getProductCategories((int) $product['product_id']);
         $product_category = array_pop($product_categories);
         $prod = new Product($product['product_id']);
         //gets the product FIA-NET category
         $product_type = $this->getFianetSubCategoryId($product_category, $id_shop);
         if (!empty($prod->ean13) && ($prod->ean13 != 0 || $prod->ean13 != '')) {
             $codeean = $prod->ean13;
         } else {
             $codeean = null;
         }
         $reference = (isset($prod->reference) and !empty($prod->reference)) ? $prod->reference : $product['product_id'];
         if ($product_type) {
             //if a FIA-NET category is set: the type attribute takes the product FIA-NET type value
             $fianet_type = $product_type;
         } else {
             //if FIA-NET category not set: the type attribute takes the default value
             $fianet_type = $default_product_type;
         }
         //get product image
         $images = Product::getCover($product['product_id']);
         if (!empty($images)) {
             $image = new Image($images['id_image']);
             $image_url = _PS_BASE_URL_ . _THEME_PROD_DIR_ . $image->getExistingImgPath() . "." . $image->image_format;
         }
         $productsceau->createProduct($codeean, str_replace("'", "", $reference), $fianet_type, str_replace("'", "", $product['product_name']), (string) $product['product_price_wt'], $image_url);
     }
     $sceaucontrol->createPayment($this->getPaymentFianetType($id_order));
     $fianetsceau->addCrypt($sceaucontrol);
     $result = $fianetsceau->sendSendrating($sceaucontrol);
     if (isXMLstringSceau($result)) {
         $resxml = new SceauSendratingResponse($result);
         if ($resxml->isValid()) {
             //update fianetsceau_state 2:sent
             $this->updateOrder($id_order, array('id_fianetsceau_state' => '2'));
             SceauLogger::insertLogSceau(__METHOD__ . " : " . __LINE__, 'Order ' . $id_order . ' sended');
             return true;
         } else {
             //update fianetsceau_state 3:error
             $this->updateOrder($id_order, array('id_fianetsceau_state' => '3'));
             SceauLogger::insertLogSceau(__METHOD__ . " : " . __LINE__, 'Order ' . $id_order . ' XML send error : ' . $resxml->getDetail());
             return false;
         }
     } else {
         //update fianetsceau_state 3:error
         $this->updateOrder($id_order, array('id_fianetsceau_state' => '3'));
         SceauLogger::insertLogSceau(__METHOD__ . " : " . __LINE__, 'Order ' . $id_order . ' XML send error : ' . $resxml->getDetail());
         return false;
     }
 }
开发者ID:ventsiwad,项目名称:presta_addons,代码行数:89,代码来源:fianetsceau.php

示例14: validateOrder


//.........这里部分代码省略.........
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (isset($customization['datas'][_CUSTOMIZE_FILE_])) {
                                $customizationText .= sizeof($customization['datas'][_CUSTOMIZE_FILE_]) . ' ' . Tools::displayError('image(s)') . '<br />';
                            }
                            $customizationText .= '---<br />';
                        }
                        $customizationText = rtrim($customizationText, '---<br />');
                        $customizationQuantity = (int) $product['customizationQuantityTotal'];
                        $productsList .= '<tr style="background-color: ' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';">
							<td style="padding: 0.6em 0.4em;">' . $product['reference'] . '</td>
							<td style="padding: 0.6em 0.4em;"><strong>' . $product['name'] . (isset($product['attributes_small']) ? ' ' . $product['attributes_small'] : '') . ' - ' . $this->l('Customized') . (!empty($customizationText) ? ' - ' . $customizationText : '') . '</strong></td>
							<td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice(round(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false) . '</td>
							<td style="padding: 0.6em 0.4em; text-align: center;">' . $customizationQuantity . '</td>
							<td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice($customizationQuantity * round(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false) . '</td>
						</tr>';
                    }
                    if (!$customizationQuantity or (int) $product['cart_quantity'] > $customizationQuantity) {
                        $productsList .= '<tr style="background-color: ' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';">
							<td style="padding: 0.6em 0.4em;">' . $product['reference'] . '</td>
							<td style="padding: 0.6em 0.4em;"><strong>' . $product['name'] . (isset($product['attributes_small']) ? ' ' . $product['attributes_small'] : '') . '</strong></td>
							<td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice(round(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false) . '</td>
							<td style="padding: 0.6em 0.4em; text-align: center;">' . ((int) $product['cart_quantity'] - $customizationQuantity) . '</td>
							<td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice(((int) $product['cart_quantity'] - $customizationQuantity) * round(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false) . '</td>
						</tr>';
                    }
                    //if giftcard, create voucher and send the mails now.
                    $categories = Product::getProductCategories($product['id_product']);
                    if (in_array(CAT_GIFTCARD, $categories)) {
                        $friendsName = '';
                        $friendsEmail = '';
                        $giftMessage = '';
                        foreach ($customizedDatas[$product['id_product']][$product['id_product_attribute']] as $customization) {
                            if (isset($customization['datas'][_CUSTOMIZE_TEXTFIELD_])) {
                                foreach ($customization['datas'][_CUSTOMIZE_TEXTFIELD_] as $text) {
                                    if ($text['index'] == 21) {
                                        $friendsName = $text['value'];
                                    } else {
                                        if ($text['index'] == 22) {
                                            $friendsEmail = $text['value'];
                                        } else {
                                            if ($text['index'] == 23) {
                                                $giftMessage = $text['value'];
                                            } else {
                                                if ($text['index'] == 25) {
                                                    $couponCode = $text['value'];
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        //$couponCode = "GC" . Tools::rand_string(8);
                        // create discount
                        $languages = Language::getLanguages($order);
                        $voucher = new Discount();
                        $voucher->id_discount_type = 2;
                        foreach ($languages as $language) {
                            $voucher->description[$language['id_lang']] = $product['name'];
开发者ID:priyankajsr19,项目名称:indusdiva2,代码行数:67,代码来源:PaymentModule.php

示例15: productImport

 public function productImport()
 {
     global $cookie;
     $this->receiveTab();
     $handle = $this->openCsvFile();
     $defaultLanguageId = (int) Configuration::get('PS_LANG_DEFAULT');
     self::setLocale();
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, Tools::getValue('separator')); $current_line++) {
         if (Tools::getValue('convert')) {
             $line = $this->utf8_encode_array($line);
         }
         $info = self::getMaskedRow($line);
         if (array_key_exists('id', $info) and (int) $info['id'] and Product::existsInDatabase((int) $info['id'], 'product')) {
             $product = new Product((int) $info['id']);
             $categoryData = Product::getProductCategories((int) $product->id);
             foreach ($categoryData as $tmp) {
                 $product->category[] = $tmp;
             }
         } else {
             $product = new Product();
         }
         self::setEntityDefaultValues($product);
         self::array_walk($info, array('AdminImport', 'fillInfo'), $product);
         if ((int) $product->id_tax_rules_group != 0) {
             if (Validate::isLoadedObject(new TaxRulesGroup($product->id_tax_rules_group))) {
                 $product->tax_rate = TaxRulesGroup::getTaxesRate((int) $product->id_tax_rules_group, Configuration::get('PS_COUNTRY_DEFAULT'), 0, 0);
             } else {
                 $this->_addProductWarning('id_tax_rules_group', $product->id_tax_rules_group, Tools::displayError('Invalid tax rule group ID, you first need a group with this ID.'));
             }
         }
         if (isset($product->manufacturer) and is_numeric($product->manufacturer) and Manufacturer::manufacturerExists((int) $product->manufacturer)) {
             $product->id_manufacturer = (int) $product->manufacturer;
         } elseif (isset($product->manufacturer) and is_string($product->manufacturer) and !empty($product->manufacturer)) {
             if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) {
                 $product->id_manufacturer = (int) $manufacturer;
             } else {
                 $manufacturer = new Manufacturer();
                 $manufacturer->name = $product->manufacturer;
                 if (($fieldError = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $manufacturer->add()) {
                     $product->id_manufacturer = (int) $manufacturer->id;
                 } else {
                     $this->_errors[] = $manufacturer->name . (isset($manufacturer->id) ? ' (' . $manufacturer->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
                     $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
                 }
             }
         }
         if (isset($product->supplier) and is_numeric($product->supplier) and Supplier::supplierExists((int) $product->supplier)) {
             $product->id_supplier = (int) $product->supplier;
         } elseif (isset($product->supplier) and is_string($product->supplier) and !empty($product->supplier)) {
             if ($supplier = Supplier::getIdByName($product->supplier)) {
                 $product->id_supplier = (int) $supplier;
             } else {
                 $supplier = new Supplier();
                 $supplier->name = $product->supplier;
                 if (($fieldError = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $supplier->add()) {
                     $product->id_supplier = (int) $supplier->id;
                 } else {
                     $this->_errors[] = $supplier->name . (isset($supplier->id) ? ' (' . $supplier->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
                     $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
                 }
             }
         }
         if (isset($product->price_tex) and !isset($product->price_tin)) {
             $product->price = $product->price_tex;
         } elseif (isset($product->price_tin) and !isset($product->price_tex)) {
             $product->price = $product->price_tin;
             // If a tax is already included in price, withdraw it from price
             if ($product->tax_rate) {
                 $product->price = (double) number_format($product->price / (1 + $product->tax_rate / 100), 6, '.', '');
             }
         } elseif (isset($product->price_tin) and isset($product->price_tex)) {
             $product->price = $product->price_tex;
         }
         if (isset($product->category) and is_array($product->category) and sizeof($product->category)) {
             $product->id_category = array();
             // Reset default values array
             foreach ($product->category as $value) {
                 if (is_numeric($value)) {
                     if (Category::categoryExists((int) $value)) {
                         $product->id_category[] = (int) $value;
                     } else {
                         $categoryToCreate = new Category();
                         $categoryToCreate->id = (int) $value;
                         $categoryToCreate->name = self::createMultiLangField($value);
                         $categoryToCreate->active = 1;
                         $categoryToCreate->id_parent = 1;
                         // Default parent is home for unknown category to create
                         if (($fieldError = $categoryToCreate->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $categoryToCreate->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $categoryToCreate->add()) {
                             $product->id_category[] = (int) $categoryToCreate->id;
                         } else {
                             $this->_errors[] = $categoryToCreate->name[$defaultLanguageId] . (isset($categoryToCreate->id) ? ' (' . $categoryToCreate->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
                             $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
                         }
                     }
                 } elseif (is_string($value) and !empty($value)) {
                     $category = Category::searchByName($defaultLanguageId, $value, true);
                     if ($category['id_category']) {
                         $product->id_category[] = (int) $category['id_category'];
                     } else {
                         $categoryToCreate = new Category();
//.........这里部分代码省略.........
开发者ID:greench,项目名称:prestashop,代码行数:101,代码来源:AdminImport.php


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