Created
April 8, 2016 20:56
-
-
Save unlocomqx/b00689a4035db2295fa94600fa5885dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function deleteProduct($id_product, $id_product_attribute = null, $id_customization = null, $id_address_delivery = 0) | |
{ | |
if (isset(self::$_nbProducts[$this->id])) { | |
unset(self::$_nbProducts[$this->id]); | |
} | |
if (isset(self::$_totalWeight[$this->id])) { | |
unset(self::$_totalWeight[$this->id]); | |
} | |
if ((int)$id_customization) { | |
$product_total_quantity = (int)Db::getInstance()->getValue( | |
'SELECT `quantity` | |
FROM `'._DB_PREFIX_.'cart_product` | |
WHERE `id_product` = '.(int)$id_product.' | |
AND `id_customization` = '.(int)$id_customization.' | |
AND `id_cart` = '.(int)$this->id.' | |
AND `id_product_attribute` = '.(int)$id_product_attribute | |
); | |
$customization_quantity = (int)Db::getInstance()->getValue(' | |
SELECT `quantity` | |
FROM `'._DB_PREFIX_.'customization` | |
WHERE `id_cart` = '.(int)$this->id.' | |
AND `id_product` = '.(int)$id_product.' | |
AND `id_customization` = '.(int)$id_customization.' | |
AND `id_product_attribute` = '.(int)$id_product_attribute.' | |
'.((int)$id_address_delivery ? 'AND `id_address_delivery` = '.(int)$id_address_delivery : '')); | |
if (!$this->_deleteCustomization((int)$id_customization, (int)$id_product, (int)$id_product_attribute, (int)$id_address_delivery)) { | |
return false; | |
} | |
// refresh cache of self::_products | |
//$this->_products = $this->getProducts(true); | |
//return ($customization_quantity == $product_total_quantity && $this->deleteProduct((int)$id_product, (int)$id_product_attribute, null, (int)$id_address_delivery)); | |
} | |
/* Get customization quantity */ | |
$result = Db::getInstance()->getRow(' | |
SELECT SUM(`quantity`) AS \'quantity\' | |
FROM `'._DB_PREFIX_.'customization` | |
WHERE `id_cart` = '.(int)$this->id.' | |
AND `id_product` = '.(int)$id_product.' | |
AND `id_customization` = '.(int)$id_customization.' | |
AND `id_product_attribute` = '.(int)$id_product_attribute); | |
if ($result === false) { | |
return false; | |
} | |
/* If the product still possesses customization it does not have to be deleted */ | |
if (Db::getInstance()->NumRows() && (int)$result['quantity']) { | |
return Db::getInstance()->execute( | |
'UPDATE `'._DB_PREFIX_.'cart_product` | |
SET `quantity` = '.(int)$result['quantity'].' | |
WHERE `id_cart` = '.(int)$this->id.' | |
AND `id_product` = '.(int)$id_product.' | |
AND `id_customization` = '.(int)$id_customization. | |
($id_product_attribute != null ? ' AND `id_product_attribute` = '.(int)$id_product_attribute : '') | |
); | |
} | |
/* Product deletion */ | |
$result = Db::getInstance()->execute(' | |
DELETE FROM `'._DB_PREFIX_.'cart_product` | |
WHERE `id_product` = '.(int)$id_product.' | |
AND `id_customization` = '.(int)$id_customization. | |
(!is_null($id_product_attribute) ? ' AND `id_product_attribute` = '.(int)$id_product_attribute : '').' | |
AND `id_cart` = '.(int)$this->id.' | |
'.((int)$id_address_delivery ? 'AND `id_address_delivery` = '.(int)$id_address_delivery : '')); | |
if ($result) { | |
$return = $this->update(); | |
// refresh cache of self::_products | |
$this->_products = $this->getProducts(true); | |
CartRule::autoRemoveFromCart(); | |
CartRule::autoAddToCart(); | |
return $return; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment