Перейти до вмісту
Пошук в
  • Детальніше...
Шукати результати, які ...
Шукати результати в ...

Продажа товара оптом в пачках


Recommended Posts

Подскажите как реализовать такое:

Есть товар, который отпускается оптом в пачках. В пачке может быть 5, 10, 15 и 20 единиц продукции.

Цены по магазину указаны за единицу, дабы не шокировать клиентов :rolleyes:

Надо чтобы товар добавленный в корзину, автоматически считался как за пачку и умножался на 5, 10, 15 или 20.

При чем чтобы множитель пачки товара можно было задавать из админки в карточке товара.

Как такое сделать практически?

Надіслати
Поділитися на інших сайтах


если знаком с php/mysql/html то подскажу где что искать, если нет - то со столь специфичным заданием ответ лучше искать в разделе платных услуг)

Надіслати
Поділитися на інших сайтах


если знаком с php/mysql/html то подскажу где что искать, если нет - то со столь специфичным заданием ответ лучше искать в разделе платных услуг)

Знание на уровне основ есть.

Подскажите пожалуйста, только доходчиво :rolleyes:

Надіслати
Поділитися на інших сайтах


глянул сейчас свое старенькое решение которое делал на farmatek.ru (оказалось не так уж и сложно как показалось)

вообщем примерно так было дело:

чтоб не плодить лишних полей в базе я для определения количества в пачке использовал поле SKU (в редактировании товара оно есть) и на основе его собственно и делал

в ..\controller\product\product.php

добавил

$this->data['sku'] = $product_info['sku'];

в product.tpl

рядом со строчкой

<input type="text" name="quantity" size="3" value="1" />
добавил

<?php if ($sku) {echo ' x '.$sku;} ?>
так сказать для информативности

и чуть ниже

<input type="hidden" name="sku" value="<? echo $sku; ?>" />
будем передавать информацию при добавлении в корзину о том сколько в пачке штук

теперь идем в ..\controller\module\cart.php

в функции callback() меняем

$this->cart->add($this->request->post['product_id'], $this->request->post['quantity'], $option);
на

if ($this->request->post['sku']) {
	$sku = $this->request->post['sku'];
} else {
	$sku = 1;
}
$this->cart->add($this->request->post['product_id'], $this->request->post['quantity']*$sku, $option);

в ..\controller\checkout\cart.php

делаем тоже самое что и в предыдущем действии

вроде все.. теперь все товары будут улетать в корзину пачками по sku штук

здесь правда не учитывается что в корзине можно будет редактировать количество, но там дело за малым

Надіслати
Поділитися на інших сайтах


Всё сделал как сказали, поле sku задействовалось - рядом с количеством значение sku выводится, но при добавлении в корзину умножение на sku не происходит... Может быть потому что у меня не стандартный модуль корзины?

Код модуль \module\cart.php в результате такой:

<?php 
class ControllerModuleCart extends Controller { 
protected function index() {
	$this->language->load('module/cart');

	$this->load->model('tool/seo_url');

   	$this->data['heading_title'] = $this->language->get('heading_title');

	$this->data['text_subtotal'] = $this->language->get('text_subtotal');
	$this->data['text_empty'] = $this->language->get('text_empty');
	$this->data['text_remove'] = $this->language->get('text_remove');
	$this->data['text_confirm'] = $this->language->get('text_confirm');
	$this->data['text_view'] = $this->language->get('text_view');
	$this->data['text_checkout'] = $this->language->get('text_checkout');

	$this->data['view'] = HTTP_SERVER . 'index.php?route=checkout/cart';
	$this->data['checkout'] = HTTPS_SERVER . 'index.php?route=checkout/shipping';

	$this->data['products'] = array();

   	foreach ($this->cart->getProducts() as $result) {
       	$option_data = array();

       	foreach ($result['option'] as $option) {
         		$option_data[] = array(
           		'name'  => $option['name'],
           		'value' => $option['value']
         		);
       	}

     		$this->data['products'][] = array(
       		'key' 		 => $result['key'],
       		'name'       => $result['name'],
			'option'     => $option_data,
       		'quantity'   => $result['quantity'],
			'stock'      => $result['stock'],
			'price'      => $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))),
			'href'       => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $result['product_id']),
     		);
   	}

	if (!$this->config->get('config_customer_price')) {
		$this->data['display_price'] = TRUE;
	} elseif ($this->customer->isLogged()) {
		$this->data['display_price'] = TRUE;
	} else {
		$this->data['display_price'] = FALSE;
	}

	$total_data = array();
	$total = 0;
	$taxes = $this->cart->getTaxes();

	$this->load->model('checkout/extension');

	$sort_order = array(); 

	$results = $this->model_checkout_extension->getExtensions('total');

	foreach ($results as $key => $value) {
		$sort_order[$key] = $this->config->get($value['key'] . '_sort_order');
	}

	array_multisort($sort_order, SORT_ASC, $results);

	foreach ($results as $result) {
		$this->load->model('total/' . $result['key']);

		$this->{'model_total_' . $result['key']}->getTotal($total_data, $total, $taxes);
	}

	$sort_order = array(); 

	foreach ($total_data as $key => $value) {
     		$sort_order[$key] = $value['sort_order'];
   	}

   	array_multisort($sort_order, SORT_ASC, $total_data);

   	$this->data['totals'] = $total_data;

	$this->data['ajax'] = $this->config->get('cart_ajax');

	$this->id = 'cart';

	if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/cart.tpl')) {
		$this->template = $this->config->get('config_template') . '/template/module/cart.tpl';
	} else {
		$this->template = 'default/template/module/cart.tpl';
	}

	$this->render();
}

public function callback() {
	$this->language->load('module/cart');

	$this->load->model('tool/seo_url');

	unset($this->session->data['shipping_methods']);
	unset($this->session->data['shipping_method']);
	unset($this->session->data['payment_methods']);
	unset($this->session->data['payment_method']);	

	if ($this->request->server['REQUEST_METHOD'] == 'POST') {

		if (isset($this->request->post['remove'])) {
    		$result = explode('_', $this->request->post['remove']);
         		$this->cart->remove(trim($result[1]));
     		} else {
			if (isset($this->request->post['option'])) {
				$option = $this->request->post['option'];
			} else {
				$option = array();	
			}

     		if ($this->request->post['sku']) {
       $sku = $this->request->post['sku'];
} else {
       $sku = 1;
}
$this->cart->add($this->request->post['product_id'], $this->request->post['quantity']*$sku, $option);
		}
	}

	$output = '<table cellpadding="2" cellspacing="0" style="width: 100%;">';

	if ($this->cart->getProducts()) {

   		foreach ($this->cart->getProducts() as $product) {
     			$output .= '<tr>';
       		$output .= '<td width="1" valign="top" align="left"><span class="cart_remove" id="remove_ ' . $product['key'] . '" /> </span></td><td width="1" valign="top" align="right">' . $product['quantity'] . ' x </td>';
       		$output .= '<td align="left" valign="top"><a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $product['product_id']) . '">' . $product['name'] . '</a>';
         		$output .= '<div>';

			foreach ($product['option'] as $option) {
           		$output .= ' - <small style="color: #999;">' . $option['name'] . ' ' . $option['value'] . '</small><br />';
            }

			$output .= '</div></td>';
			$output .= '</tr>';
     		}

		$output .= '</table>';
   		$output .= '<br />';

   		$total = 0;
		$taxes = $this->cart->getTaxes();

		$this->load->model('checkout/extension');

		$sort_order = array(); 

		$view = HTTP_SERVER . 'index.php?route=checkout/cart';
		$checkout = HTTPS_SERVER . 'index.php?route=checkout/shipping';

		$results = $this->model_checkout_extension->getExtensions('total');

		foreach ($results as $key => $value) {
			$sort_order[$key] = $this->config->get($value['key'] . '_sort_order');
		}

		array_multisort($sort_order, SORT_ASC, $results);

		foreach ($results as $result) {
			$this->load->model('total/' . $result['key']);

			$this->{'model_total_' . $result['key']}->getTotal($total_data, $total, $taxes);
		}

		$sort_order = array(); 

		foreach ($total_data as $key => $value) {
     			$sort_order[$key] = $value['sort_order'];
   		}

   		array_multisort($sort_order, SORT_ASC, $total_data);

   		$output .= '<table cellpadding="0" cellspacing="0" align="right" style="display:inline-block;">';
     		foreach ($total_data as $total) {
     			$output .= '<tr>';
	        $output .= '<td align="right"><span class="cart_module_total"><b>' . $total['title'] . '</b></span></td>';
	        $output .= '<td align="right"><span class="cart_module_total">' . $total['text'] . '</span></td>';
     			$output .= '</tr>';
     		}
     		$output .= '</table>';
     		$output .= '<div style="padding-top:5px;text-align:center;clear:both;"><a href="' . $view . '">' . $this->language->get('text_view') . '</a> | <a href="' . $checkout . '">' . $this->language->get('text_checkout') . '</a></div>';
	} else {
		$output .= '<div style="text-align: center;">' . $this->language->get('text_empty') . '</div>';
	}

	$this->response->setOutput($output, $this->config->get('config_compression'));
} 	
	public function callbacktop() {
	$this->language->load('module/cart');

	$this->load->model('tool/seo_url');

	unset($this->session->data['shipping_methods']);
	unset($this->session->data['shipping_method']);
	unset($this->session->data['payment_methods']);
	unset($this->session->data['payment_method']);

	if ($this->request->server['REQUEST_METHOD'] == 'POST') {

	if (isset($this->request->post['remove'])) {
	$result = explode('_', $this->request->post['remove']);
	$this->cart->remove(trim($result[1]));
	} else {
	if (isset($this->request->post['option'])) {
	$option = $this->request->post['option'];
	} else {
	$option = array();
}

	$this->cart->add($this->request->post['product_id'], $this->request->post['quantity'], $option);
}
}

	if ($this->cart->getProducts()) {

	$total = 0;
	$taxes = $this->cart->getTaxes();

	$this->load->model('checkout/extension');

	$sort_order = array();

	$view = HTTP_SERVER . 'index.php?route=checkout/cart';
	$checkout = HTTPS_SERVER . 'index.php?route=checkout/shipping';

	$results = $this->model_checkout_extension->getExtensions('total');

	foreach ($results as $key => $value) {
	$sort_order[$key] = $this->config->get($value['key'] . '_sort_order');
}

	array_multisort($sort_order, SORT_ASC, $results);

	foreach ($results as $result) {
	$this->load->model('total/' . $result['key']);

	$this->{'model_total_' . $result['key']}->getTotal($total_data, $total, $taxes);
}

	$sort_order = array();

	foreach ($total_data as $key => $value) {
	$sort_order[$key] = $value['sort_order'];
}

	array_multisort($sort_order, SORT_ASC, $total_data);

	foreach ($total_data as $total) {}
}

	$output_mod = '<font class="top_cart_val">';
	$output_mod .= $total['text'];

	$output_mod .= '</font><br/>
	<font class="top_cart_count_text">'. $this->language->get('text_youhave_gkc') .' '.$this->cart->countProducts().' '. $this->language->get('text_items_gkc') .'.</font>';

	$this->response->setOutput($output_mod, $this->config->get('config_compression'));
	}

}
?>

А код checkout\cart.php такой:

<?php 
class ControllerCheckoutCart extends Controller {
private $error = array();

public function index() {
	$this->language->load('checkout/cart');

	if ($this->request->server['REQUEST_METHOD'] == 'GET' && isset($this->request->get['product_id'])) {

		if (isset($this->request->get['option'])) {
			$option = $this->request->get['option'];
		} else {
			$option = array();	
		}

		if (isset($this->request->get['quantity'])) {
			$quantity = $this->request->get['quantity'];
		} else {
			$quantity = 1;
		}

		unset($this->session->data['shipping_methods']);
		unset($this->session->data['shipping_method']);
		unset($this->session->data['payment_methods']);
		unset($this->session->data['payment_method']);

	if ($this->request->post['sku']) {
       $sku = $this->request->post['sku'];
} else {
       $sku = 1;
}
$this->cart->add($this->request->post['product_id'], $this->request->post['quantity']*$sku, $option);

		$this->redirect(HTTPS_SERVER . 'index.php?route=checkout/cart');

	} elseif ($this->request->server['REQUEST_METHOD'] == 'POST') {

     		if (isset($this->request->post['quantity'])) {
			if (!is_array($this->request->post['quantity'])) {
				if (isset($this->request->post['option'])) {
					$option = $this->request->post['option'];
				} else {
					$option = array();	
				}

     				$this->cart->add($this->request->post['product_id'], $this->request->post['quantity'], $option);
			} else {
				foreach ($this->request->post['quantity'] as $key => $value) {
      				$this->cart->update($key, $value);
				}
			}

			unset($this->session->data['shipping_methods']);
			unset($this->session->data['shipping_method']);
			unset($this->session->data['payment_methods']);
			unset($this->session->data['payment_method']);
     		}

     		if (isset($this->request->post['remove'])) {
    		foreach (array_keys($this->request->post['remove']) as $key) {
         			$this->cart->remove($key);
			}
     		}

		if (isset($this->request->post['redirect'])) {
			$this->session->data['redirect'] = $this->request->post['redirect'];
		}	

		if (isset($this->request->post['quantity']) || isset($this->request->post['remove'])) {
			unset($this->session->data['shipping_methods']);
			unset($this->session->data['shipping_method']);
			unset($this->session->data['payment_methods']);
			unset($this->session->data['payment_method']);	

			$this->redirect(HTTPS_SERVER . 'index.php?route=checkout/cart');
		}
   	}

   	$this->document->title = $this->language->get('heading_title');

     	$this->document->breadcrumbs = array();

     	$this->document->breadcrumbs[] = array(
       	'href'      => HTTP_SERVER . 'index.php?route=common/home',
       	'text'      => $this->language->get('text_home'),
       	'separator' => FALSE
     	); 

     	$this->document->breadcrumbs[] = array(
       	'href'      => HTTP_SERVER . 'index.php?route=checkout/cart',
       	'text'      => $this->language->get('text_basket'),
       	'separator' => $this->language->get('text_separator')
     	);

   	if ($this->cart->hasProducts()) {
     		$this->data['heading_title'] = $this->language->get('heading_title');

		$this->data['text_select'] = $this->language->get('text_select');
     		$this->data['text_sub_total'] = $this->language->get('text_sub_total');
		$this->data['text_discount'] = $this->language->get('text_discount');
		$this->data['text_weight'] = $this->language->get('text_weight');

    		$this->data['column_remove'] = $this->language->get('column_remove');
     		$this->data['column_image'] = $this->language->get('column_image');
     		$this->data['column_name'] = $this->language->get('column_name');
     		$this->data['column_model'] = $this->language->get('column_model');
     		$this->data['column_quantity'] = $this->language->get('column_quantity');
		$this->data['column_price'] = $this->language->get('column_price');
     		$this->data['column_total'] = $this->language->get('column_total');

     		$this->data['button_update'] = $this->language->get('button_update');
     		$this->data['button_shopping'] = $this->language->get('button_shopping');
     		$this->data['button_checkout'] = $this->language->get('button_checkout');

		if (isset($this->error['warning'])) {
			$this->data['error_warning'] = $this->error['warning'];			
		} elseif (!$this->cart->hasStock() && (!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning'))) {
     			$this->data['error_warning'] = $this->language->get('error_stock');
		} else {
			$this->data['error_warning'] = '';
		}

		$this->data['action'] = HTTPS_SERVER . 'index.php?route=checkout/cart';

		$this->load->model('tool/seo_url'); 
		$this->load->model('tool/image');

     		$this->data['products'] = array();

     		foreach ($this->cart->getProducts() as $result) {
       		$option_data = array();

       		foreach ($result['option'] as $option) {
         			$option_data[] = array(
           			'name'  => $option['name'],
           			'value' => $option['value']
         			);
       		}

			if ($result['image']) {
				$image = $result['image'];
			} else {
				$image = 'no_image.jpg';
			}

       		$this->data['products'][] = array(
         			'key'      => $result['key'],
         			'name'     => $result['name'],
         			'model'    => $result['model'],
         			'thumb'    => $this->model_tool_image->resize($image, $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height')),
         			'option'   => $option_data,
         			'quantity' => $result['quantity'],
         			'stock'    => $result['stock'],
				'price'    => $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))),
				'total'    => $this->currency->format($this->tax->calculate($result['total'], $result['tax_class_id'], $this->config->get('config_tax'))),
				'href'     => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $result['product_id'])
       		);
     		}

		if (!$this->config->get('config_customer_price')) {
			$this->data['display_price'] = TRUE;
		} elseif ($this->customer->isLogged()) {
			$this->data['display_price'] = TRUE;
		} else {
			$this->data['display_price'] = FALSE;
		}

		if ($this->config->get('config_cart_weight')) {
			$this->data['weight'] = $this->weight->format($this->cart->getWeight(), $this->config->get('config_weight_class'));
		} else {
			$this->data['weight'] = FALSE;
		}

     		$total_data = array();
		$total = 0;
		$taxes = $this->cart->getTaxes();

		$this->load->model('checkout/extension');

		$sort_order = array(); 

		$results = $this->model_checkout_extension->getExtensions('total');

		foreach ($results as $key => $value) {
			$sort_order[$key] = $this->config->get($value['key'] . '_sort_order');
		}

		array_multisort($sort_order, SORT_ASC, $results);

		foreach ($results as $result) {
			$this->load->model('total/' . $result['key']);

			$this->{'model_total_' . $result['key']}->getTotal($total_data, $total, $taxes);
		}

		$sort_order = array(); 

		foreach ($total_data as $key => $value) {
     			$sort_order[$key] = $value['sort_order'];
   		}

   		array_multisort($sort_order, SORT_ASC, $total_data);

		$this->data['totals'] = $total_data;

		if (isset($this->session->data['redirect'])) {
     			$this->data['continue'] = $this->session->data['redirect'];

			unset($this->session->data['redirect']);
		} else {
			$this->data['continue'] = HTTP_SERVER . 'index.php?route=common/home';
		}

		$this->data['checkout'] = HTTPS_SERVER . 'index.php?route=checkout/shipping';

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/cart.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/checkout/cart.tpl';
		} else {
			$this->template = 'default/template/checkout/cart.tpl';
		}

		$this->children = array(
			'common/column_right',
			'common/column_left',
			'common/footer',
			'common/header'
		);		

		$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));					
   	} else {
     		$this->data['heading_title'] = $this->language->get('heading_title');

     		$this->data['text_error'] = $this->language->get('text_error');

     		$this->data['button_continue'] = $this->language->get('button_continue');

     		$this->data['continue'] = HTTP_SERVER . 'index.php?route=common/home';

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
		} else {
			$this->template = 'default/template/error/not_found.tpl';
		}

		$this->children = array(
			'common/column_right',
			'common/column_left',
			'common/footer',
			'common/header'
		);

		$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));			
   	}
 	}
}
?>

Надіслати
Поділитися на інших сайтах


  • 1 year later...

В 1.5.3.1 функция изменилась и заменяемых строк нет (как и собственно функции callback()) может кто нибудь делал подобное для данной версии и подскажет как быть?

Похожая по смыслу строка выглядит так вот:

$this->cart->add($this->request->post['product_id'], $quantity, $option);

Менять в ней?

p.s. сделал: Прошелся поиском по $this->cart->add

и везде добавил условие вначале

if ($this->request->post['sku']) {

$sku = $this->request->post['sku'];

} else {

$sku = 1;

}

потом в этих строках ['quantity']*$sku сделал

В корзину добавляет теперь, а вот как сделать чтобы в корзине выводилось не количество штук а деленное на значение sku - чтобы менять можно было только количество упаковок

Змінено користувачем vorobey
Надіслати
Поділитися на інших сайтах


  • 2 weeks later...

В 1.5.х.х достаточно

в catalogcontrollercheckoutcart.php в районе 353 строки под

   if (!isset($json['error'])) {
Чтобы было так:

	if ($this->request->post['sku']) {
		$sku = $this->request->post['sku'];
} else {
		$sku = 1;
}
$this->cart->add($this->request->post['product_id'], $quantity*$sku, $option);

Кстати, лучше не sku использовать, а upc т.к. sku задействуется в 1.5.хх как артикул и выводится в документах

Надіслати
Поділитися на інших сайтах


В 1.5.х.х достаточно

в catalogcontrollercheckoutcart.php в районе 353 строки под

   if (!isset($json['error'])) {
Чтобы было так:

	if ($this->request->post['sku']) {
		$sku = $this->request->post['sku'];
} else {
		$sku = 1;
}
$this->cart->add($this->request->post['product_id'], $quantity*$sku, $option);

Кстати, лучше не sku использовать, а upc т.к. sku задействуется в 1.5.хх как артикул и выводится в документах

пытаюсь настроить данную фишку на версии 1.5.3.1 , но в районе

353 строки и вообще в данном файле нет нечего подобного...

Ребята, подскажите, как быть?

Змінено користувачем dfg
Надіслати
Поділитися на інших сайтах


пытаюсь настроить данную фишку на версии 1.5.3.1 , но в районе

353 строки и вообще в данном файле нет нечего подобного...

Ребята, подскажите, как быть?

В 1.5.3.1 - 541 строка

Вместо:

$this->cart->add($this->request->post['product_id'], $quantity, $option);

Поставить:

if ($this->request->post['sku']) {
				$sku = $this->request->post['sku'];
} else {
				$sku = 1;
}
$this->cart->add($this->request->post['product_id'], $quantity*$sku, $option);

Ctrl F тебе в помощь :-)

Надіслати
Поділитися на інших сайтах


  • 1 year later...
  • 9 years later...

Створіть аккаунт або увійдіть для коментування

Ви повинні бути користувачем, щоб залишити коментар

Створити обліковий запис

Зареєструйтеся для отримання облікового запису. Це просто!

Зареєструвати аккаунт

Вхід

Уже зареєстровані? Увійдіть тут.

Вхід зараз
  • Зараз на сторінці   0 користувачів

    • Ні користувачів, які переглядиють цю сторінку

×
×
  • Створити...

Important Information

На нашому сайті використовуються файли cookie і відбувається обробка деяких персональних даних користувачів, щоб поліпшити користувальницький інтерфейс. Щоб дізнатися для чого і які персональні дані ми обробляємо перейдіть за посиланням . Якщо Ви натиснете «Я даю згоду», це означає, що Ви розумієте і приймаєте всі умови, зазначені в цьому Повідомленні про конфіденційність.