Skip to content
Browse files

Merge pull request #285 from hkulekci/newfeature

Option Values Deleting Automatically for #284
  • Loading branch information...
2 parents 2332ed1 + 03fd3fa commit 7ba1837c93645994063a6df67638924d86b0c672 @danielkerr danielkerr committed
Showing with 6 additions and 2 deletions.
  1. +6 −2 upload/admin/model/catalog/product.php
View
8 upload/admin/model/catalog/product.php
@@ -38,10 +38,12 @@ public function addProduct($data) {
$product_option_id = $this->db->getLastId();
- if (isset($product_option['product_option_value'])) {
+ if (isset($product_option['product_option_value']) && count($product_option['product_option_value']) > 0 ) {
foreach ($product_option['product_option_value'] as $product_option_value) {
$this->db->query("INSERT INTO " . DB_PREFIX . "product_option_value SET product_option_id = '" . (int)$product_option_id . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', option_value_id = '" . (int)$product_option_value['option_value_id'] . "', quantity = '" . (int)$product_option_value['quantity'] . "', subtract = '" . (int)$product_option_value['subtract'] . "', price = '" . (float)$product_option_value['price'] . "', price_prefix = '" . $this->db->escape($product_option_value['price_prefix']) . "', points = '" . (int)$product_option_value['points'] . "', points_prefix = '" . $this->db->escape($product_option_value['points_prefix']) . "', weight = '" . (float)$product_option_value['weight'] . "', weight_prefix = '" . $this->db->escape($product_option_value['weight_prefix']) . "'");
}
+ }else{
+ $this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_option_id = '".$product_option_id."'");
}
} else {
$this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', option_value = '" . $this->db->escape($product_option['option_value']) . "', required = '" . (int)$product_option['required'] . "'");
@@ -160,10 +162,12 @@ public function editProduct($product_id, $data) {
$product_option_id = $this->db->getLastId();
- if (isset($product_option['product_option_value'])) {
+ if (isset($product_option['product_option_value']) && count($product_option['product_option_value']) > 0 ) {
foreach ($product_option['product_option_value'] as $product_option_value) {
$this->db->query("INSERT INTO " . DB_PREFIX . "product_option_value SET product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "', product_option_id = '" . (int)$product_option_id . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', option_value_id = '" . (int)$product_option_value['option_value_id'] . "', quantity = '" . (int)$product_option_value['quantity'] . "', subtract = '" . (int)$product_option_value['subtract'] . "', price = '" . (float)$product_option_value['price'] . "', price_prefix = '" . $this->db->escape($product_option_value['price_prefix']) . "', points = '" . (int)$product_option_value['points'] . "', points_prefix = '" . $this->db->escape($product_option_value['points_prefix']) . "', weight = '" . (float)$product_option_value['weight'] . "', weight_prefix = '" . $this->db->escape($product_option_value['weight_prefix']) . "'");
}
+ }else{
+ $this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_option_id = '".$product_option_id."'");
}
} else {
$this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_option_id = '" . (int)$product_option['product_option_id'] . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', option_value = '" . $this->db->escape($product_option['option_value']) . "', required = '" . (int)$product_option['required'] . "'");

0 comments on commit 7ba1837

Please sign in to comment.
Something went wrong with that request. Please try again.