Example #1
0
 function valuesToForm(&$ret, Product $record)
 {
     if ($record->isLoaded()) {
         $ret['_categories'] = $record->getCategories();
         $ret['_plan'] = array();
         foreach ($record->getBillingPlans() as $plan) {
             $arr = $plan->toArray();
             $arr['paysys_id'] = $arr['paysys_id'] ? explode(',', $arr['paysys_id']) : array();
             if (!empty($arr['rebill_times'])) {
                 $arr['_rebill_times'] = $arr['rebill_times'];
                 if (!in_array($arr['rebill_times'], array(0, 1, IProduct::RECURRING_REBILLS))) {
                     $arr['_rebill_times'] = 'x';
                 }
             }
             foreach (array('first_period', 'second_period') as $f) {
                 if (array_key_exists($f, $arr)) {
                     $arr[$f] = new Am_Period($arr[$f]);
                 }
             }
             $ret['_plan'][$plan->pk()] = $arr;
         }
     }
 }
 /**
  * @param \Product $product
  *
  * @return string
  * @throws \Exception
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since 150213
  */
 protected function getProductCategories(\Product &$product)
 {
     $categories = array();
     if ($this->Options->getValue('map_category') == 1) {
         $info = \Tag::getProductTags($product->id);
         if ($info && !isset($info[$this->defaultLang])) {
             $categories = (array) $info[$this->defaultLang];
         }
     } else {
         $info = \Category::getCategoryInformations($product->getCategories());
         if (!is_array($info) || empty($info)) {
             return '';
         }
         foreach ((array) $info as $cat) {
             // Todo is there a better way to check for home category?
             if ($cat['id_category'] == 2) {
                 continue;
             }
             array_push($categories, $cat['name']);
         }
     }
     return implode(' - ', (array) $categories);
 }
 $data[] = $product->height . " mt";
 $data[] = $product->blouse_length . "cm";
 if (is_array($product->tags[1])) {
     $data[] = implode(";", $product->tags[1]);
 } else {
     $data[] = "";
 }
 $data[] = $product->shipping_sla;
 $data[] = $product->color;
 $data[] = $product->generic_color;
 $data[] = $product->fabric;
 $data[] = $product->work_type;
 $data[] = "Dry cleaning is the best method to wash an apparel made of soft and delicate material. Never wrap silk apparel in plastic and trap the moisture; this could change the color and quality of the fabric in no time.";
 $data[] = $product->category;
 //occasion
 $id_categories = $product->getCategories();
 $this_occasion = array();
 if (in_array(41, $id_categories)) {
     array_push($this_occasion, 'Festive');
 }
 if (in_array(42, $id_categories)) {
     array_push($this_occasion, 'Wedding');
 }
 if (in_array(43, $id_categories)) {
     array_push($this_occasion, 'Wedding');
 }
 if (in_array(44, $id_categories)) {
     array_push($this_occasion, 'Casual');
 }
 if (in_array(45, $id_categories)) {
     array_push($this_occasion, 'Formal');
Example #4
0
 /**
  * Builds the category paths the product belongs to and returns them.
  *
  * By "path" we mean the full tree path of the products categories and sub-categories.
  *
  * @param Product $product the product model.
  * @param int $id_lang for which language ID to fetch the categories.
  * @return array the built category paths.
  */
 protected function buildCategories(Product $product, $id_lang)
 {
     $categories = array();
     foreach ($product->getCategories() as $category_id) {
         $category = NostoTaggingCategory::buildCategoryString($category_id, $id_lang);
         if (!empty($category)) {
             $categories[] = $category;
         }
     }
     return $categories;
 }
Example #5
0
	/**
	 *
	 * @param int $id_zone
	 * @param Array $groups group of the customer
	 * @return Array
	 */
	public static function getCarriersForOrder($id_zone, $groups = null, $cart = null)
	{
		$context = Context::getContext();
		$id_lang = $context->language->id;
		if (is_null($cart))
			$cart = $context->cart;
		$id_currency = $context->currency->id;

		if (is_array($groups) && !empty($groups))
			$result = Carrier::getCarriers($id_lang, true, false, (int)$id_zone, $groups, self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
		else
			$result = Carrier::getCarriers($id_lang, true, false, (int)$id_zone, array(Configuration::get('PS_UNIDENTIFIED_GROUP')), self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
		$results_array = array();
                
		foreach ($result as $k => $row)
		{
			$carrier = new Carrier((int)$row['id_carrier']);
			$shipping_method = $carrier->getShippingMethod();
			if ($shipping_method != Carrier::SHIPPING_METHOD_FREE)
			{
				// Get only carriers that are compliant with shipping method
				if (($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false)
					|| ($shipping_method == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false))
				{
					unset($result[$k]);
					continue;
				}

				// If out-of-range behavior carrier is set on "Desactivate carrier"
				if ($row['range_behavior'])
				{
					// Get id zone
					if (!$id_zone)
							$id_zone = Country::getIdZone(Country::getDefaultCountryId());

					// Get only carriers that have a range compatible with cart
					if (($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT
						&& (!Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone)))
						|| ($shipping_method == Carrier::SHIPPING_METHOD_PRICE
						&& (!Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $id_currency))))
					{
						unset($result[$k]);
						continue;
					}
				}
			}

			$row['name'] = (strval($row['name']) != '0' ? $row['name'] : Configuration::get('PS_SHOP_NAME'));
			$row['price'] = (($shipping_method == Carrier::SHIPPING_METHOD_FREE) ? 0 : $cart->getPackageShippingCost((int)$row['id_carrier'], true, null, null, $id_zone));
			$row['price_tax_exc'] = (($shipping_method == Carrier::SHIPPING_METHOD_FREE) ? 0 : $cart->getPackageShippingCost((int)$row['id_carrier'], false, null, null, $id_zone));
			$row['img'] = file_exists(_PS_SHIP_IMG_DIR_.(int)$row['id_carrier']).'.jpg' ? _THEME_SHIP_DIR_.(int)$row['id_carrier'].'.jpg' : '';

			// If price is false, then the carrier is unavailable (carrier module)
			if ($row['price'] === false)
			{
                            $row['price'] = 0;
//				unset($result[$k]);
//				continue;
			}

			//Проверка, если способ доставки - DP, то этот способ доставки доступен, если в корзине только книги
			$DeutschePostCarrierName = "Deutsche Post"; //название службы доставки "Deutsche post"
			$books_cat_id = 12; //id категории книги
			if ($row['name'] == $DeutschePostCarrierName) {
				$cart_products = $cart->getProducts();
				if (!empty($cart_products))
				{
					$all_books = true;
					foreach ($cart_products as $key => $cart_product)
					{
						$product = new Product($cart_product['id_product']);
						$categories = $product->getCategories();
						if (!empty($categories))
						{
							$product_is_book = false;
							foreach ($categories as $key => $category) 
							{
								$log .= "категория = ".var_export($category,true)."; ";
								if ($category == $books_cat_id)
								{
									$product_is_book = true;
									break;
								}
							}
						}
						if (!$product_is_book) {
							$all_books = false;
							break;
						}
					}
					if (!$all_books){
						unset($result[$k]);
						continue;
					}
				}
				
			}
			//Конец проверки

			$results_array[] = $row;
		}
		file_put_contents($log_file, $log);

		// if we have to sort carriers by price
		$prices = array();
		if (Configuration::get('PS_CARRIER_DEFAULT_SORT') == Carrier::SORT_BY_PRICE)
		{
			foreach ($results_array as $r)
				$prices[] = $r['price'];
			if (Configuration::get('PS_CARRIER_DEFAULT_ORDER') == Carrier::SORT_BY_ASC)
				array_multisort($prices, SORT_ASC, SORT_NUMERIC, $results_array);
			else
				array_multisort($prices, SORT_DESC, SORT_NUMERIC, $results_array);
		}

		return $results_array;
	}
Example #6
0
 if (isset($productObj->generic_color) && !empty($productObj->generic_color)) {
     $colors = explode(',', $productObj->generic_color);
     foreach ($colors as $c) {
         $color = strtolower(preg_replace('/\\s+/', '-', trim($c)));
     }
 }
 $fabric = '';
 if (isset($productObj->fabric) && !empty($productObj->fabric)) {
     $fabric = $productObj->fabric;
 }
 $availability = 'TRUE';
 $quantity = Product::getQuantity($id_product);
 if ((int) $quantity < 1) {
     $availability = 'FALSE';
 }
 $catIds = $productObj->getCategories();
 $category_names = array();
 foreach ($catIds as $catID) {
     $category = new Category((int) $catID);
     $category_names[] = $category->getName(1);
 }
 $category_names = array_diff($category_names, array('Home'));
 $categories = implode(',', $category_names);
 $category = 'Other';
 if (in_array(CAT_SAREE, $catIds)) {
     $category = 'Saree';
 } elseif (in_array(CAT_SKD, $catIds)) {
     if (in_array(CAT_ANARKALI, $catIds)) {
         $category = 'Anarkali';
     } else {
         $category = 'SKD';
Example #7
0
 public static function isBook($cart_products)
 {
     //Этот способ находит книги во вложенных категориях 20.06.2015
     $books_cat_ru_name = "Книги";
     $parent_for_books_cat_id = 2;
     $books_KNIGI_lang = 1;
     //echo "поиск категории Книги";
     $bookscat = Category::searchByNameAndParentCategoryId($books_KNIGI_lang, $books_cat_ru_name, $parent_for_books_cat_id);
     //var_dump($bookscat);
     $books_cat_id = $bookscat["id_category"];
     $books_nleft = $bookscat["nleft"];
     $books_nright = $bookscat["nright"];
     //$cart_products = $cart->getProducts();
     if (!empty($cart_products)) {
         $all_books = true;
         foreach ($cart_products as $key => $cart_product) {
             $product = new Product($cart_product['id_product']);
             $categories = $product->getCategories();
             //var_dump($categories);
             if (!empty($categories)) {
                 $product_is_book = false;
                 foreach ($categories as $key => $category) {
                     //echo $category;
                     if ($category == $books_cat_id) {
                         $product_is_book = true;
                         //echo "это в самих книгах";
                         break;
                     }
                     /*искать родителей до рута. если id родителя любого уровня = $books_cat_id, значить это книги*/
                     //echo "nleft ".$books_nleft;
                     //echo "nright ".$books_nright;
                     //echo "<br/><br/>";
                     $current_cat_id = $category;
                     while (1) {
                         $current_cat = new Category($current_cat_id);
                         //var_dump($current_cat->id_parent);
                         if ($current_cat->is_root_category == 1) {
                             //echo "это корневая категория";
                             break;
                         }
                         if ($current_cat->id_parent == $books_cat_id) {
                             $product_is_book = true;
                             //echo " это книга";
                             break;
                         }
                         $current_cat_id = $current_cat->id_parent;
                     }
                     if ($category >= $books_nleft and $category <= $books_nright) {
                         $product_is_book = true;
                         //echo " это книга";
                         break;
                     }
                     //echo " не книга";
                 }
             }
             if (!$product_is_book) {
                 $all_books = false;
                 break;
             }
         }
     }
     return $all_books;
 }
Example #8
0
	/**
	 *
	 * @param int $id_zone
	 * @param Array $groups group of the customer
	 * @return Array
	 */
	public static function getCarriersForOrder($id_zone, $groups = null, $cart = null)
	{
		
		$context = Context::getContext();
		$id_lang = $context->language->id;
		if (is_null($cart))
			$cart = $context->cart;
		$id_currency = $context->currency->id;

		if (is_array($groups) && !empty($groups))
			$result = Carrier::getCarriers($id_lang, true, false, (int)$id_zone, $groups, self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
		else
			$result = Carrier::getCarriers($id_lang, true, false, (int)$id_zone, array(Configuration::get('PS_UNIDENTIFIED_GROUP')), self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
		$results_array = array();
                
               // var_dump($result);
		foreach ($result as $k => $row)
		{
			$carrier = new Carrier((int)$row['id_carrier']);
			$shipping_method = $carrier->getShippingMethod();
			if ($shipping_method != Carrier::SHIPPING_METHOD_FREE)
			{
				// Get only carriers that are compliant with shipping method
				if (($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false)
					|| ($shipping_method == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false))
				{
					unset($result[$k]);
					continue;
				}

				// If out-of-range behavior carrier is set on "Desactivate carrier"
				if ($row['range_behavior'])
				{
					// Get id zone
					if (!$id_zone)
							$id_zone = Country::getIdZone(Country::getDefaultCountryId());

					// Get only carriers that have a range compatible with cart
					if (($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT
						&& (!Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone)))
						|| ($shipping_method == Carrier::SHIPPING_METHOD_PRICE
						&& (!Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $id_currency))))
					{
						unset($result[$k]);
						continue;
					}
				}
			}

			$row['name'] = (strval($row['name']) != '0' ? $row['name'] : Configuration::get('PS_SHOP_NAME'));
			$row['price'] = (($shipping_method == Carrier::SHIPPING_METHOD_FREE) ? 0 : $cart->getPackageShippingCost((int)$row['id_carrier'], true, null, null, $id_zone));
			$row['price_tax_exc'] = (($shipping_method == Carrier::SHIPPING_METHOD_FREE) ? 0 : $cart->getPackageShippingCost((int)$row['id_carrier'], false, null, null, $id_zone));
			$row['img'] = file_exists(_PS_SHIP_IMG_DIR_.(int)$row['id_carrier']).'.jpg' ? _THEME_SHIP_DIR_.(int)$row['id_carrier'].'.jpg' : '';

			// If price is false, then the carrier is unavailable (carrier module)
			if ($row['price'] === false)
			{
                            $row['price'] = 0;
//				unset($result[$k]);
//				continue;
			}

			//Проверка, если способ доставки - DP, то этот способ доставки доступен, если в корзине только книги
			$log = '';
			$DeutschePostCarrierName = "Deutsche Post"; //название службы доставки "Deutsche post"
			
			$books_cat_ru_name = "Книги";
			$parent_for_books_cat_id = 2;
			$books_KNIGI_lang = 1;

			if ($row['name'] == $DeutschePostCarrierName) {
				//echo "поиск категории Книги";
				$bookscat = Category::searchByNameAndParentCategoryId($books_KNIGI_lang,$books_cat_ru_name,$parent_for_books_cat_id);
				//var_dump($bookscat);
				$books_cat_id = $bookscat["id_category"];
				/*
				id_category"]=> string(1) "3" ["id_parent"]=> string(1) "2" ["id_shop_default"]=> string(1) "1" ["level_depth"]=> string(1) "2" ["nleft"]=> string(1) "3" ["nright"]=> string(3) "102" ["active"]=> string(1) "1" ["date_add"]=> string(19) "2015-02-19 21:05:41" ["date_upd"]=> string(19) "2015-02-19 21:05:41" ["position"]=> string(1) "0" ["is_root_category"]=> string(1) "0" ["id_shop"]=> string(1) "1" ["id_lang"]=> string(1) "1" ["name"]=> string(10) "Книги" ["description"]=> string(0) "" ["link_rewrite"]=> string(5) "knigi" ["meta_title"]=> string(0) "" ["meta_keywords"]=> string(0) "" ["meta_description"]=> string(0) "" }

				*/
				/*
				$books_cat_id = 12; //id категории книги
				$BooksCategory = new Category($books_cat_id);
				$interval = $BooksCategory->getInterval($books_cat_id);
				
				$books_nleft = $interval['nleft'];//21;
				$books_nright = $interval['nright'];//134;
				*/
				$books_nleft = $bookscat["nleft"];
				$books_nright = $bookscat["nright"];
				$cart_products = $cart->getProducts();
				if (!empty($cart_products))
				{ 
					$all_books = true;
					foreach ($cart_products as $key => $cart_product)
					{
						$product = new Product($cart_product['id_product']);
						$categories = $product->getCategories();
						//var_dump($categories);
						if (!empty($categories))
						{
							$product_is_book = false;
							foreach ($categories as $key => $category) 
							{
								//echo $category;
								if ($category == $books_cat_id)
								{
									$product_is_book = true;
									//echo "это в самих книгах";
									break;
								}

								/*искать родителей до рута. если id родителя любого уровня = $books_cat_id, значить это книги*/
								//echo "nleft ".$books_nleft;
								//echo "nright ".$books_nright;
								//echo "<br/><br/>";
								$current_cat_id = $category;
								while (1)
								{
									$current_cat = new Category($current_cat_id);
									//var_dump($current_cat->id_parent);
									if ($current_cat->is_root_category == 1){
										//echo "это корневая категория";
										break;
									}
									if ($current_cat->id_parent == $books_cat_id)
									{
										$product_is_book = true;
										//echo " это книга";
										break;
									}
									$current_cat_id = $current_cat->id_parent;
									
								}
								
								
								if ($category >= $books_nleft AND $category <= $books_nright)
								{
									$product_is_book = true;
									//echo " это книга";
									break;
								}
								//echo " не книга";
							}
						}
						if (!$product_is_book) {
							$all_books = false;
							break;
						}
					}
					if (!$all_books){
						unset($result[$k]);
						continue;
					}
				}
				
			}
			//Конец проверки

			$results_array[] = $row;
		}


		// if we have to sort carriers by price
		$prices = array();
		if (Configuration::get('PS_CARRIER_DEFAULT_SORT') == Carrier::SORT_BY_PRICE)
		{
			foreach ($results_array as $r)
				$prices[] = $r['price'];
			if (Configuration::get('PS_CARRIER_DEFAULT_ORDER') == Carrier::SORT_BY_ASC)
				array_multisort($prices, SORT_ASC, SORT_NUMERIC, $results_array);
			else
				array_multisort($prices, SORT_DESC, SORT_NUMERIC, $results_array);
		}

		return $results_array;
	}
Example #9
0
</head>
<body>
<?php 
require_once dirname(__FILE__) . '/menu.php';
require_once dirname(__FILE__) . "/lib/Product.php";
require_once dirname(__FILE__) . "/lib/Converter.php";
try {
    if (isset($_POST['convert_the_the_file']) && (int) $_POST['attribute_set_id'] > 0 && $_FILES["file_to_convert"]["error"] == UPLOAD_ERR_OK) {
        $archive_name = Converter::convertForImport((int) $_POST['attribute_set_id'], $_FILES["file_to_convert"], (int) $_POST['rows_per_file'], implode(",", $_POST['category_ids']), $_POST['add_update_products'], isset($_POST['out_of_stock']), isset($_POST['add_images']), strlen($_FILES["exclude_sku_list"]['tmp_name']) ? $_FILES["exclude_sku_list"] : null, $_POST['import_language'], isset($_POST['attribytes_by_groups']), (array) $_POST['manuf_fix']);
        echo '<h2><a href="/dl/' . $archive_name . '">Готово.</a></h2>';
    }
} catch (Exception $e) {
    die($e->getMessage());
}
$attribute_sets = Product::getAttributeSets();
$categories = Product::getCategories();
?>
<form action="" method="post" enctype="multipart/form-data">
<table border="0" style="margin: 0 auto;">
	<tbody>
		<tr>
			<td>
				<label for="attribute_set_id">Тип:&nbsp;</label>
			</td>
			<td>
				<select name="attribute_set_id" id="attribute_set_id">
				<option selected="selected" value="dummy"></option>
				<?php 
foreach ($attribute_sets as $attribute_set_id => $attribute_set_name) {
    echo '<option value="' . $attribute_set_id . '">' . $attribute_set_name . '</option>';
}
 /**
  * This function returns the products by using the product filter.
  *
  * @author David Pauli <*****@*****.**>
  * @return Product[] Returns an array of products.
  * @since 0.0.0
  * @since 0.1.0 Use a default Locale.
  * @since 0.1.1 Unstatic every attributes.
  * @since 0.1.2 Add error reporting.
  * @since 0.1.3 Get all results.
  * @since 0.2.0 Set error message for empty responses to notify.
  * @since 0.2.1 Implement REST client fixes.
  */
 public function getProducts()
 {
     $this->errorReset();
     $parameter = $this->getParameter();
     // if request method is blocked
     if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) {
         $this->errorSet("RESTC-9");
         return;
     }
     RESTClient::send(self::RESTPATH . "?" . $parameter);
     $content = RESTClient::getJSONContent();
     // if respond is empty
     if (InputValidator::isEmpty($content)) {
         $this->errorSet("PF-8");
         Logger::notify("ep6\\ProductFilter\nREST respomd for getting products is empty.");
         return;
     }
     // if there is no results, page AND resultsPerPage element
     if (InputValidator::isEmptyArrayKey($content, "results") || InputValidator::isEmptyArrayKey($content, "page") || InputValidator::isEmptyArrayKey($content, "resultsPerPage")) {
         $this->errorSet("PF-9");
         Logger::error("ep6\\ProductFilter\nRespond for " . self::RESTPATH . " can not be interpreted.");
         return;
     }
     $this->results = $content['results'];
     $products = array();
     // is there any product found: load the products.
     if (!InputValidator::isEmptyArrayKey($content, "items") && sizeof($content['items']) != 0) {
         foreach ($content['items'] as $item) {
             $product = new Product($item);
             // go to every filter
             foreach ($this->filters as $filter) {
                 switch ($filter->getAttribute()) {
                     case 'stocklevel':
                         $value = array();
                         $value["stocklevel"] = $product->getStocklevel();
                         break;
                     case 'price':
                         $value = array();
                         $value["price"] = $product->getPrice()->getAmount();
                         break;
                     case 'category':
                         $value = array();
                         $value["category"] = $product->getCategories();
                         break;
                     default:
                         $value = $item;
                         break;
                 }
                 if (!InputValidator::isEmptyArrayKey($value, $filter->getAttribute()) || $filter->getOperator() == FilterOperation::UNDEF) {
                     if (!InputValidator::isArray($value[$filter->getAttribute()])) {
                         if (!$filter->isElementInFilter($value)) {
                             continue 2;
                         }
                     }
                 } else {
                     continue 2;
                 }
             }
             array_push($products, $product);
         }
     }
     return $products;
 }