本文整理汇总了PHP中Products::deleteByShopCategory方法的典型用法代码示例。如果您正苦于以下问题:PHP Products::deleteByShopCategory方法的具体用法?PHP Products::deleteByShopCategory怎么用?PHP Products::deleteByShopCategory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Products
的用法示例。
在下文中一共展示了Products::deleteByShopCategory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delete
/**
* Deletes this ShopCategory from the database.
*
* Also removes associated subcategories and Products.
* Images will only be erased from the disc if the optional
* $flagDeleteImages parameter evaluates to true.
* @return boolean True on success, false otherwise
* @global ADONewConnection $objDatabase Database connection object
* @author Reto Kohli <reto.kohli@comvation.com>
*/
function delete($flagDeleteImages = false)
{
global $objDatabase;
// Delete Products and images
if (Products::deleteByShopCategory($this->id, $flagDeleteImages) === false) {
return false;
}
// Delete subcategories
foreach ($this->getChildCategories() as $subCategory) {
if (!$subCategory->delete($flagDeleteImages)) {
return false;
}
}
// TEST: Delete pictures, if requested
if ($flagDeleteImages) {
\File::delete_file($this->picture());
}
// Delete Text
\Text::deleteById($this->id(), 'Shop', self::TEXT_NAME);
\Text::deleteById($this->id(), 'Shop', self::TEXT_DESCRIPTION);
// Delete Category
$objResult = $objDatabase->Execute("\n DELETE FROM " . DBPREFIX . "module_shop" . MODULE_INDEX . "_categories\n WHERE id={$this->id}");
if (!$objResult) {
return false;
}
$objDatabase->Execute("\n OPTIMIZE TABLE " . DBPREFIX . "module_shop" . MODULE_INDEX . "_categories");
return true;
}
示例2: delete_categories
/**
* Deletes one or more ShopCategories
*
* Only succeeds if there are no subcategories, and if all contained
* Products can be deleted as well. Products that are present in any
* order won't be deleted.
* @param integer $category_id The optional ShopCategory ID.
* If this is no valid ID, it is taken
* from the request parameters
* $_GET['delete_category_id'], or
* $_POST['selectedCatId'], in this
* order.
* @return boolean True on success, null on noop,
* false otherwise.
*/
function delete_categories($category_id = 0)
{
global $objDatabase, $_ARRAYLANG;
$arrCategoryId = array();
$deleted = false;
if (empty($category_id)) {
if (!empty($_GET['delete_category_id'])) {
array_push($arrCategoryId, $_GET['delete_category_id']);
} elseif (!empty($_POST['selected_category_id']) && is_array($_POST['selected_category_id'])) {
$arrCategoryId = $_POST['selected_category_id'];
}
} else {
array_push($arrCategoryId, $category_id);
}
if (empty($arrCategoryId)) {
return null;
}
// When multiple IDs are posted, the list must be reversed,
// so subcategories are removed first
$arrCategoryId = array_reverse($arrCategoryId);
//DBG::log("delete_categories($category_id): Got ".var_export($arrCategoryId, true));
foreach ($arrCategoryId as $category_id) {
// Check whether this category has subcategories
$arrChildId = ShopCategories::getChildCategoryIdArray($category_id, false);
//DBG::log("delete_categories($category_id): Children of $category_id: ".var_export($arrChildId, true));
if (count($arrChildId)) {
\Message::warning($_ARRAYLANG['TXT_CATEGORY_NOT_DELETED_BECAUSE_IN_USE'] . " (" . $_ARRAYLANG['TXT_CATEGORY'] . " " . $category_id . ")");
continue;
}
// Get Products in this category
$count = 1000000000.0;
$arrProducts = Products::getByShopParams($count, 0, null, $category_id, null, null, false, false, '', null, true);
//DBG::log("delete_categories($category_id): Products in $category_id: ".var_export($arrProducts, true));
// Delete the products in the category
foreach ($arrProducts as $objProduct) {
// Check whether there are orders with this Product ID
$product_id = $objProduct->id();
$query = "\n SELECT 1\n FROM " . DBPREFIX . "module_shop" . MODULE_INDEX . "_order_items\n WHERE product_id={$product_id}";
$objResult = $objDatabase->Execute($query);
if (!$objResult || $objResult->RecordCount()) {
\Message::error($_ARRAYLANG['TXT_COULD_NOT_DELETE_ALL_PRODUCTS'] . " (" . sprintf($_ARRAYLANG['TXT_SHOP_CATEGORY_ID_FORMAT'], $category_id) . ")");
continue 2;
}
}
if (Products::deleteByShopCategory($category_id) === false) {
\Message::error($_ARRAYLANG['TXT_ERROR_DELETING_PRODUCT'] . " (" . $_ARRAYLANG['TXT_CATEGORY'] . " " . $category_id . ")");
continue;
}
// Delete the Category now
$result = ShopCategories::deleteById($category_id);
if ($result === null) {
continue;
}
if ($result === false) {
return self::error_database();
}
$deleted = true;
}
if ($deleted) {
$objDatabase->Execute("OPTIMIZE TABLE " . DBPREFIX . "module_shop" . MODULE_INDEX . "_categories");
$objDatabase->Execute("OPTIMIZE TABLE " . DBPREFIX . "module_shop" . MODULE_INDEX . "_products");
return \Message::ok($_ARRAYLANG['TXT_DELETED_CATEGORY_AND_PRODUCTS']);
}
return null;
}