Jump to content

module productscategory


Recommended Posts

Hi all, i need display in stock or out of stock in module products category.

Web is here http://www.autobaterie-adac.cz/index.php?id_product=38115&controller=product

 

Yet is permanently displayed out of stock (není skladem)

 

My code is here:

  		<p id="availability_statut"{if ($categoryProduct.quantity <= 0 && !$categoryProduct.available_later && $allow_oosp) OR ($categoryProduct.quantity > 0 && !$categoryProduct.available_now) OR !$categoryProduct.available_for_order OR $PS_CATALOG_MODE} style="display: none;"{/if}>
<span id="availability_value"{if $categoryProduct.quantity <= 0} class="warning_inline"{/if}>{if $categoryProduct.quantity <= 0}{if $allow_oosp}{$categoryProduct.available_later}{else}<span class="no_skladem">{l s='není skladem' mod='homefeatured'}</span>{/if}{else}<span class="je_skladem">{$categoryProduct.available_now}</span>{/if}</span>				
			</p>    

In product-list.tpl is all fine http://www.autobaterie-adac.cz/index.php?id_category=6&controller=category

Edited by tozi (see edit history)
Link to comment
Share on other sites

HI

 

in categoty class not have quantity of product but

in class product you have this function

 

 getQuantity($id_product, $id_product_attribute = null, $cache_is_pack = null) 

 

then you can add in productcategory.php in

foreach ($category_products as $key => $category_product) of function hookProductFooter

category_product['quantity'] = product::getQuantity(category_product['id_product'], $id_product_attribute = null, $cache_is_pack = null);

and in tpl

<span class="{if category_product.quantity <= 0}out-of-stock{else}available-now{/if}">
<link itemprop="availability" href="http://schema.org/InStock" />{if category_product.quantity <= 0}{l s='Out of stock'}{/if}{else}{l s='In Stock'}{/if}</span>

i not test it

 

@++

 

Loulou66

Link to comment
Share on other sites

Like this?

	public function hookProductFooter($params)
	{
		$id_product = (int)$params['product']->id;
		$product = $params['product'];
	
		category_product['quantity'] = product::getQuantity(category_product['id_product'], $id_product_attribute = null, $cache_is_pack = null);
		
		$cache_id = 'productscategory|'.$id_product.'|'.(isset($params['category']->id_category) ? (int)$params['category']->id_category : $product->id_category_default);

It writes me error. 

Link to comment
Share on other sites

HI

 

ok^^

 

in productcategory.php in function hookProductFooter you have the loop foreach for each product for apply the taxe en get price then add in the function for quantity

foreach ($category_products as $key => $category_product)
{
	if ($category_product['id_product'] != $id_product)
	{
		if ($taxes == 0 || $taxes == 2)
		{
			$category_products[$key]['displayed_price'] = Product::getPriceStatic(
			(int)$category_product['id_product'],
			true,
			null,
			2
			);
		} elseif ($taxes == 1)
		{
			$category_products[$key]['displayed_price'] = Product::getPriceStatic(
			(int)$category_product['id_product'],
			false,
			null,
			2
			);
		}        
	}
        category_product['quantity'] = product::getQuantity(category_product['id_product'], $id_product_attribute = null, $cache_is_pack = null);
}

@++

 

Loulou66

Edited by loulou66 (see edit history)
Link to comment
Share on other sites

Hi

 

ok then i tested on PS 1.5.6.2 i think its same for you

 

in categoryProduct.php

before
// Get positions
add
foreach ($categoryProducts AS $key => $categoryProduct)	
{		
	$categoryProduct['quantity'] = Product::getQuantity($categoryProduct['id_product'], $id_product_attribute = null, $cache_is_pack = null);
}	
				

and in categoryproduct.tpl

before
{if $ProdDisplayPrice AND $categoryProduct.show_price == 1 AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}
<p class="price_display">
add
<p id="availability_statut">
	<span id="availability_value"{if $categoryProduct.quantity <= 0} class="warning_inline"{/if}>{if $categoryProduct.quantity <= 0}{l s='out of stock' mod='productscategory'}{else}{l s='available' mod='productscategory'}{/if}
        </span>				
</p>

go in traduction of module for traducte words

and in categoryproduct.css add css declaration for the 

#productscategory_list li  #availability_statut 

and

#productscategory_list li  #availability_statut span

 

@++

 

Loulou66

Link to comment
Share on other sites

Nothing http://zahradny.simplydesign.sk/index.php?id_product=38127&controller=product

 

Here my modules/productscategory/productscategory.tpl



{if count($categoryProducts) > 0 && $categoryProducts !== false}

<div id="blockproductscategory">
    <div class="title_block_feat"><span>{if $lang_iso == en }related products{else}související produkty{/if}</span></div>
	
	<div class="control">
		<a id="prev2" class="prev" href="#"><</a>
		<a id="next2" class="next" href="#">></a>
	</div>	
	
	<div class="list_carousel">
		<ul id="foo2">
			{foreach from=$categoryProducts item='categoryProduct' name=categoryProduct}
			<li>
				{hook h='myExtraFieldHook' id_product=$categoryProduct.id_product} 
       
					<div class="product_name">
					<h5><a href="{$link->getProductLink($categoryProduct.id_product, $categoryProduct.link_rewrite, $categoryProduct.category, $categoryProduct.ean13)|escape:'html'}" title="{$categoryProduct.name|htmlspecialchars}">{$categoryProduct.name|truncate:30:'...'|escape:'htmlall':'UTF-8'}</a></h5>
				</div>
				<a href="{$link->getProductLink($categoryProduct.id_product, $categoryProduct.link_rewrite, $categoryProduct.category, $categoryProduct.ean13)}" title="{$categoryProduct.name|htmlspecialchars}" class="product_img_link"><img src="{$link->getImageLink($categoryProduct.link_rewrite, $categoryProduct.id_image, 'akcni')}" width="152" height="90" alt="{$categoryProduct.name|htmlspecialchars}" />
          
			
					{if isset($categoryProduct.new) && $categoryProduct.new == 1}<span class="new">{l s='Novinka'}</span>{/if}
				
					{if isset($categoryProduct.on_sale) && $categoryProduct.on_sale && isset($categoryProduct.show_price) && $categoryProduct.show_price && !$PS_CATALOG_MODE}<span class="on_sale">{l s='On sale!'}</span>
					{elseif isset($categoryProduct.reduction) && $categoryProduct.reduction && isset($categoryProduct.show_price) && $categoryProduct.show_price && !$PS_CATALOG_MODE}<span class="discount">{l s='sleva!'}</span>{/if}				
			{if $ProdDisplayPrice AND $categoryProduct.show_price == 1 AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}
<p id="availability_statut">
	<span id="availability_value"{if $categoryProduct.quantity <= 0} class="warning_inline"{/if}>{if $categoryProduct.quantity <= 0}{l s='out of stock' mod='productscategory'}{else}{l s='available' mod='productscategory'}{/if}
        </span>				
</p>        
{/if}
				</a>
				<div class="clearfix"> </div>
	
				
				<div class="textdescription">{$categoryProduct.description_short|truncate:50:'...'}</div>
				
            
				{if ($categoryProduct.quantity > 0 OR $categoryProduct.allow_oosp)}
   	
                         {if $ProdDisplayPrice AND $categoryProduct.show_price == 1 AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}
				<div class="price_display">
					<div class="cenaintwo">{convertPrice price=$categoryProduct.displayed_price}</div>
				</div>       

               {else}
				<div class="clearfix"> </div>
				{/if}

               
               
               

               
               
               
               
				<a class="button ajax_add_to_cart_button exclusive buttonos" rel="ajax_id_product_{$categoryProduct.id_product|intval}" href="{$link->getPageLink('cart',false, NULL, "add=1&id_product={$categoryProduct.id_product|intval}&token={$static_token}", false)|escape:'html'}" title="{l s='Koupit'}">{l s='Do košiku' mod='productscategory'}</a>
				
				{else}
				<img src="{$img_dir}sklad_no.png" alt="{$shop_name|escape:'htmlall':'UTF-8'}" width="14" height="14" class="ico_no_skladem"/>
				{/if}			
                

      
			</li>
			{/foreach}
		</ul>
	</div>
	

</div>
{/if}


<!-- include carouFredSel plugin -->
<script type="text/javascript" language="javascript" src="{$js_dir}jquery.carouFredSel-6.2.1-packed.js"></script>

<!-- fire plugin onDocumentReady -->
<script type="text/javascript" language="javascript">
	$(function() {
		//	Scrolled by user interaction
		$('#foo2').carouFredSel({
			auto: false,
			circular: false, 
			prev: '#prev2',
			next: '#next2'
		});
	});
</script>

And here productscategory.php

if (!defined('_PS_VERSION_'))
	exit;

class productsCategory extends Module
{
 	private $_html;

	public function __construct()
 	{
 	 	$this->name = 'productscategory';
 	 	$this->version = '1.5';
		$this->author = 'PrestaShop';
 	 	$this->tab = 'front_office_features';
		$this->need_instance = 0;
		
		parent::__construct();
		
		$this->displayName = $this->l('Products Category');
		$this->description = $this->l('Display products of the same category on the product page.');
		
 	}

	public function install()
	{
		Configuration::updateValue('PRODUCTSCATEGORY_DISPLAY_PRICE', 0);
		$this->_clearCache('productscategory.tpl');
	 	return (parent::install()
			&& $this->registerHook('productfooter')
			&& $this->registerHook('header')
			&& $this->registerHook('addproduct')
			&& $this->registerHook('updateproduct')
			&& $this->registerHook('deleteproduct')
		);
	}
	
	public function uninstall()
	{
		Configuration::deleteByName('PRODUCTSCATEGORY_DISPLAY_PRICE');
		$this->_clearCache('productscategory.tpl');
	 	return parent::uninstall();
	}
	
	public function getContent()
	{
		$this->_html = '';
		if (Tools::isSubmit('submitCross') AND Tools::getValue('displayPrice') != 0 AND Tools::getValue('displayPrice') != 1)
			$this->_html .= $this->displayError('Invalid displayPrice');
		elseif (Tools::isSubmit('submitCross'))
		{
			Configuration::updateValue('PRODUCTSCATEGORY_DISPLAY_PRICE', Tools::getValue('displayPrice'));
			$this->_clearCache('productscategory.tpl');
			$this->_html .= $this->displayConfirmation($this->l('Settings updated successfully'));
		}
		$this->_html .= '
		<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
		<fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
			<label>'.$this->l('Display price on products').'</label>
			<div class="margin-form">
				<input type="radio" name="displayPrice" id="display_on" value="1" '.(Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE') ? 'checked="checked" ' : '').'/>
				<label class="t" for="display_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
				<input type="radio" name="displayPrice" id="display_off" value="0" '.(!Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE') ? 'checked="checked" ' : '').'/>
				<label class="t" for="display_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
				<p class="clear">'.$this->l('Show the price on the products in the block.').'</p>
			</div>
			<center><input type="submit" name="submitCross" value="'.$this->l('Save').'" class="button" /></center>
		</fieldset>
		</form>';
		return $this->_html;
	}
	
	private function getCurrentProduct($products, $id_current)
	{
		if ($products)
			foreach ($products AS $key => $product)
				if ($product['id_product'] == $id_current)
					return $key;
		return false;
	}
	
	public function hookProductFooter($params)
	{
		
		$id_product = (int)$params['product']->id;
		$product = $params['product'];
		
		$cache_id = 'productscategory|'.$id_product.'|'.(isset($params['category']->id_category) ? (int)$params['category']->id_category : $product->id_category_default);

		if (!$this->isCached('productscategory.tpl', $this->getCacheId($cache_id)))
		{
			/* If the visitor has came to this product by a category, use this one */
			if (isset($params['category']->id_category))
				$category = $params['category'];
			/* Else, use the default product category */
			else
			{
				if (isset($product->id_category_default) AND $product->id_category_default > 1)
					$category = new Category((int)$product->id_category_default);
			}
			
			if (!Validate::isLoadedObject($category) OR !$category->active) 
				return;

			// Get infos
			$categoryProducts = $category->getProducts($this->context->language->id, 1, 100); /* 100 products max. */
			$sizeOfCategoryProducts = (int)sizeof($categoryProducts);
			$middlePosition = 0;
			
			// Remove current product from the list
			if (is_array($categoryProducts) AND sizeof($categoryProducts))
			{
				
				
				
				foreach ($categoryProducts AS $key => $categoryProduct)
					if ($categoryProduct['id_product'] == $id_product)
					{
						unset($categoryProducts[$key]);
						break;
					}

				$taxes = Product::getTaxCalculationMethod();
				if (Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE'))
					foreach ($categoryProducts AS $key => $categoryProduct)	
{		
	$categoryProduct['quantity'] = Product::getQuantity($categoryProduct['id_product'], $id_product_attribute = null, $cache_is_pack = null);
}
			
				// Get positions
				$middlePosition = round($sizeOfCategoryProducts / 2, 0);
				$productPosition = $this->getCurrentProduct($categoryProducts, (int)$id_product);
			
				// Flip middle product with current product
				if ($productPosition)
				{
					$tmp = $categoryProducts[$middlePosition-1];
					$categoryProducts[$middlePosition-1] = $categoryProducts[$productPosition];
					$categoryProducts[$productPosition] = $tmp;
				}
			
				// If products tab higher than 30, slice it
				if ($sizeOfCategoryProducts > 30)
				{
					$categoryProducts = array_slice($categoryProducts, $middlePosition - 15, 30, true);
					$middlePosition = 15;
				}
			}
			
			// Display tpl
			$this->smarty->assign(array(
				'categoryProducts' => $categoryProducts,
				'middlePosition' => (int)$middlePosition,
				'ProdDisplayPrice' => Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE')));
		}
		return $this->display(__FILE__, 'productscategory.tpl', $this->getCacheId($cache_id));
	}
	
	public function hookHeader($params)
	{
		$this->context->controller->addCSS($this->_path.'productscategory.css', 'all');
		$this->context->controller->addJS($this->_path.'productscategory.js');
		$this->context->controller->addJqueryPlugin(array('scrollTo', 'serialScroll'));
	}

	public function hookAddProduct($params)
	{
		$this->_clearCache('productscategory.tpl');
	}

	public function hookUpdateProduct($params)
	{
		$this->_clearCache('productscategory.tpl');
	}

	public function hookDeleteProduct($params)
	{
		$this->_clearCache('productscategory.tpl');
	}
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...