Jump to content

Need help with module duplication


Anxiety

Recommended Posts

hello,
 
Maybe you guys could help me with module duplication. I have renamed the module, installed and it works fine, but i have problem i think with css. Seems like the module don't load csss from global.css. where could be the problem?
 
site: http://smeg.buineta.lt/

 

 

posfeatureproduct2.php

<?php

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

class Posfeatureproduct2 extends Module {

    private $_html = '';
    private $_postErrors = array();

    function __construct() {
        $this->name = 'posfeatureproduct2';
        $this->tab = 'front_office_features';
        $this->version = '1.5';
        $this->author = 'Posthemes';
        $this->need_instance = 0;
        $this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.6');
        parent::__construct();

        $this->displayName = $this->l('Featured products with slider on the homepage 2.');
        $this->description = $this->l('Displays featured products in any where of your homepage.');
    }

    function install() {
        $this->_clearCache('posfeatureproduct2.tpl');
        Configuration::updateValue('POSFEATUREPRODUCT2', 8);
        Configuration::updateValue($this->name . '_auto_slide', 0);
        Configuration::updateValue($this->name . '_speed_slide', '1000');
        Configuration::updateValue($this->name . '_a_speed', '600');
        Configuration::updateValue($this->name . '_show_price', 1);
        Configuration::updateValue($this->name . '_show_des', 0);
        Configuration::updateValue($this->name . '_qty_products', 12);
        Configuration::updateValue($this->name . '_qty_items', 4);
        Configuration::updateValue($this->name . '_width_item', 270);
        Configuration::updateValue($this->name . '_show_nextback', 1);
        Configuration::updateValue($this->name . '_show_control', 0);
        Configuration::updateValue($this->name . '_min_item', 4);
        Configuration::updateValue($this->name . '_max_item', 12);
        Configuration::updateValue($this->name . '_show_addtocart', 1);

        if (!parent::install()
                || !$this->registerHook('header')
                || !$this->registerHook('feature')
                || !$this->registerHook('addproduct')
                || !$this->registerHook('updateproduct')
                || !$this->registerHook('deleteproduct')
				|| !$this->registerHook('blockPosition2')
        )
            return false;
        return true;
    }

    public function uninstall() {
        Configuration::deleteByName($this->name . '_auto_slide');
        Configuration::deleteByName($this->name . '_speed_slide');
        Configuration::deleteByName($this->name . '_a_speed');
        Configuration::deleteByName($this->name . '_show_price');
        Configuration::deleteByName($this->name . '_show_des');
        Configuration::deleteByName($this->name . '_qty_products');
        Configuration::deleteByName($this->name . '_qty_items');
        Configuration::deleteByName($this->name . '_width_item');
        Configuration::deleteByName($this->name . '_show_nextback');
        Configuration::deleteByName($this->name . '_show_control');
        Configuration::deleteByName($this->name . '_min_item');
        Configuration::deleteByName($this->name . '_max_item');
        Configuration::deleteByName($this->name . '_show_addtocart');

        $this->_clearCache('posfeatureproduct2.tpl');
        return parent::uninstall();
    }

    public function getContent() {
        $output = '<h2>' . $this->displayName . '</h2>';
        if (Tools::isSubmit('submitPostFeaturedProduct2')) {
            if (!sizeof($this->_postErrors))
                $this->_postProcess();
            else {
                foreach ($this->_postErrors AS $err) {
                    $this->_html .= '<div class="alert error">' . $err . '</div>';
                }
            }
        }
        return $output . $this->_displayForm();
    }

    public function getSelectOptionsHtml($options = NULL, $name = NULL, $selected = NULL) {
        $html = "";
        $html .='<select name =' . $name . ' style="width:130px">';
        if (count($options) > 0) {
            foreach ($options as $key => $val) {
                if (trim($key) == trim($selected)) {
                    $html .='<option value=' . $key . ' selected="selected">' . $val . '</option>';
                } else {
                    $html .='<option value=' . $key . '>' . $val . '</option>';
                }
            }
        }
        $html .= '</select>';
        return $html;
    }

    private function _postProcess() {
        Configuration::updateValue($this->name . '_auto_slide', Tools::getValue('auto_slide'));
        Configuration::updateValue($this->name . '_speed_slide', Tools::getValue('speed_slide'));
        Configuration::updateValue($this->name . '_a_speed', Tools::getValue('a_speed'));
        Configuration::updateValue($this->name . '_show_price', Tools::getValue('show_price'));
        Configuration::updateValue($this->name . '_show_des', Tools::getValue('show_des'));
        Configuration::updateValue($this->name . '_qty_products', Tools::getValue('qty_products'));
        Configuration::updateValue($this->name . '_qty_items', Tools::getValue('qty_items'));
        Configuration::updateValue($this->name . '_width_item', Tools::getValue('width_item'));
        Configuration::updateValue($this->name . '_show_nextback', Tools::getValue('show_nextback'));
        Configuration::updateValue($this->name . '_show_control', Tools::getValue('show_control'));
        Configuration::updateValue($this->name . '_min_item', Tools::getValue('min_item'));
        Configuration::updateValue($this->name . '_max_item', Tools::getValue('max_item'));
        Configuration::updateValue($this->name . '_show_addtocart', Tools::getValue('show_addtocart'));



        $this->_html .= '<div class="conf confirm">' . $this->l('Settings updated') . '</div>';
    }

    private function _displayForm() {
        $this->_html .= '
		<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
                  <fieldset>
                    <legend><img src="../img/admin/cog.gif" alt="" class="middle" />' . $this->l('Settings') . '</legend>
                     <label>' . $this->l('Auto slide: ') . '</label>
                    <div class="margin-form">';
        $this->_html .= $this->getSelectOptionsHtml(array(0 => 'No', 1 => 'Yes'), 'auto_slide', (Tools::getValue('auto_slide') ? Tools::getValue('auto_slide') : Configuration::get($this->name . '_auto_slide')));
        $this->_html .='
                    </div>
                     <label>' . $this->l('Min Items: ') . '</label>
                    <div class="margin-form">
                            <input type = "text"  name="min_item" value =' . (Tools::getValue('min_item') ? Tools::getValue('min_item') : Configuration::get($this->name . '_min_item')) . ' ></input>
                    </div>
                    
                     <label>' . $this->l('Qty of Products: ') . '</label>
                    <div class="margin-form">
                            <input type = "text"  name="qty_products" value =' . (Tools::getValue('qty_products') ? Tools::getValue('qty_products') : Configuration::get($this->name . '_qty_products')) . ' ></input>
                    </div>
                    
                    <input type="submit" name="submitPostFeaturedProduct2" value="' . $this->l('Update') . '" class="button" />
                     </fieldset>
		</form>';
        return $this->_html;
    }

    public function hookDisplayHeader($params) {
        $this->hookHeader($params);
    }

    public function hookHeader($params) {
       // $this->context->controller->addCSS(($this->_path) . 'css/posfeatureproduct2.css', 'all');
//                $this->context->controller->addJS($this->_path.'js/modernizr.custom.17475.js');
//                $this->context->controller->addJS($this->_path.'js/jquerypp.custom.js');
//                $this->context->controller->addJS($this->_path.'js/jquery.elastislide.js');
    }

    public function getSlideshowHtml() {

        if (!$this->isCached('posfeatureproduct2.tpl', $this->getCacheId('posfeatureproduct2'))) {
            $slideOptions = array(
                'auto_slide' => Configuration::get($this->name . '_auto_slide'),
                'speed_slide' => Configuration::get($this->name . '_speed_slide'),
                'a_speed' => Configuration::get($this->name . '_a_speed'),
                'show_price' => Configuration::get($this->name . '_show_price'),
                'show_des' => Configuration::get($this->name . '_show_des'),
                'qty_products' => Configuration::get($this->name . '_qty_products'),
                'qty_items' => Configuration::get($this->name . '_qty_items'),
                'width_item' => Configuration::get($this->name . '_width_item'),
                'show_nexback' => Configuration::get($this->name . '_show_nextback'),
                'show_control' => Configuration::get($this->name . '_show_control'),
                'min_item' => Configuration::get($this->name . '_min_item'),
                'max_item' => Configuration::get($this->name . '_max_item'),
                'show_addtocart' => Configuration::get($this->name . '_show_addtocart'),
            );
            //echo "<pre>"; print_r($slideOptions);
            $category = new Category(Context::getContext()->shop->getCategory(), (int) Context::getContext()->language->id);
            $nb = (int) Configuration::get($this->name . '_qty_products');
            $products = $category->getProducts((int) Context::getContext()->language->id, 1, ($nb ? $nb : 8));
            if(!$products) return ;
            $this->smarty->assign(array(
                'products' => $products,
                'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
                'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
                'slideOptions' => $slideOptions
            ));
        }
        return $this->display(__FILE__, 'posfeatureproduct2.tpl', $this->getCacheId('posfeatureproduct2'));
    }

    public function hookfeature($params) {
        return $this->getSlideshowHtml();
    }
	  public function hookblockPosition2($params) {
        return $this->getSlideshowHtml();
    }

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

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

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

}

posfeatureproduct2.tpl

<div class="pos-feature-product">
	<div class="pos-feature-product-title">
	<h2>{l s='Featured Products 2' mod='posfeatureproducts2'}</h2>
	</div>
	{if count($products)>1}
		<div class="featureSlide">
			{foreach from=$products item=product name=posFeatureProducts2}
				{if $smarty.foreach.posFeatureProducts2.index % 2 == 0 || $smarty.foreach.posFeatureProducts2.first }
				  <div class="item">
				 {/if}
				<div class="item-ii">
					<div class="pull-left">
						<a class="product_img_link" href="{$product.link|escape:'html':'UTF-8'}" title="{$product.name|escape:'html':'UTF-8'}" itemprop="url">
							<img class="replace-2x img-responsive" src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'pos_product')|escape:'html':'UTF-8'}" alt="{if !empty($product.legend)}{$product.legend|escape:'html':'UTF-8'}{else}{$product.name|escape:'html':'UTF-8'}{/if}" title="{if !empty($product.legend)}{$product.legend|escape:'html':'UTF-8'}{else}{$product.name|escape:'html':'UTF-8'}{/if}" {if isset($homeSize)} {/if} itemprop="image" />
						</a>
					</div>
					<div class="media-body">
						<h5 class="s_title_block"><a href="{$product.link|escape:'html'}" title="{$product.name|truncate:30:'...'|escape:'htmlall':'UTF-8'}">{$product.name|truncate:30:'...'|escape:'htmlall':'UTF-8'}</a></h5>
						{if $slideOptions.show_des ==1 }
						    <div class="product_desc"><a href="{$product.link|escape:'html'}" title="{l s='More' mod='posfeatureproducts2'}">{$product.description_short|strip_tags|truncate:65:'...'}</a></div>
						{/if}
						<div class="acction">
							<div class="ratings">{hook h='displayProductListReviews' product=$product}</div>
							<div class="price-box">
								{if isset($product.show_price) && $product.show_price && !isset($restricted_country_mode)}
									<span itemprop="price" class="price product-price">
										{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}
									</span>
									{if isset($product.specific_prices) && $product.specific_prices && isset($product.specific_prices.reduction) && $product.specific_prices.reduction > 0}
										<span class="old-price product-price">
											{displayWtPrice p=$product.price_without_reduction}
										</span>
									{/if}
								{/if}
							</div>
							<div class="cart-content">
								<div class="cart">
									{if ($product.id_product_attribute == 0 || (isset($add_prod_display) && ($add_prod_display == 1))) && $product.available_for_order && !isset($restricted_country_mode) && $product.minimal_quantity <= 1 && $product.customizable != 2 && !$PS_CATALOG_MODE}
									{if ($product.allow_oosp || $product.quantity > 0)}
									{if isset($static_token)}
										<a class="button ajax_add_to_cart_button btn btn-default" href="{$link->getPageLink('cart',false, NULL, "add=1&id_product={$product.id_product|intval}&token={$static_token}", false)|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Add to cart' mod='posfeatureproducts2'}" data-id-product="{$product.id_product|intval}">
											<span><i class="fa fa-plus-square"></i> {l s='Add to cart' mod='posfeatureproducts2'}</span>
										</a>
									{else}
									<a class="button ajax_add_to_cart_button btn btn-default" href="{$link->getPageLink('cart',false, NULL, 'add=1&id_product={$product.id_product|intval}', false)|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Add to cart' mod='posfeatureproducts2'}" data-id-product="{$product.id_product|intval}">
										<span>{l s='Add to cart' mod='posfeatureproducts2'}</span>
									</a>
								       {/if}      
									{else}
									<span class="button ajax_add_to_cart_button btn btn-default disabled">
										<span>{l s='Add to cart' mod='posfeatureproducts2'}</span>
									</span>
									{/if}
									{/if}
								</div>
								<ul class="add-to-links">
									<li>
										<a class="addToWishlist wishlistProd_{$product.id_product|intval}" title="Wishlist" href="#" data-wishlist="{$product.id_product|intval}" onclick="WishlistCart('wishlist_block_list', 'add', '{$product.id_product|intval}', false, 1); return false;">
											<span>{l s="Wishlist" mod='blockwishlist'}</span>
										</a>
									</li>
									<li>
										{if isset($quick_view) && $quick_view}
											<a class="quick-view" title="{l s='quick view' mod='posfeatureproducts2'}" href="{$product.link|escape:'html':'UTF-8'}" rel="{$product.link|escape:'html':'UTF-8'}">
												<span>{l s='Quick view'}</span>
											</a>
										{/if}
									</li>
								</ul>
							</div>
						</div>
					</div>
					</div>
				{if $smarty.foreach.posFeatureProducts2.iteration % 2 == 0 || $smarty.foreach.posFeatureProducts2.last  }
				  </div>
				 {/if}
			{/foreach}
		</div>
		<div class="nextPrev">
			<a class="prevfea"><span>prev</span></a>
			<a class="nextfea"><span>next</span></a>
		</div>
	{else}
	<p class="warning">{l s='No products for this new products.'}</p>
	{/if}
<script type="text/javascript"> 
    $(document).ready(function() {
		var owl = $(".featureSlide");
		owl.owlCarousel({
		items :{if $slideOptions.min_item != ''}{$slideOptions.min_item}{else}3{/if},
		itemsDesktop : [1200,2],
		itemsDesktopSmall : [1024,2], 
		itemsTablet: [680,1], 
		itemsMobile : [360,1],
		autoPlay :  {if $slideOptions.auto_slide != 1}false{else}true{/if},
		});
		 
		// Custom Navigation Events
		$(".nextfea").click(function(){
		owl.trigger('owl.next');
		})
		$(".prevfea").click(function(){
		owl.trigger('owl.prev');
		})     
    });

</script>
</div>
	<script type="text/javascript">
		  $('.pos-feature-product .bxslider').bxSlider({
            auto: {if $slideOptions.auto_slide != 1}{$slideOptions.auto_slide}{else}1{/if},
            slideWidth:{if $slideOptions.width_item != ''}{$slideOptions.width_item}{else}262{/if},
			slideMargin: 30,
			minSlides: {if $slideOptions.min_item != ''}{$slideOptions.min_item}{else}3{/if},
			maxSlides: {if $slideOptions.max_item != ''}{$slideOptions.max_item}{else}8{/if},
			speed:  {if $slideOptions.speed_slide != ''}{$slideOptions.speed_slide}{else}5000{/if},
			pause: {if $slideOptions.a_speed != ''}{$slideOptions.a_speed}{else}1000{/if},
			controls: {if $slideOptions.show_nexback != 0}{$slideOptions.show_nexback}{else}false{/if},
            pager: {if $slideOptions.show_control != 0}{$slideOptions.show_control}{else}false{/if},
		});
	</script>
		 


post-348613-0-52579600-1464360938_thumb.jpg

post-348613-0-65103500-1464360944_thumb.jpg

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...