/** * Shows a bug with opportunity as a product relation. The bug is when there is a default customField value * The fix is the use of isReallyModified() to now determine if during save() if the model has really been modified * If it is a new model, then for example 'name' must not be empty, otherwise it is has not really been modified */ public function testEmptyOpportunityGetsCreatedOnProductEdit() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $name = 'Amazing Kid Sample'; $productTemplateName = ProductsDemoDataMaker::getProductTemplateForProduct($name); $productTemplate = ProductTemplateTestHelper::createProductTemplateByName($productTemplateName); $model = new Product(); $name = 'My Simple Product'; $model->name = $name; $model->quantity = 4; $model->stage->value = 'Open'; $model->priceFrequency = $productTemplate->priceFrequency; $model->sellPrice->value = $productTemplate->sellPrice->value; $model->type = $productTemplate->type; $postData = array(); $postData['opportunity'] = array('id' => ''); $model->setAttributes($postData); $model->validate(); $sanitizedOwnerData = array('owner' => array('id' => $super->id)); $model->setAttributes($sanitizedOwnerData); $model->validate(array('owner')); $this->assertTrue($model->opportunity->id < 0); //need to check this to call get first. $this->assertTrue($model->save(false)); $this->assertTrue($model->save(false)); $this->assertTrue($model->opportunity->id < 0); $model->delete(); $productTemplate->delete(); }
public function post() { $post = Input::all(); $validator = Product::validate($post); $productId = $post['id']; if ($validator->fails()) { return Redirect::to('productos/' . $productId)->withErrors($validator)->withInput(); } else { $product = self::__checkExistence($productId); $isNew = false; if (!$productId) { $product = new Product(); $isNew = true; } $product->name = $post['name']; $product->description = $post['description']; $product->code = $post['code']; $product->minimum_stock = $post['minimum_stock']; $product->cost = str_replace(',', '.', $post['cost']); $product->save(); if ($isNew) { Globals::triggerAlerts(4, array('productId' => $product->id)); } if ($post['status'] == 'inactive') { $product->delete(); } else { if ($product->trashed()) { $product->restore(); } } Session::flash('success', 'Producto guardado correctamente.'); return Redirect::to('productos'); } }
public function deleteProduct($idP, $ref) { $product = new Product($idP); $product->delete(); self::deleteAttributePdt($ref); Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'ec_ecopresto_product_shop` SET `imported`=2 WHERE `reference`="' . pSQL($ref) . '" AND `id_shop`=' . (int) self::getInfoEco('ID_SHOP')); if (Db::getInstance()->execute('SELECT `reference` FROM `' . _DB_PREFIX_ . 'ec_ecopresto_product_deleted` WHERE `reference`="' . pSQL($ref) . '"')) { Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'ec_ecopresto_product_deleted` SET status=1 WHERE `reference`="' . pSQL($ref) . '"'); } }
function delete($id = false) { if ($id) { $product = new Product($id); if ($product->exists()) { $product->delete(); } } $this->session->set_flashdata('top_success', 'Продукт удален'); redirect('admin/products/show'); }
function admin_delete_product($id = null) { if (!$id) { $this->Session->setFlash('Invalid id for a product'); $this->redirect(array('action' => 'admin_show_all_products')); } if ($this->Product->delete($id)) { $this->Session->setFlash('Product was deleted successfully!'); $this->redirect(array('action' => 'admin_show_all_products')); } $this->Session->setFlash('Product was not deleted!'); $this->redirect(array('action' => 'admin_show_all_products')); }
/** * Delete product * * @param int $id Product ID * @return array * * @url DELETE product/{id} */ function delete($id) { if (!DolibarrApiAccess::$user->rights->product->supprimer) { throw new RestException(401); } $result = $this->product->fetch($id); if (!$result) { throw new RestException(404, 'Product not found'); } if (!DolibarrApi::_checkAccessToResource('product', $this->product->id)) { throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); } return $this->product->delete($id); }
function deleteAction() { $this->view->title = "Delete Product"; if ($this->_request->isPost()) { $id = (int) $this->_request->getPost('id'); $del = $this->_request->getPost('del'); if ($del == 'Yes' && $id > 0) { $products = new Product(); $where = 'id=' . $id; $products->delete($where); } $this->_redirect('/'); } else { $id = (int) $this->_request->getParam('id'); if ($id > 0) { $product = new Product(); $this->view->product = $product->fetchRow('id=' . $id); } } }
private function truncateTables($case) { switch ((int) $case) { case $this->entities[$this->l('Categories')]: $categories = Db::getInstance()->ExecuteS('SELECT `id_category` FROM `' . _DB_PREFIX_ . 'category` WHERE id_category != 1'); foreach ($categories as $category) { $c = new Category((int) $category['id_category']); $c->delete(); } break; case $this->entities[$this->l('Products')]: $products = Db::getInstance()->ExecuteS('SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product`'); foreach ($products as $product) { $p = new Product((int) $product['id_product']); $p->delete(true); } break; case $this->entities[$this->l('Customers')]: $customers = Db::getInstance()->ExecuteS('SELECT `id_customer` FROM `' . _DB_PREFIX_ . 'customer`'); foreach ($customers as $customer) { $c = new Customer((int) $customer['id_customer']); $c->delete(); } break; case $this->entities[$this->l('Addresses')]: $addresses = Db::getInstance()->ExecuteS('SELECT `id_address` FROM `' . _DB_PREFIX_ . 'address`'); foreach ($addresses as $address) { $a = new Address((int) $address['id_address']); $a->delete(); } break; case $this->entities[$this->l('Combinations')]: $products = Db::getInstance()->ExecuteS('SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product`'); foreach ($products as $product) { $p = new Product((int) $product['id_product']); $p->deleteProductAttributes(); } break; case $this->entities[$this->l('Manufacturers')]: $manufacturers = Db::getInstance()->ExecuteS('SELECT `id_manufacturer` FROM `' . _DB_PREFIX_ . 'manufacturer`'); foreach ($manufacturers as $manufacturer) { $m = new Manufacturer((int) $manufacturer['id_manufacturer']); $m->delete(); } break; case $this->entities[$this->l('Suppliers')]: $suppliers = Db::getInstance()->ExecuteS('SELECT `id_supplier` FROM `' . _DB_PREFIX_ . 'supplier`'); foreach ($suppliers as $supplier) { $m = new Supplier((int) $supplier['id_supplier']); $m->delete(); } break; } Image::clearTmpDir(); return true; }
function admin() { global $Shopp; $db =& DB::get(); if (!defined('WP_ADMIN') || !isset($_GET['page'])) { return; } $Admin = $Shopp->Flow->Admin; $adminurl = $Shopp->wpadminurl . "admin.php"; $defaults = array('page' => false, 'deleting' => false, 'delete' => false, 'id' => false, 'save' => false, 'duplicate' => false, 'next' => false); $args = array_merge($defaults, $_REQUEST); extract($args, EXTR_SKIP); if (strstr($page, $Admin->categories)) { if ($page == "shopp-categories" && !empty($deleting) && !empty($delete) && is_array($delete)) { foreach ($delete as $deletion) { $Category = new Category($deletion); $db->query("UPDATE {$Category->_table} SET parent=0 WHERE parent={$Category->id}"); $Category->delete(); } $redirect = esc_url(add_query_arg(array_merge($_GET, array('delete[]' => null, 'deleting' => null)), $adminurl)); shopp_redirect($redirect); } if ($id && $id != "new") { $Shopp->Category = new Category($id); } else { $Shopp->Category = new Category(); } if ($save) { $this->save_category($Shopp->Category); $this->Notice = '<strong>' . stripslashes($Shopp->Category->name) . '</strong> ' . __('has been saved.', 'Shopp'); if ($next) { if ($next != "new") { $Shopp->Category = new Category($next); } else { $Shopp->Category = new Category(); } } else { if (empty($id)) { $id = $Shopp->Category->id; } $Shopp->Category = new Category($id); } } } // end $Admin->categories if (strstr($page, $Admin->products)) { if ($page == "shopp-products" && !empty($deleting) && !empty($delete) && is_array($delete)) { foreach ($delete as $deletion) { $Product = new Product($deletion); $Product->delete(); } $redirect = esc_url(add_query_arg(array_merge($_GET, array('delete' => null, 'deleting' => null)), $adminurl)); shopp_redirect($redirect); exit; } if ($duplicate) { $Product = new Product(); $Product->load($duplicate); $Product->duplicate(); shopp_redirect(add_query_arg('page', $Admin->products, $adminurl)); } if ($id && $id != "new") { $Shopp->Product = new Product($id); $Shopp->Product->load_data(array('prices', 'specs', 'categories', 'tags')); } else { $Shopp->Product = new Product(); $Shopp->Product->published = "on"; } if ($save) { $this->save_product($Shopp->Product); $this->Notice = '<strong>' . stripslashes($Shopp->Product->name) . '</strong> ' . __('has been saved.', 'Shopp'); if ($next) { if ($next == "new") { $Shopp->Product = new Product(); $Shopp->Product->published = "on"; } else { $Shopp->Product = new Product($next); $Shopp->Product->load_data(array('prices', 'specs', 'categories', 'tags')); } } else { if (empty($id)) { $id = $Shopp->Product->id; } $Shopp->Product = new Product($id); $Shopp->Product->load_data(array('prices', 'specs', 'categories', 'tags')); } } } // end $Admin->products }
dol_print_error($product->db); } } } /* * Suppression d'un produit/service pas encore affect */ if ($action == 'confirm_delete' && $confirm == 'yes') { $product = new Product($db); $product->fetch($id); if ( ($product->type == 0 && $user->rights->produit->supprimer) || ($product->type == 1 && $user->rights->service->supprimer) ) { $result = $product->delete($id); } if ($result == 0) { Header('Location: '.DOL_URL_ROOT.'/product/liste.php?delprod='.$product->ref); exit; } else { $reload = 0; $action=''; } }
/** * testProductDelete * * @param int $id Id of product * @return void * * @depends testProductOther * The depends says test is run only if previous is ok */ public function testProductDelete($id) { global $conf, $user, $langs, $db; $conf = $this->savconf; $user = $this->savuser; $langs = $this->savlangs; $db = $this->savdb; $localobject = new Product($this->savdb); $result = $localobject->fetch($id); $result = $localobject->delete($id); print __METHOD__ . " id=" . $id . " result=" . $result . "\n"; $this->assertLessThan($result, 0); return $result; }
//var_dump($subs); break; case 'selectProduct': $name = $_GET['name']; $id = $_GET['id']; $proObj = $pro->product($name, $id); if ($proObj) { $result = array("result" => "false"); } else { $result = array("result" => "true"); } echo json_encode($result); //var_dump($proObj); break; case 'editstatus': $id = $_GET['id']; $status = $_GET['status']; //echo "id = ".$id."status = ".$status; $pro->status = $status; $product_id = $pro->updateStatus($id); echo $product_id; $_SESSION['Psuccess'] = "Product add has updated success"; header('location:../controle.php#tabs-5'); //echo " error on update"; break; case 'delete': $id = $_GET['id']; echo $pro->delete($id); header('location:../controle.php#tabs-5'); break; }
<?php require_once "/etc/apache2/capstone-mysql/encrypted-config.php"; require_once "product.php"; $pdo = connectToEncryptedMySQL("/etc/apache2/data-design/jfindley2.ini"); $product = new Product(null, "imagefile", 10, "Info", "Detail", "Tech", "Name"); $product->insert($pdo); $product->setProductName("This is the new name"); $product->update($pdo); $product->delete($pdo);
public function postProcess($token = NULL) { global $currentIndex; /* Add a new product */ if (Tools::isSubmit('submitAddproduct') or Tools::isSubmit('submitAddproductAndStay')) { if ($this->tabAccess['add'] === '1') { $this->submitAddproduct($token); } elseif (Tools::getValue('id_product') and $this->tabAccess['edit'] === '1') { $this->submitAddproduct($token); } else { $this->_errors[] = Tools::displayError('You do not have permission to add anything here.'); } } /* Delete a product in the download folder */ if (Tools::getValue('deleteVirtualProduct')) { if ($this->tabAccess['delete'] === '1') { $this->deleteVirtualProduct(); } else { $this->_errors[] = Tools::displayError('You do not have permission to delete anything here.'); } } elseif (Tools::isSubmit('submitAttachments')) { if ($this->tabAccess['edit'] === '1') { if ($id = intval(Tools::getValue($this->identifier))) { if (Attachment::attachToProduct($id, $_POST['attachments'])) { Tools::redirectAdmin($currentIndex . '&id_product=' . $id . '&conf=4&add' . $this->table . '&tabs=6&token=' . ($token ? $token : $this->token)); } } } } elseif (isset($_GET['duplicate' . $this->table])) { if ($this->tabAccess['add'] === '1') { if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) { $id_product_old = $product->id; unset($product->id); unset($product->id_product); $product->indexed = 0; if ($product->add() and Category::duplicateProductCategories($id_product_old, $product->id) and ($combinationImages = Product::duplicateAttributes($id_product_old, $product->id)) !== false and Product::duplicateAccessories($id_product_old, $product->id) and Product::duplicateFeatures($id_product_old, $product->id) and Product::duplicateQuantityDiscount($id_product_old, $product->id) and Pack::duplicate($id_product_old, $product->id) and Product::duplicateCustomizationFields($id_product_old, $product->id) and Product::duplicateTags($id_product_old, $product->id)) { if (!Tools::getValue('noimage') and !Image::duplicateProductImages($id_product_old, $product->id, $combinationImages)) { $this->_errors[] = Tools::displayError('an error occurred while copying images'); } else { Hook::addProduct($product); Search::indexation(false); Tools::redirectAdmin($currentIndex . '&id_category=' . intval(Tools::getValue('id_category')) . '&conf=19&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('an error occurred while creating object'); } } } else { $this->_errors[] = Tools::displayError('You do not have permission to add anything here.'); } } elseif ($id_image = intval(Tools::getValue('id_image')) and Validate::isUnsignedId($id_image) and Validate::isLoadedObject($image = new Image($id_image))) { if ($this->tabAccess['edit'] === '1') { /* Delete product image */ if (isset($_GET['deleteImage'])) { $image->delete(); deleteImage($image->id_product, $image->id); if (!Image::getCover($image->id_product)) { $first_img = Db::getInstance()->getRow(' SELECT `id_image` FROM `' . _DB_PREFIX_ . 'image` WHERE `id_product` = ' . intval($image->id_product)); Db::getInstance()->Execute(' UPDATE `' . _DB_PREFIX_ . 'image` SET `cover` = 1 WHERE `id_image` = ' . intval($first_img['id_image'])); } @unlink(dirname(__FILE__) . '/../../img/tmp/product_' . $image->id_product . '.jpg'); @unlink(dirname(__FILE__) . '/../../img/tmp/product_mini_' . $image->id_product . '.jpg'); Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=1' . '&token=' . ($token ? $token : $this->token)); } elseif (isset($_GET['editImage'])) { if ($image->cover) { $_POST['cover'] = 1; } $languages = Language::getLanguages(); foreach ($languages as $language) { if (isset($image->legend[$language['id_lang']])) { $_POST['legend_' . $language['id_lang']] = $image->legend[$language['id_lang']]; } } $_POST['id_image'] = $image->id; $this->displayForm($token ? $token : $this->token); } elseif (isset($_GET['coverImage'])) { Image::deleteCover($image->id_product); $image->cover = 1; if (!$image->update()) { $this->_errors[] = Tools::displayError('Impossible to change the product cover'); } else { $productId = intval(Tools::getValue('id_product')); @unlink(dirname(__FILE__) . '/../../img/tmp/product_' . $productId . '.jpg'); @unlink(dirname(__FILE__) . '/../../img/tmp/product_mini_' . $productId . '.jpg'); Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . intval(Tools::getValue('id_category')) . '&addproduct&tabs=1' . '&token=' . ($token ? $token : $this->token)); } } elseif (isset($_GET['imgPosition']) and isset($_GET['imgDirection'])) { $image->positionImage(intval(Tools::getValue('imgPosition')), intval(Tools::getValue('imgDirection'))); Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=1&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.'); } } elseif (Tools::isSubmit('submitProductAttribute')) { if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) { if (!isset($_POST['attribute_quantity']) or $_POST['attribute_quantity'] == NULL) { $this->_errors[] = Tools::displayError('attribute quantity is required'); } if (!isset($_POST['attribute_price']) or $_POST['attribute_price'] == NULL) { $this->_errors[] = Tools::displayError('attribute price is required'); } if (!isset($_POST['attribute_combinaison_list']) or !sizeof($_POST['attribute_combinaison_list'])) { $this->_errors[] = Tools::displayError('you must add at least one attribute'); } if (!sizeof($this->_errors)) { if (!isset($_POST['attribute_wholesale_price'])) { $_POST['attribute_wholesale_price'] = 0; } if (!isset($_POST['attribute_price_impact'])) { $_POST['attribute_price_impact'] = 0; } if (!isset($_POST['attribute_weight_impact'])) { $_POST['attribute_weight_impact'] = 0; } if (!isset($_POST['attribute_ecotax'])) { $_POST['attribute_ecotax'] = 0; } if (Tools::getValue('attribute_default')) { $product->deleteDefaultAttributes(); } // Change existing one if ($id_product_attribute = intval(Tools::getValue('id_product_attribute'))) { if ($this->tabAccess['edit'] === '1') { if ($product->productAttributeExists($_POST['attribute_combinaison_list'], $id_product_attribute)) { $this->_errors[] = Tools::displayError('This attribute already exists.'); } else { $product->updateProductAttribute($id_product_attribute, Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_ecotax'), Tools::getValue('attribute_quantity'), Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_supplier_reference'), Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location')); } } else { $this->_errors[] = Tools::displayError('You do not have permission to add anything here.'); } } else { if ($this->tabAccess['add'] === '1') { if ($product->productAttributeExists($_POST['attribute_combinaison_list'])) { $this->_errors[] = Tools::displayError('This combination already exists.'); } else { $id_product_attribute = $product->addCombinationEntity(Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_ecotax'), Tools::getValue('attribute_quantity'), Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_supplier_reference'), Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location')); } } else { $this->_errors[] = Tools::displayError('You do not have permission to') . '<hr>' . Tools::displayError('edit something here.'); } } if (!sizeof($this->_errors)) { $product->addAttributeCombinaison($id_product_attribute, Tools::getValue('attribute_combinaison_list')); $product->checkDefaultAttributes(); } if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=2&token=' . ($token ? $token : $this->token)); } } } } elseif (isset($_GET['deleteProductAttribute'])) { if ($this->tabAccess['delete'] === '1') { if ($id_product = intval(Tools::getValue('id_product')) and Validate::isUnsignedId($id_product) and Validate::isLoadedObject($product = new Product($id_product))) { $product->deleteAttributeCombinaison(intval(Tools::getValue('id_product_attribute'))); $product->checkDefaultAttributes(); Tools::redirectAdmin($currentIndex . '&add' . $this->table . '&id_category=' . intval(Tools::getValue('id_category')) . '&tabs=2&id_product=' . $product->id . '&token=' . ($token ? $token : $this->token)); } else { $this->_errors[] = Tools::displayError('impossible to delete attribute'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } elseif (Tools::isSubmit('submitProductFeature')) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) { // delete all objects $product->deleteFeatures(); // add new objects $languages = Language::getLanguages(); foreach ($_POST as $key => $val) { if (preg_match("/^feature_([0-9]+)_value/i", $key, $match)) { if ($val) { $product->addFeaturesToDB($match[1], $val); } else { if ($default_value = $this->checkFeatures($languages, $match[1])) { $id_value = $product->addFeaturesToDB($match[1], 0, 1, $language['id_lang']); foreach ($languages as $language) { if ($cust = Tools::getValue('custom_' . $match[1] . '_' . $language['id_lang'])) { $product->addFeaturesCustomToDB($id_value, $language['id_lang'], $cust); } else { $product->addFeaturesCustomToDB($id_value, $language['id_lang'], $default_value); } } } } } } if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=3&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('product must be created before adding features'); } } $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.'); } elseif (Tools::isSubmit('submitQuantityDiscount')) { $_POST['tabs'] = 5; if ($this->tabAccess['add'] === '1') { if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) { if (!($id_discount_type = intval(Tools::getValue('id_discount_type')))) { $this->_errors[] = Tools::displayError('discount type not selected'); } else { if (!($quantity_discount = intval(Tools::getValue('quantity_discount')))) { $this->_errors[] = Tools::displayError('quantity is required'); } else { if (!($value_discount = floatval(Tools::getValue('value_discount')))) { $this->_errors[] = Tools::displayError('value is required'); } else { $qD = new QuantityDiscount(); $qD->id_product = $product->id; $qD->id_discount_type = $id_discount_type; $qD->quantity = $quantity_discount; $qD->value = $value_discount; if ($qD->add() and !sizeof($this->_errors) and $qD->validateFields()) { Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=5&conf=3&token=' . ($token ? $token : $this->token)); } $this->_errors[] = Tools::displayError('an error occurred while creating object'); } } } } else { $this->_errors[] = Tools::displayError('product must be created before adding quantity discounts'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to add anything here.'); } } elseif (isset($_GET['deleteQuantityDiscount'])) { if ($this->tabAccess['delete'] === '1') { if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) { if (Validate::isLoadedObject($qD = new QuantityDiscount(intval(Tools::getValue('id_quantity_discount'))))) { $qD->delete(); if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=5&conf=1&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('not a valid quantity discount'); } } else { $this->_errors[] = Tools::displayError('product must be created before delete quantity discounts'); } $qD = new QuantityDiscount(); } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } elseif (Tools::isSubmit('submitCustomizationConfiguration')) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) { if (!$product->createLabels(intval($_POST['uploadable_files']) - intval($product->uploadable_files), intval($_POST['text_fields']) - intval($product->text_fields))) { $this->_errors[] = Tools::displayError('an error occured while creating customization fields'); } if (!sizeof($this->_errors) and !$product->updateLabels()) { $this->_errors[] = Tools::displayError('an error occured while updating customization'); } $product->uploadable_files = intval($_POST['uploadable_files']); $product->text_fields = intval($_POST['text_fields']); $product->customizable = (intval($_POST['uploadable_files']) > 0 or intval($_POST['text_fields']) > 0) ? 1 : 0; if (!sizeof($this->_errors) and !$product->update()) { $this->_errors[] = Tools::displayError('an error occured while updating customization configuration'); } if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=4&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('product must be created before adding customization possibilities'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.'); } } elseif (Tools::isSubmit('submitProductCustomization')) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) { foreach ($_POST as $field => $value) { if (strncmp($field, 'label_', 6) == 0 and !Validate::isLabel($value)) { $this->_errors[] = Tools::displayError('label fields are invalid'); } } if (!sizeof($this->_errors) and !$product->updateLabels()) { $this->_errors[] = Tools::displayError('an error occured while updating customization'); } if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=4&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('product must be created before adding customization possibilities'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.'); } } elseif (isset($_GET['delete' . $this->table])) { if ($this->tabAccess['delete'] === '1') { if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) { if (!$this->deleteImage($product->id)) { $this->_errors[] = Tools::displayError('an error occurred during product image deletion'); } if ($product->delete()) { Tools::redirectAdmin($currentIndex . '&id_category=' . intval(Tools::getValue('id_category')) . '&conf=1&token=' . ($token ? $token : $this->token)); } $this->_errors[] = Tools::displayError('an error occurred during product deletion'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } else { parent::postProcess(true); } }
include 'layout/_header.php'; if (!empty($_GET['productId'])) { include_once 'tools.php'; $prodObj = new Product(); $product = $prodObj->findById($connect, $_GET['productId']); if (!empty($product)) { ?> <h4> Are you sure want to delete this product?</h4> <form action='' method=post> <input type="hidden" name="id" id="id" value="<?php echo empty($product) ? '' : $product->id; ?> "/> <input class="button button-yes" type=submit name='btnYes' value='Yes'> <input class="button button-no" type=submit name='btnNo' value='No'> </form> <?php } if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_POST['btnYes'])) { $prodObj->delete($_POST['id'], $connect); } header("Location: /"); return; } $connect->close(); } else { echo '<h4>Error: No product to delete</h4>'; } include 'layout/_footer.php';
public function deleteSelection($products) { $return = 1; foreach ($products as $id_product) { $product = new Product((int) $id_product); $return &= $product->delete(); } return $return; }
<?php if (!empty($_GET['delete'])) { $id = (int) $_GET['delete']; Product::delete($id); } $products = Product::getAll(); ?> <form method="post" action="?page=edit"> <input type="submit" name="newpost" class="button" value="New Post" /> </form> <table class="product-table"> <thead> <tr> <th>Title</th> <th>Art. Number</th> <th>Delete</th> </tr> </thead> <tbody> <?php foreach ($products as $product) { ?> <tr> <td><a href="?page=edit&post=<?php print $product['id']; ?> "><?php print $product['title']; ?>
public function deleteSelection($products) { $return = 1; if (is_array($products) && ($count = count($products))) { // Deleting products can be quite long on a cheap server. Let's say 1.5 seconds by product (I've seen it!). if (intval(ini_get('max_execution_time')) < round($count * 1.5)) { ini_set('max_execution_time', round($count * 1.5)); } foreach ($products as $id_product) { $product = new Product((int) $id_product); $return &= $product->delete(); } } return $return; }
<?php #1. Auth::kickout_non_admin('/pokecart/'); $product = new Product(); $product->load(Route::param('id')); $product->delete(); #2. REDIRECT URL::redirect('/pokecart/admin');
/** * Deletes a product from the database. * * @param int $id id of the product to delete */ public static function delete($id) { $product = new Product(array('id' => $id)); $product->delete(); Redirect::to($_POST['redirect'], array('message' => 'Tuote poistettu!')); }
require_once "DataBase/Price.php"; $db_action = var_get_post("db_action", ""); $product = new Product(); $tax = new Tax(); $category = new Category(); $priceset = new Priceset(); $price = new Price(); $group = new Group(); switch ($db_action) { case "new": $product->create(var_post("product_id", ""), array(var_post("name", ""), var_post("details", ""), var_post("category_id", ""), var_post("tax_id", ""), var_post("available", ""), var_post("group_id", ""), var_post("order_number", ""), var_post("anmerkung", ""))); $priceset_list = $priceset->get(); for ($i = 0; $i < count($priceset_list); $i++) { $price->create(var_post("priceset_id_" . $i, ""), var_post("product_id", ""), array(var_post("priceset_price_" . $i, ""))); } break; case "edit": $product->update(var_post("product_id", ""), array(var_post("name", ""), var_post("details", ""), var_post("category_id", ""), var_post("tax_id", ""), var_post("available", ""), var_post("group_id", ""), var_post("order_number", ""), var_post("anmerkung", ""))); $priceset_list = $priceset->get(); for ($i = 0; $i < count($priceset_list); $i++) { if ($price->exists(var_post("priceset_id_" . $i, ""), var_post("product_id", ""))) { $price->update(var_post("priceset_id_" . $i, ""), var_post("product_id", ""), array(var_post("priceset_price_" . $i, ""))); } else { $price->create(var_post("priceset_id_" . $i, ""), var_post("product_id", ""), array(var_post("priceset_price_" . $i, ""))); } } break; case "delete": $product->delete(var_get("product_id", "")); break; }
<?php session_start(); require "../includes/checkPermission.php"; require "../../deny/connector.php"; require "class/class.Product.php"; require "../includes/injection.php"; $_SESSION['DELETEPRODUCT'] = ""; $productid = sqlInjection($_GET['pID']); $str = "select cd_id from tblorderdetail where cd_id={$productid} "; $result = mysql_query($str); if (mysql_num_rows($result) > 0) { $_SESSION['DELETEPRODUCT'] = "Không thể xóa sản phẩm này vì đang có đơn đặt hàng"; } else { $productid = intval($productid); $prod = new Product(); $prod->delete($productid); $_SESSION['DELETEPRODUCT'] = ""; } //echo $cateid."<br>".$str."<br>"; echo "<meta http-equiv='refresh' content='0;url=../admincp.php?opt=listproduct'>"; //header("location: ../admincp.php?opt=listproduct"); //exit();
function testDelete() { $product = new Product(); $product->name = 'CD'; $product->save(); $product->delete(); $this->assertFalse(SActiveStore::findByPk('Product', $product->id)); }
function recycle($id) { $arr = $this->input->post('checkinput'); foreach ($arr as $row) { $o = new Product($row); $o->delete(); $o->clear(); } flash_message('success', "Tất cả các đối tượng đã được xóa thành công."); redirect($_SERVER['HTTP_REFERER']); }
// check if value was posted if ($_POST) { // include classes include_once '../config/database.php'; include_once '../objects/product.php'; include_once '../objects/product_image.php'; include_once '../objects/product_pdf.php'; // get database connection $database = new Database(); $db = $database->getConnection(); // initialize objects $product = new Product($db); $productImage = new ProductImage($db); $productPdf = new ProductPdf($db); // set product id to be deleted $product_id = $_POST['object_id']; // delete the product $product->id = $product_id; if ($product->delete()) { // delete all related images in database & directory $productImage->product_id = $product_id; $productImage->deleteAll(); // delete all related pdf in database & directory $productPdf->product_id = $product_id; $productPdf->deleteAll(); echo "Object was deleted."; } else { echo "Unable to delete object."; } }
function index_delete() { $models = json_decode($this->delete('models')); foreach ($models as $key => $value) { $obj = new Product(null, $this->entity); $obj->where("id", $value->id)->get(); $data["results"][] = array("data" => $value, "status" => $obj->delete()); } //Response data $this->response($data, 200); }
protected function processBulkDelete() { if ($this->tabAccess['delete'] === '1') { if (is_array($this->boxes) && !empty($this->boxes)) { $object = new $this->className(); if (isset($object->noZeroObject) && (count(call_user_func(array($this->className, $object->noZeroObject))) <= 1 || count($_POST[$this->table . 'Box']) == count(call_user_func(array($this->className, $object->noZeroObject))))) { $this->errors[] = Tools::displayError('You need at least one object.') . ' <b>' . $this->table . '</b><br />' . Tools::displayError('You cannot delete all of the items.'); } else { $success = 1; $products = Tools::getValue($this->table . 'Box'); if (is_array($products) && ($count = count($products))) { // Deleting products can be quite long on a cheap server. Let's say 1.5 seconds by product (I've seen it!). if (intval(ini_get('max_execution_time')) < round($count * 1.5)) { ini_set('max_execution_time', round($count * 1.5)); } if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { $stock_manager = StockManagerFactory::getManager(); } foreach ($products as $id_product) { $product = new Product((int) $id_product); /* * @since 1.5.0 * It is NOT possible to delete a product if there are currently: * - physical stock for this product * - supply order(s) for this product */ if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management) { $physical_quantity = $stock_manager->getProductPhysicalQuantities($product->id, 0); $real_quantity = $stock_manager->getProductRealQuantities($product->id, 0); if ($physical_quantity > 0 || $real_quantity > $physical_quantity) { $this->errors[] = sprintf(Tools::displayError('You cannot delete the product #%d because there is physical stock left.'), $product->id); } } if (!count($this->errors)) { if ($product->delete()) { PrestaShopLogger::addLog(sprintf($this->l('%s deletion', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int) $product->id, true, (int) $this->context->employee->id); } else { $success = false; } } else { $success = 0; } } } if ($success) { $id_category = (int) Tools::getValue('id_category'); $category_url = empty($id_category) ? '' : '&id_category=' . (int) $id_category; $this->redirect_after = self::$currentIndex . '&conf=2&token=' . $this->token . $category_url; } else { $this->errors[] = Tools::displayError('An error occurred while deleting this selection.'); } } } else { $this->errors[] = Tools::displayError('You must select at least one element to delete.'); } } else { $this->errors[] = Tools::displayError('You do not have permission to delete this.'); } }
@unlink(THUMB_UPLOAD_DIR . $theProduct['image']); } //update $product->update($_POST, (int) $param); $theProduct = $product->find((int) $param); } else { //insert $product->insert($_POST); Redirect::to(BASE_URL . 'products/'); } } else { $theProduct = $_POST; } } //$template = 'products_edit'; break; case 'delete': if (isset($param) && !empty($param)) { $p = $product->find((int) $param); $product->delete((int) $param); if ($p['image']) { @unlink(FOTO_UPLOAD_DIR . $p['image']); @unlink(THUMB_UPLOAD_DIR . $p['image']); } Redirect::to(BASE_URL . 'products/'); } break; } } else { Redirect::to(BASE_URL . 'login'); }
/** * Delete a product or service * * @param array $authentication Array of authentication information * @param string $listofidstring List of id with comma * @return array Array result */ function deleteProductOrService($authentication, $listofidstring) { global $db, $conf, $langs; $now = dol_now(); dol_syslog("Function: deleteProductOrService login="******"List of Id of products or services to delete are required."; } if (!$error) { $firsterror = ''; $db->begin(); foreach ($listofid as $key => $id) { $newobject = new Product($db); $result = $newobject->fetch($id); if ($result == 0) { $error++; $firsterror = 'Product or service with id ' . $id . ' not found'; break; } else { $result = $newobject->delete(); if ($result <= 0) { $error++; $firsterror = $newobject->error; break; } $listofiddeleted[] = $id; } } if (!$error) { $db->commit(); //$objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'listofid'=>$listofiddeleted); $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'nbdeleted' => count($listofiddeleted)); } else { $db->rollback(); $error++; $errorcode = 'KO'; $errorlabel = $firsterror; } } if ($error) { //$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel), 'listofid'=>$listofiddeleted); $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel), 'nbdeleted' => 0); } else { if (count($listofiddeleted) == 0) { //$objectresp=array('result'=>array('result_code'=>'NOT_FOUND', 'result_label'=>'No product or service with id '.join(',',$listofid).' found'), 'listofid'=>$listofiddeleted); $objectresp = array('result' => array('result_code' => 'NOT_FOUND', 'result_label' => 'No product or service with id ' . join(',', $listofid) . ' found'), 'nbdeleted' => 0); } } return $objectresp; }
/** * Handles loading, saving and deleting products in the context of workflows * * @return void **/ function workflow () { global $Ecart; $db =& DB::get(); $defaults = array( 'page' => false, 'deleting' => false, 'delete' => false, 'id' => false, 'save' => false, 'duplicate' => false, 'next' => false ); $args = array_merge($defaults,$_REQUEST); extract($args,EXTR_SKIP); if (!defined('WP_ADMIN') || !isset($page) || $page != $this->Admin->pagename('products')) return false; $adminurl = admin_url('admin.php'); if ($page == $this->Admin->pagename('products') && !empty($deleting) && !empty($delete) && is_array($delete)) { foreach($delete as $deletion) { $Product = new Product($deletion); $Product->delete(); } $redirect = esc_url(add_query_arg(array_merge($_GET,array('delete'=>null,'deleting'=>null)),$adminurl)); ecart_redirect($redirect); } if ($duplicate) { $Product = new Product($duplicate); $Product->duplicate(); ecart_redirect(add_query_arg('page',$this->Admin->pagename('products'),$adminurl)); } if (isset($id) && $id != "new") { $Ecart->Product = new Product($id); $Ecart->Product->load_data(array('prices','specs','categories','tags')); } else { $Ecart->Product = new Product(); $Ecart->Product->status = "publish"; } if ($save) { $this->save_product($Ecart->Product); $this->Notice = '<strong>'.stripslashes($Ecart->Product->name).'</strong> '.__('has been saved.','Ecart'); if ($next) { if ($next == "new") { $Ecart->Product = new Product(); $Ecart->Product->status = "publish"; } else { $Ecart->Product = new Product($next); $Ecart->Product->load_data(array('prices','specs','categories','tags')); } } else { if (empty($id)) $id = $Ecart->Product->id; $Ecart->Product = new Product($id); $Ecart->Product->load_data(array('prices','specs','categories','tags')); } } }