Jump to content

Help with Manufacture block modification


hopkins001

Recommended Posts

The scenario is:

 

I have a block php setup on my online store's site.

Manufactures block lets me add a manufacture with description and a picture, than it displays it in a block on my webpage in a list form.

 

I need to modify the manufactures block on my shops site to have an option to add a manufacture under another manufacture ( like a product line kind of thing).

 

If anyone has any ideas, or at least can give me a starting point of how could i modify that code please reply. HELP REALLY APPRICIATED.

Here's the current code:

 

blockmanufacturer.php

<?php

class BlockManufacturer extends Module
{
    function __construct()
    {
        $this->name = 'blockmanufacturer';
        $this->tab = 'Blocks';
        $this->version = 1.0;

        parent::__construct();

        /* The parent construct is required for translations */
	$this->page = basename(__FILE__, '.php');
	$this->displayName = $this->l('Manufacturers block');
        $this->description = $this->l('Displays a block of manufacturers/brands');
    }

    function install()
    {
        parent::install();
        $this->registerHook('leftColumn');
	Configuration::updateValue('MANUFACTURER_DISPLAY_TEXT', true);
	Configuration::updateValue('MANUFACTURER_DISPLAY_TEXT_NB', 5);
	Configuration::updateValue('MANUFACTURER_DISPLAY_FORM', true);
    }
   
    function hookLeftColumn($params)
    {
	global $smarty, $link;

	$smarty->assign(array(
		'manufacturers' => Manufacturer::getManufacturers(),
		'link' => $link,
		'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'),
		'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'),
		'form_list' => Configuration::get('MANUFACTURER_DISPLAY_FORM'),
	));
	return $this->display(__FILE__, 'blockmanufacturer.tpl');
}

function hookRightColumn($params)
{
	return $this->hookLeftColumn($params);
}

function getContent()
{
	$output = '<h2>'.$this->displayName.'</h2>';
	if (Tools::isSubmit('submitBlockManufacturers'))
	{
		$text_list = intval(Tools::getValue('text_list'));
		$text_nb = intval(Tools::getValue('text_nb'));
		$form_list = intval(Tools::getValue('form_list'));
		if ($text_list AND !Validate::isUnsignedInt($text_nb))
			$errors[] = $this->l('Invalid number of elements');
		elseif (!$text_list AND !$form_list)
			$errors[] = $this->l('Please activate at least one system list');
		else
		{
			Configuration::updateValue('MANUFACTURER_DISPLAY_TEXT', $text_list);
			Configuration::updateValue('MANUFACTURER_DISPLAY_TEXT_NB', $text_nb);
			Configuration::updateValue('MANUFACTURER_DISPLAY_FORM', $form_list);
		}
		if (isset($errors) AND sizeof($errors))
			$output .= $this->displayError(implode('<br />', $errors));
		else
			$output .= $this->displayConfirmation($this->l('Settings updated'));
	}
	return $output.$this->displayForm();
}

public function displayForm()
{
	$output = '
	<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
		<fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
			<label>'.$this->l('Use a plain-text list').'</label>
			<div class="margin-form">
				<input type="radio" name="text_list" id="text_list_on" value="1" '.(Tools::getValue('text_list', Configuration::get('MANUFACTURER_DISPLAY_TEXT')) ? 'checked="checked" ' : '').'/>
				<label class="t" for="text_list_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
				<input type="radio" name="text_list" id="text_list_off" value="0" '.(!Tools::getValue('text_list', Configuration::get('MANUFACTURER_DISPLAY_TEXT')) ? 'checked="checked" ' : '').'/>
				<label class="t" for="text_list_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
				   '.$this->l('Display').' <input type="text" size="2" name="text_nb" value="'.intval(Tools::getValue('text_nb', Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'))).'" /> '.$this->l('elements').'
				<p class="clear">'.$this->l('To display manufacturers in a plain-text list').'</p>
			</div>
			<label>'.$this->l('Use a drop-down list').'</label>
			<div class="margin-form">
				<input type="radio" name="form_list" id="form_list_on" value="1" '.(Tools::getValue('form_list', Configuration::get('MANUFACTURER_DISPLAY_FORM')) ? 'checked="checked" ' : '').'/>
				<label class="t" for="form_list_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
				<input type="radio" name="form_list" id="form_list_off" value="0" '.(!Tools::getValue('form_list', Configuration::get('MANUFACTURER_DISPLAY_FORM')) ? 'checked="checked" ' : '').'/>
				<label class="t" for="form_list_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
				<p class="clear">'.$this->l('To display manufacturers in a drop-down list').'</p>
			</div>
			<center><input type="submit" name="submitBlockManufacturers" value="'.$this->l('Save').'" class="button" /></center>
		</fieldset>
	</form>';
	return $output;
}
}

?>

 

blockmanufacturer.tpl

<div id="manufacturers_block_left" class="block blockmanufacturer">
<h4><a href="{$base_dir}manufacturer.php" title="{l s='Manufacturers' mod='blockmanufacturer'}">{l s='Manufacturers' mod='blockmanufacturer'}</a></h4>
<div class="block_content">
{if $manufacturers}
{if $text_list}
<ul class="bullet">
{foreach from=$manufacturers item=manufacturer name=manufacturer_list}
	{if $smarty.foreach.manufacturer_list.iteration <= $text_list_nb}
	<li class="{if $smarty.foreach.manufacturer_list.last}last_item{elseif $smarty.foreach.manufacturer_list.first}first_item{else}item{/if}"><a href="{$link->getmanufacturerLink($manufacturer.id_manufacturer, $manufacturer.link_rewrite)}" title="{l s='More about' mod='blockmanufacturer'} {$manufacturer.name}">{$manufacturer.name}</a></li>
	{/if}
{/foreach}
</ul>
{/if}
{if $form_list}
	<form action="{$smarty.server.SCRIPT_NAME}" method="get">
		<p>
			<select id="manufacturer_list" onclick="autoUrl('manufacturer_list', '');">
				<option value="0">{l s='All manufacturers' mod='blockmanufacturer'}</option>
			{foreach from=$manufacturers item=manufacturer}
				<option value="{$link->getmanufacturerLink($manufacturer.id_manufacturer, $manufacturer.link_rewrite)}">{$manufacturer.name}</option>
			{/foreach}
			</select>
		</p>
	</form>
{/if}
{else}
<p>{l s='No manufacturer' mod='blockmanufacturer'}</p>
{/if}
</div>
</div>

 

Maybe someone at least can tell me if im on the right track...

i know i have to create a new field in my manufactures table in the database.

 

Lets say i'll call it "product_line", give it INT(10) default value 0 ( 0 would corespond to the main manufacture). Nubers other than 0 would corespond to the manufacture_id number in the manufactures table.

Admin adds a new manufacture. (in his form he will have a list called Master_Manufacture that would write the manufacture_id value to the product_line value in the database)

 

Could anyone write a little sample of how should i start? thx for any help

And by the way, if i posted in a wrong section than please move me to the more propper one. Thank you

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.