onAfterCategoryUpdate et onAfterCategoryCreate dans hikamarket plugin

  • Posts: 453
  • Thank you received: 31
  • Hikamarket Multivendor Hikashop Business
2 years 3 months ago #343502

Bonjour,

je viens de faire un plugin pour que nos clients gère en front end hikamarket la mise en page de leurs produits, je rencontre un souci bizarre, tout fonctionne très bien lors de l'édition ou la création de produit, mais pas dans l'édition ou la création de catégorie.

dans mon plugin se trouvent les 4 trigger :
onAfterProductCreate
onAfterProductUpdate
onAfterCategoryCreate
onAfterCategoryUpdate

Les deux premiers fonctionnent si le créer ou que j'édite un produit, mais les deux suivants ne fonctionnent pas si je créer ou que j'édite une catégorie, et je ne vois pas pourquoi, voyez vous ?

J'ai même mis un var_dump('test');exit; directement au début du trigger, il ne s'affiche pas en front, alors que si je les mets dans les deux premiers trigger, bien sur ils s'affichent

Ci dessous mon code de plugin, merci d'avance, j'espère ne pas avoir loupé un truc trop bête ...

<?php
defined('_JEXEC') or die;

class plgHikamarketProduct_layout extends JPlugin
{
	
	protected $file1		= 'show_1';
	protected $file2		= 'show_2';
	
	public function onBeforeCompileHead(){
				
		$db			= JFactory::getDbo();
		$fileName1	= $this->params->get('fileName1', 'Vue 1');
		$fileName2	= $this->params->get('fileName2', 'Vue 2');
		$sourceFile	= $this->params->get('sourceFile', 'show_default');
		
		$db->setQuery('SELECT * FROM #__hikashop_field WHERE field_namekey = "product_custom_layout"');
		$product_custom_layout = $db->loadObject();
		if(empty($product_custom_layout)){
			$db->setQuery('SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = "an53e_hikashop_product" AND COLUMN_NAME = "product_custom_layout"');
			$product_custom_layout_exist = $db->loadColumn();
			if(empty($product_custom_layout_exist)){
				$db->setQuery('ALTER TABLE #__hikashop_product ADD product_custom_layout VARCHAR(255)');
				$db->execute();
			
				$query = $db->getQuery(true);
				$fields = array(
					$db->quoteName('product_custom_layout').' = '.$db->quote('show_cat'),
					$db->quoteName('product_layout').' = '.$db->quote($this->file1),
				);
				$conditions = 1;
				$query->update($db->quoteName('#__hikashop_product'))->set($fields)->where($conditions);
				$db->setQuery($query);
				$result = $db->execute();
			}
			$db->setQuery('SELECT MAX(field_ordering) FROM #__hikashop_field WHERE field_table = "product"');
			$field_ordering = $db->loadResult();
			$query = $db->getQuery(true);
			$columns = array(
				'field_table',
				'field_realname',
				'field_namekey',
				'field_type',
				'field_value',
				'field_published',
				'field_ordering',
				'field_options',
				'field_default',
				'field_access',
				'field_categories',
				'field_products',
				'field_display'
			);
			$values = array(
				$db->quote('product'),
				$db->quote('Mise en page'),
				$db->quote('product_custom_layout'),
				$db->quote('singledropdown'),
				$db->quote('show_cat::Mise en page de la catégorie::0
'.$this->file1.'::'.$fileName1.'::0
'.$this->file2.'::'.$fileName2.'::0'),
				$db->quote(1),
				$db->quote($field_ordering),
				$db->quote('a:28:{s:15:"limit_to_parent";s:0:"";s:12:"errormessage";s:0:"";s:5:"regex";s:0:"";s:9:"attribute";s:0:"";s:11:"placeholder";s:0:"";s:6:"inline";s:1:"0";s:12:"target_blank";s:1:"1";s:9:"allow_add";s:1:"0";s:4:"cols";s:0:"";s:9:"filtering";s:1:"1";s:9:"maxlength";s:1:"0";s:4:"rows";s:0:"";s:9:"zone_type";s:7:"country";s:12:"pleaseselect";s:1:"0";s:4:"size";s:0:"";s:6:"format";s:8:"%Y-%m-%d";s:5:"allow";s:0:"";s:18:"allowed_extensions";s:0:"";s:10:"upload_dir";s:0:"";s:12:"max_filesize";s:1:"0";s:9:"max_width";s:1:"0";s:10:"max_height";s:1:"0";s:8:"multiple";s:1:"0";s:8:"readonly";s:1:"0";s:12:"translatable";s:1:"0";s:24:"market_vendorselect_type";s:1:"0";s:11:"mysql_query";s:0:"";s:18:"datepicker_options";a:14:{s:5:"today";s:1:"0";s:6:"inline";s:1:"0";s:12:"monday_first";s:1:"0";s:12:"change_month";s:1:"0";s:11:"change_year";s:1:"0";s:16:"year_range_start";s:0:"";s:14:"year_range_end";s:0:"";s:14:"show_btn_panel";s:1:"0";s:11:"show_months";s:1:"1";s:11:"other_month";s:1:"0";s:19:"exclude_days_format";s:3:"mdY";s:7:"waiting";s:0:"";s:14:"hour_extra_day";s:0:"";s:11:"check_dates";s:3:"all";}}'),
				$db->quote($this->file1),
				$db->quote('all'),
				$db->quote('all'),
				$db->quote(''),
				$db->quote(';compare=0;front_listing=0;back_invoice=0;back_shipping_invoice=0;order_form=0;back_cart_details=0;front_cart_details=0;checkout=0;mail_order_notif=0;mail_status_notif=0;mail_order_creation=0;mail_admin_notif=0;mail_payment_notif=0;vendor_product_edit=1;vendor_product_listing=1;'),
			);
			$query
				->insert($db->quoteName('#__hikashop_field'))
				->columns($db->quoteName($columns))
				->values(implode(',', $values));
			$db->setQuery($query);
			$db->execute();
		}
		
		$db->setQuery('SELECT * FROM #__hikashop_field WHERE field_namekey = "category_custom_layout"');
		$category_custom_layout = $db->loadObject();
		if(empty($category_custom_layout)){
			$db->setQuery('SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = "#__hikashop_category" AND COLUMN_NAME = "category_custom_layout"');
			$category_custom_layout_exist = $db->loadColumn();
			if(empty($category_custom_layout_exist)){
				$db->setQuery('ALTER TABLE #__hikashop_category ADD category_custom_layout VARCHAR(255)');
				$db->execute();
			
				$query = $db->getQuery(true);
				$fields = array(
					$db->quoteName('product_layout').' = '.$db->quote($this->file1),
					$db->quoteName('category_custom_layout').' = '.$db->quote($this->file1)
				);
				$conditions = 1;
				$query->update($db->quoteName('#__hikashop_category'))->set($fields)->where($conditions);
				$db->setQuery($query);
				$result = $db->execute();
			}
			
			$db->setQuery('SELECT MAX(field_ordering) FROM #__hikashop_field WHERE field_table = "category"');
			$field_ordering = $db->loadResult();
			$query = $db->getQuery(true);
			$columns = array(
				'field_table',
				'field_realname',
				'field_namekey',
				'field_type',
				'field_value',
				'field_published',
				'field_ordering',
				'field_options',
				'field_default',
				'field_access',
				'field_categories',
				'field_products',
				'field_display'
			);
			$values = array(
				$db->quote('category'),
				$db->quote('Mise en page'),
				$db->quote('category_custom_layout'),
				$db->quote('singledropdown'),
				$db->quote($this->file1.'::'.$fileName1.'::0
'.$this->file2.'::'.$fileName2.'::0'),
				$db->quote(1),
				$db->quote($field_ordering),
				$db->quote('a:27:{s:12:"errormessage";s:0:"";s:5:"regex";s:0:"";s:9:"attribute";s:0:"";s:11:"placeholder";s:0:"";s:6:"inline";s:1:"0";s:12:"target_blank";s:1:"1";s:9:"allow_add";s:1:"0";s:4:"cols";s:0:"";s:9:"filtering";s:1:"1";s:9:"maxlength";s:1:"0";s:4:"rows";s:0:"";s:9:"zone_type";s:7:"country";s:12:"pleaseselect";s:1:"0";s:4:"size";s:0:"";s:6:"format";s:8:"%Y-%m-%d";s:5:"allow";s:0:"";s:18:"allowed_extensions";s:0:"";s:10:"upload_dir";s:0:"";s:12:"max_filesize";s:1:"0";s:9:"max_width";s:1:"0";s:10:"max_height";s:1:"0";s:8:"multiple";s:1:"0";s:8:"readonly";s:1:"0";s:12:"translatable";s:1:"0";s:24:"market_vendorselect_type";s:1:"0";s:11:"mysql_query";s:0:"";s:18:"datepicker_options";a:14:{s:5:"today";s:1:"0";s:6:"inline";s:1:"0";s:12:"monday_first";s:1:"0";s:12:"change_month";s:1:"0";s:11:"change_year";s:1:"0";s:16:"year_range_start";s:0:"";s:14:"year_range_end";s:0:"";s:14:"show_btn_panel";s:1:"0";s:11:"show_months";s:1:"1";s:11:"other_month";s:1:"0";s:19:"exclude_days_format";s:3:"mdY";s:7:"waiting";s:0:"";s:14:"hour_extra_day";s:0:"";s:11:"check_dates";s:3:"all";}}'),
				$db->quote($this->file1),
				$db->quote('all'),
				$db->quote('all'),
				$db->quote(''),
				$db->quote(';vendor_category_edit=1;vendor_category_listing=1;'),
			);
			$query
				->insert($db->quoteName('#__hikashop_field'))
				->columns($db->quoteName($columns))
				->values(implode(',', $values));
			$db->setQuery($query);
			$db->execute();
		
		}
		
		$db->setQuery('SELECT template FROM #__template_styles WHERE home = 1 AND client_id = 0');
		$template = $db->loadResult();
		
		if(!file_exists($_SERVER['DOCUMENT_ROOT'].'/components/com_hikashop/views/product/tmpl/'.$this->file1.'.php')){
			copy($_SERVER['DOCUMENT_ROOT'].'/components/com_hikashop/views/product/tmpl/'.$sourceFile.'.php', $_SERVER['DOCUMENT_ROOT'].'/templates/'.$template.'/html/com_hikashop/product/'.$this->file1.'.php');
		}
		
		if(!file_exists($_SERVER['DOCUMENT_ROOT'].'/components/com_hikashop/views/product/tmpl/'.$this->file2.'.php')){
			copy($_SERVER['DOCUMENT_ROOT'].'/components/com_hikashop/views/product/tmpl/'.$sourceFile.'.php', $_SERVER['DOCUMENT_ROOT'].'/templates/'.$template.'/html/com_hikashop/product/'.$this->file2.'.php');
		}
		
	}
	
	function setLayoutProduct($product){
		
		$productClass	= hikashop_get('class.product');
		$db				= JFactory::getDbo();
		
		$product_layout = $product->product_custom_layout;
		
		if($product->product_custom_layout == 'show_cat'){
			$db->setQuery('SELECT product_layout FROM #__hikashop_category WHERE category_id = (SELECT category_id FROM #__hikashop_product_category WHERE product_id = '.$product->product_id.' ORDER BY category_id DESC LIMIT 1)');
			$product_layout = $db->loadResult();
		}
		
		$query = $db->getQuery(true);
		$fields = array(
			$db->quoteName('product_layout').' = '.$db->quote($product_layout)
		);
		$conditions = array(
			$db->quoteName('product_id').' = '.$db->quote($product->product_id)
		);
		$query->update($db->quoteName('#__hikashop_product'))->set($fields)->where($conditions);
		$db->setQuery($query);
		$result = $db->execute();
		
	}
	
	
	function setLayoutCategory($category){
		
		$categoryClass	= hikashop_get('class.category');
		$db				= JFactory::getDbo();
		
		$query = $db->getQuery(true);
		$fields = array(
			$db->quoteName('product_layout').' = '.$db->quote($category->category_custom_layout)
		);
		$conditions = array(
			$db->quoteName('category_id').' = '.$db->quote($category->category_id)
		);
		$query->update($db->quoteName('#__hikashop_category'))->set($fields)->where($conditions);
		$db->setQuery($query);
		$result = $db->execute();
		
		$db->setQuery('SELECT * FROM #__hikashop_product WHERE product_id IN (SELECT product_id FROM #__hikashop_product_category WHERE category_id = '.$category->category_id.')');
		$products = $db->loadAssocList();
		var_dump($products);exit;
		foreach($products as $row){
			if($row['product_custom_layout'] = 'show_cat'){
				$query = $db->getQuery(true);
				$fields = array(
					$db->quoteName('product_layout').' = '.$db->quote($category->category_custom_layout)
				);
				$conditions = array(
					$db->quoteName('product_id').' = '.$db->quote($row['product_id'])
				);
				$query->update($db->quoteName('#__hikashop_product'))->set($fields)->where($conditions);
				$db->setQuery($query);
				$result = $db->execute();
			}
		}
		
	}
	
	function onAfterProductCreate(&$product) {
		self::setLayoutProduct($product);
	}
	
	function  onAfterProductUpdate(&$product){
		self::setLayoutProduct($product);
	}
	
	function onAfterCategoryCreate(&$category){
		var_dump('test');exit;
		self::setLayoutCategory($category);
	}
	
	function onAfterCategoryUpdate(&$category){
		var_dump('test');exit;
		self::setLayoutCategory($category);
	}
	
}

Last edit: 2 years 3 months ago by Minie.

Please Log in or Create an account to join the conversation.

  • Posts: 82823
  • Thank you received: 13370
  • MODERATOR
2 years 3 months ago #343503

Bonjour,

HikaMarket va charger les plugins du groupe "hikamarket" lorsqu'il déclenche un évènement.
Et HikaShop va charger les plugins du groupe "hikashop" lorsqu'il déclenche un évènement.
Là, vous essayez d'implémenter un évènement HikaShop dans un plugin du groupe "hikamarket". Il n'y a donc aucune garanti que le plugin soit chargé à ce moment là.

Donc il faudrait faire un plugin du groupe "hikashop" plutôt dans votre cas. En plus, dans ce cas, lorsque HikaMarket se charge, soit HikaShop est déjà chargé, soit HikaMarket charge HikaShop avant de se charger lui-même car HikaMarket a besoin d'HikaShop pour fonctionner.
Donc avec un plugin du groupe "hikashop" vous aurez accès à tous les évènements HikaShop et tous les évènements HikaMarket en bonus.
Sinon, plus généralement, si vous avez besoin d'implémenter des évènements de différentes extensions dans un même plugin, vous pouvez utiliser le groupe "system". Ainsi le plugin sera appeler pour tous les évènements possibles sur le site.

Please Log in or Create an account to join the conversation.

  • Posts: 453
  • Thank you received: 31
  • Hikamarket Multivendor Hikashop Business
2 years 3 months ago #343538

Bonjour,

merci pour votre réponse.

J'ai converti mon plugin en system.

Ca à l'air de fonctionner, merci à vous

Last edit: 2 years 3 months ago by Minie.

Please Log in or Create an account to join the conversation.

Moderators: Obsidev
Time to create page: 0.060 seconds
Powered by Kunena Forum