Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Browse Button in every picture


userb

Recommended Posts

Hi,

 

I need to add browse button to every picture I'm adding to my products. Now i have only one button. The code which is responsible for images should be here. I added also image to show what I want to add. Hope somebody will help.

 

beztytuucopyi.jpg

 

Uploaded with ImageShack.us

 

 

function update_stock($product_id, $quantity = 0) {
$get_quantity_query = tep_db_query("select sum(options_quantity) as total_quantity from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . (int)$product_id . "'");
$get_quantity = tep_db_fetch_array($get_quantity_query);
$total_quantity = $get_quantity['total_quantity'] + $quantity;
tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $total_quantity . "' where products_id = '" . (int)$product_id . "'");
}

function action_productPictures($request)
{
	global $smarty;
	$args = array();

	$args['products_id'] = $products_id = (int)$request['products_id'];
	if ($products_id == 0)
		return;

	//print_r($request);die;

	$zmiana = false;
	if (isset($request['productPicture_file']) || (isset($_FILES) && $_FILES))
		$zmiana = true;

	// usuwanie zdjęcia
	if (isset($request['products_picture_delete']) && $request['products_picture_delete'])
	{
		foreach($request['products_picture_delete'] as $order)
		{
			$product_pictures = M('OsCommerceProductPicture')->find(sql(array("
						products_id = %products_id
						AND products_pictures_order = %order
					",
					"products_id" => $products_id,
					"order" => $order
					)));
			if ($product_pictures)
			{
				$products_pictures_image = $product_pictures[0]['products_pictures_image'];
				$product_pictures[0]->delete();

				// usunięcie fizyczne pliku jeżeli już nie jest używany
				$otherOroductPicture = M('OsCommerceProductPicture')->findByProductsPicturesImage($products_pictures_image);
				if (empty($otherOroductPicture))
				{
					@unlink(DIR_FS_CATALOG . DIR_WS_IMAGES . $products_pictures_image);
				}
			}

			// jeżeli pierwsze to zmodyfikować też produkt
			if (M('OsCommerceProductPicture')->getNextOrder($products_id) == 1)
			{
				$products = M('OsCommerceProduct')->find($products_id);
				$products[0]['products_image'] = '';
				$products[0]->save();
			}
		}
	}

	// dodawanie zdjęcia
	if (isset($_FILES) && $_FILES)
	{
		//print_r($_FILES['productPicture_file']);die;

		if (is_uploaded_file($_FILES['productPicture_file']['tmp_name']))
		{
			$destination_name = strtolower(preg_replace('`[^a-zA-Z0-9\.\-\_]`', '', $_FILES['productPicture_file']['name']));
			//if (file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . $destination_name))
			//$destination_name = substr(md5(time()), 0, 4) . ".". $destination_name;

			if (move_uploaded_file($_FILES['productPicture_file']['tmp_name'], DIR_FS_CATALOG . DIR_WS_IMAGES . $destination_name))
			{
				$product_picture = M('OsCommerceProductPicture')->create();
				$product_picture['products_id'] = $products_id;
				$product_picture['products_pictures_image'] = $destination_name;
				$product_picture['products_pictures_order'] = M('OsCommerceProductPicture')->getNextOrder($products_id);
				$product_picture['products_pictures_size'] = $_FILES['productPicture_file']['size'];
				$product_picture->save();

				// jeżeli pierwsze to zmodyfikować też produkt
				if ($product_picture['products_pictures_order'] == 1)
				{
					$products = M('OsCommerceProduct')->find($products_id);
					$products[0]['products_image'] = $destination_name;
					$products[0]->save();
				}
			}
		}
	}

	$products = M('OsCommerceProduct')->find($products_id);
	if ($products)
	{
		$product = $products[0];
		$product_pictures = $product->OsCommerceProductPicture;

		// poniższy warunek ma na celu tylko synchronizację tego co jest w tabelce products_pictures i products
		if ($product_pictures)
		{
			if ($product['products_image'] != $product_pictures[0]['products_pictures_image'])
			{
				$product['products_image'] = $product_pictures[0]['products_pictures_image'];
				$product->save();
			}
		}
		elseif($product['products_image'] != '')
		{
			$product_picture = M('OsCommerceProductPicture')->create();
			$product_picture['products_id'] = $products_id;
			$product_picture['products_pictures_image'] = $product['products_image'];
			$product_picture['products_pictures_order'] = 1;
			$product_picture['products_pictures_size'] = @filesize(DIR_FS_CATALOG.DIR_WS_IMAGES . $product['products_image']);
			$product_picture->save();
		}

		$product_pictures = $product->OsCommerceProductPicture;

		if ($product_pictures)
			$args['pictures'] = $product_pictures->asArray();
	}

	$args['SMALL_IMAGE_WIDTH'] = SMALL_IMAGE_WIDTH;
	$args['SMALL_IMAGE_HEIGHT'] = SMALL_IMAGE_HEIGHT;

	//$args['random'] = md5(time());

	$smarty->assign($args);

	if (!$zmiana)
		$smarty->display(file_name . '.' . $request['action'] . '.tpl');
	else
		print $products_id;

	die;
}

function action_productFiles($request)
{
	global $smarty;
	$args = array();

	$args['products_id'] = $products_id = (int)$request['products_id'];
	if ($products_id == 0)
		return;

	$args['DIR_WS_IMAGES'] = DIR_WS_CATALOG . DIR_WS_IMAGES;

	//print_r($request);die;

	$zmiana = false;
	if (isset($request['productFile_file']) || (isset($_FILES) && $_FILES))
		$zmiana = true;

	// dodawanie pliku
	if (isset($_FILES) && $_FILES)
	{
		if (is_uploaded_file($_FILES['productFile_file']['tmp_name']))
		{
			$destination_name = strtolower(preg_replace('`[^a-zA-Z0-9\.\-\_]`', '', $_FILES['productFile_file']['name']));
			//if (file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . $destination_name))
			//$destination_name = substr(md5(time()), 0, 4) . ".". $destination_name;

			if (move_uploaded_file($_FILES['productFile_file']['tmp_name'], DIR_FS_CATALOG . DIR_WS_IMAGES . $destination_name))
			{
				$product_file = M('OsCommerceProductFile')->create();
				$product_file['products_id'] = $products_id;
				$product_file['products_files_file'] = $destination_name;
				$product_file['products_files_title'] = $request['productFile_title'];
				$product_file['products_files_order'] = M('OsCommerceProductFile')->getNextOrder($products_id);
				$product_file['products_files_size'] = $_FILES['productFile_file']['size'];
				$product_file->save();
			}
		}
	}

	// usuwanie pliku
	if (isset($request['products_file_delete']) && $request['products_file_delete'])
	{
		foreach($request['products_file_delete'] as $order)
		{
			$product_files = M('OsCommerceProductFile')->find(sql(array("
						products_id = %products_id
						AND products_files_order = %order
					",
					"products_id" => $products_id,
					"order" => $order
					)));
			if ($product_files)
			{
				// usunięcie fizyczne pliku
				@unlink(DIR_FS_CATALOG . DIR_WS_IMAGES . $product_files[0]['products_files_file']);

				$product_files[0]->delete();
			}
		}
	}

	$products = M('OsCommerceProduct')->find($products_id);
	if ($products)
	{
		$product = $products[0];
		$product_files = $product->OsCommerceProductFile;

		if ($product_files)
			$args['files'] = $product_files->asArray();
	}

	$smarty->assign($args);

	if (!$zmiana)
		$smarty->display(file_name . '.' . $request['action'] . '.tpl');
	else
		print $products_id;

	die;
}

$action = false;
if (isset($_REQUEST['action']))
{
	$action = preg_replace('`[^a-zA-Z]`', '', $_REQUEST['action']);
	$function_name = 'action_'.$action;
	if (function_exists($function_name))
		$function_name($_REQUEST);
	else
		$action = false;
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...