Example #1
0
 function getProductBySku($sku)
 {
     global $database, $logger;
     $logger->debug(get_class($this) . "::getProductBySku({$sku})");
     $prod = new Product();
     $ps_prod = new ps_product();
     $ps_cat = new ps_product_category();
     $query = "select product_id from #__vm_product where product_sku=" . $sku;
     $database->loadQuery($query);
     $id = $db->loadResult();
     $prod->setOid($id);
     $prod->setName($ps_prod->get_field('product_name'));
     $prod->setFlypage($ps_prod->get_flypage($id));
     $prod->setCategoryId($ps_cat->get_cid($id));
     return $prod;
 }
Example #2
0
		function getItems(&$params) {
				
			global $CURRENCY_DISPLAY, $sess, $mm_action_url, $VM_LANG;
			$db = new ps_DB;
			
			if($rows = $this->getProductSKU( $this->NumberOfProducts, $this->SortMethod, $this->vmcategories, $this->featuredProducts, $this->specific_product_ids, $this->source, $this->catfilter ))
			{
				$ps_product = new ps_product;
				$ps_product_category = new ps_product_category;
				$pro_skus = implode("','", $rows);	
				$limit = $this->NumberOfProducts;
				if($limit>0) {
					$limit = "LIMIT $limit";
				} else {
					$limit = "";
				}
				$q = "SELECT product_id, product_name, product_parent_id, product_thumb_image, product_desc, product_full_image FROM #__{vm}_product AS p WHERE product_sku in ('$pro_skus')";
				switch( $this->SortMethod ) {
					case 'random':
						$q .= "\n ORDER BY RAND() $limit";
						break;
					case 'newest':
						$q .= "\n ORDER BY p.cdate DESC $limit";
						break;
					case 'oldest':
						$q .= "\n ORDER BY p.cdate ASC $limit";
						break;
					default:
						$q .= "\n ORDER BY p.cdate DESC $limit";
						break;
				}
				$db->setQuery( $q );
				$items = $db->loadObjectList(); 
				//var_dump($items);die;
				foreach($items as &$item) {
					$product_id = $item->product_id;

					$cid = $ps_product_category->get_cid( $product_id );

					$product_name = $item->product_name;
					$item->title = $product_name;
					if ($item->product_parent_id) {
						$url = "?page=shop.product_details&category_id=$cid&flypage=".$ps_product->get_flypage($item->product_parent_id);
						$url .= "&product_id=" . $item->product_parent_id;
					} else {
						$url = "?page=shop.product_details&category_id=$cid&flypage=".$ps_product->get_flypage($item->product_id);
						$url .= "&product_id=" . $item->product_id;
					}
					$product_link = $sess->url($mm_action_url. "index.php" . $url);
					$item->link = $product_link;
					$product_thumb_image = $item->product_full_image;
					
					//$img = $this->image_url( $product_thumb_image, "alt=\"".$product_name."\"");
					$item->image = IMAGEPATH.'product/'.$product_thumb_image;
					$item->fulltext = $item->product_desc;
					$item->introtext = $item->product_desc;
																			
					$price_base = $this->get_price($ps_product,  $item->product_id);
					$price_ps = $ps_product->get_price($item->product_id, true);
					if (_SHOW_PRICES == '1' && $this->show_price) {
						// Show price, but without "including X% tax"
						$item->price = $CURRENCY_DISPLAY->getFullValue($price_base[1]);
						
					}
					
					if (USE_AS_CATALOGUE != 1 && $this->show_addtocart
							&& isset($price_ps) && $price_ps['product_price'] // Product must have a price to add it to cart
							/*&& !$ps_product->product_has_attributes($item->product_id, true)  // Parent Products and Products with attributes can't be added to cart this way*/
							) {
						$url = "?page=shop.cart&func=cartAdd&product_id=" .  $item->product_id;
						$addtocart_link = $sess->url($mm_action_url. "index.php" . $url);
						$item->addtocart_link = $addtocart_link;

					}
					
				}

				return $this->update($params, $items);
			} else return array();
	
			
	
		}		
Example #3
0
 /**
  * Returns HTML code for a snapshot of a product based on the product sku.
  * This was written to provide a quick way to display a product inside of modules
  *
  * @param string $product_sku The SKU identifying the product
  * @param boolean $show_price Show the product price?
  * @param boolean $show_addtocart Show the add-to-cart link?
  * @param boolean $show_product_name Show the product name?
  */
 function product_snapshot($product_sku, $show_price = true, $show_addtocart = true, $show_product_name = true)
 {
     global $sess, $mm_action_url;
     $db = new ps_DB();
     require_once CLASSPATH . 'ps_product_category.php';
     $ps_product_category = new ps_product_category();
     $q = "SELECT product_id, product_name, product_parent_id, product_thumb_image FROM #__{vm}_product WHERE product_sku='{$product_sku}'";
     $db->query($q);
     if ($db->next_record()) {
         $product_id = $db->f("product_id");
         $tpl = new $GLOBALS['VM_THEMECLASS']();
         $cid = $ps_product_category->get_cid($product_id);
         $tpl->set('product_id', $product_id);
         $tpl->set('product_name', $db->f("product_name"));
         $tpl->set('show_product_name', $show_product_name);
         if ($db->f("product_parent_id")) {
             $url = "?page=shop.product_details&category_id={$cid}&flypage=" . $this->get_flypage($db->f("product_parent_id"));
             $url .= "&product_id=" . $db->f("product_parent_id");
         } else {
             $url = "?page=shop.product_details&category_id={$cid}&flypage=" . $this->get_flypage($db->f("product_id"));
             $url .= "&product_id=" . $db->f("product_id");
         }
         $product_link = $sess->url($mm_action_url . "index.php" . $url);
         $tpl->set('product_link', $product_link);
         $tpl->set('product_thumb_image', $db->f("product_thumb_image"), "alt=\"" . $db->f("product_name") . "\"");
         if (_SHOW_PRICES == '1' && $show_price) {
             // Show price, but without "including X% tax"
             $price = $this->show_price($db->f("product_id"), true);
             $tpl->set('price', $price);
         }
         if (USE_AS_CATALOGUE != 1 && $show_addtocart && isset($GLOBALS['product_info'][$product_id]['price']['product_price_id']) && !$this->product_has_attributes($product_id, true)) {
             $url = "?page=shop.cart&func=cartAdd&product_id=" . $db->f("product_id");
             $addtocart_link = $sess->url($mm_action_url . "index.php" . $url);
             $tpl->set('addtocart_link', $addtocart_link);
         }
         return $tpl->fetch('common/productsnapshot.tpl.php');
     }
     return '';
 }
Example #4
0
 /**
  * Returns HTML code for a snapshot of a product based on the product sku.
  * This was written to provide a quick way to display a product inside of modules
  *
  * @param string $product_sku The SKU identifying the product
  * @param boolean $show_price Show the product price?
  * @param boolean $show_addtocart Show the add-to-cart link?
  * @param boolean $show_product_name Show the product name?
  */
 function product_snapshot($product_sku, $show_price = true, $show_addtocart = true, $show_product_name = true)
 {
     global $sess, $mm_action_url;
     $db = new ps_DB();
     require_once CLASSPATH . 'ps_product_category.php';
     $ps_product_category = new ps_product_category();
     $q = "SELECT product_id, product_name, product_parent_id, product_thumb_image, product_in_stock, product_nobuy, cdate, top,\n\t\t\n\t\tIFNULL((SELECT SUM(product_in_stock) FROM `jos_vm_product` AS cp WHERE cp.`product_parent_id` = jos_vm_product.product_id AND product_publish = \"Y\" AND product_in_stock > 0 ), 0) AS product_in_stock_child\n\n\t\tFROM #__{vm}_product WHERE product_sku='{$product_sku}'";
     $db->query($q);
     if ($db->next_record()) {
         $product_id = $db->f("product_id");
         $tpl = new $GLOBALS['VM_THEMECLASS']();
         $cid = $ps_product_category->get_cid($product_id);
         $novinka = "";
         if (time() - $db->f("cdate") < 30 * 86400) {
             // 14 Days *  (number of seconds in  24 hours)
             $novinka = 'Y';
         }
         $tpl->set('product_id', $product_id);
         $tpl->set('product_name', $db->f("product_name"));
         //$tpl->set( 'product_in_stock', $db->f("product_in_stock") );
         $tpl->set('product_in_stock', $db->f("product_in_stock_child") ? $db->f("product_in_stock_child") : $db->f("product_in_stock"));
         $tpl->set('product_nobuy', $db->f("product_nobuy"));
         $tpl->set('show_product_name', $show_product_name);
         $tpl->set('novinka', $novinka);
         $tpl->set('top', $db->f('top'));
         if ($db->f("product_parent_id")) {
             $url = "?page=shop.product_details&category_id={$cid}&flypage=" . $this->get_flypage($db->f("product_parent_id"));
             $url .= "&product_id=" . $db->f("product_parent_id");
         } else {
             $url = "?page=shop.product_details&category_id={$cid}&flypage=" . $this->get_flypage($db->f("product_id"));
             $url .= "&product_id=" . $db->f("product_id");
         }
         $product_link = $sess->url($mm_action_url . "index.php" . $url);
         $tpl->set('product_link', $product_link);
         $tpl->set('product_thumb_image', $db->f("product_thumb_image"), "alt=\"" . $db->f("product_name") . "\"");
         if (_SHOW_PRICES == '1' && $show_price) {
             // Show price, but without "including X% tax"
             $price = $this->show_price($db->f("product_id"), true);
             $tpl->set('price', $price);
         }
         if (USE_AS_CATALOGUE != 1 && $show_addtocart && isset($GLOBALS['product_info'][$product_id]['price']['product_price_id']) && !$this->product_has_attributes($product_id, true)) {
             $url = "?page=shop.cart&func=cartAdd&product_id=" . $db->f("product_id");
             $addtocart_link = $sess->url($mm_action_url . "index.php" . $url);
             $tpl->set('addtocart_link', $addtocart_link);
         }
         $has_attributes = ps_product::product_has_attributes($product_id, true);
         $tpl->set('has_attributes', $has_attributes);
         require_once CLASSPATH . 'ps_product_attribute.php';
         $ps_product_attribute = new ps_product_attribute();
         $tpl->set('ps_product_attribute', $ps_product_attribute);
         return $tpl->fetch('common/productsnapshot.tpl.php');
     }
     return '';
 }