Jump to content
alexComposer

Удаление трех товаров из корзины одновременно

Recommended Posts

Я новичок в опенкарте, реализовал добавление двух подарочных товаров в корзину вместе с добавлением первого платного

if (!$json) {
				$this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id);

			$cart_contents = $this->cart->countProducts();
			if ($cart_contents == 1) {
    			$this->cart->add('656', '1');
				$this->cart->add('657', '1');
			}
}

Помогите реализовать удаление этих двух товаров вместе с последним платным из корзины. вот моя попытка (не работает)

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

 $cart_contents = $this->cart->countProducts();

		 if (isset($this->request->post['product_id'])) {
			 if ($cart_contents == 3) {
				 $this->cart->remove($this->request->post['product_id']);
    			 $this->cart->remove('656');
				 $this->cart->remove('657');
			 }
		 }

 

Share this post


Link to post
Share on other sites
1 час назад, alexComposer сказал:

$this->cart->remove('656');

public function remove($cart_id) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE cart_id = '" . (int)$cart_id . "' AND api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");
	}

 

Share this post


Link to post
Share on other sites
2 часа назад, fanatic сказал:

public function remove($cart_id) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE cart_id = '" . (int)$cart_id . "' AND api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");
	}

 

 

Думаю можно просто проверять общую стоимость (total), и просто использовать метод clear при нулевом total

Edited by Pavel666

Share this post


Link to post
Share on other sites
11 часов назад, Pavel666 сказал:

при нулевом total

1. если у подарков, цена 0

2. если в корзине,  нет других товаров 

 

Share this post


Link to post
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
You are posting as a guest. If you have an account, please sign in.
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.


  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.