Ejemplo n.º 1
0
function aa_item_save()
{
    if (!empty($_POST['aa-item-submitted'])) {
        $item = AA_Item::getSingleItemByID($_POST['item_id']);
        $item->item_title = $_POST['item_title'];
        $item->item_slug = trim(preg_replace('![^a-z0-9]+!', '-', strtolower($item->item_title)), '-');
        $item->item_describition = $_POST['item_desc'];
        $item->item_label = $_POST['item_label'];
        $item->item_manufacturer = $_POST['item_manufacturer'];
        $item->item_publisher = $_POST['item_publisher'];
        $item->item_studio = $_POST['item_studio'];
        $item->item_author = $_POST['item_author'];
        $item->item_price = $_POST['item_price'];
        $item->item_asin = $_POST['item_asin'];
        $item->item_ean = $_POST['item_ean'];
        $item->category_id = $_POST['category'];
        $i = 1;
        if (count($item->features) > 0) {
            foreach ($item->features as $feature_id => $feature) {
                AA_Item::updateFeature($_POST['feature_' . $i], $feature_id, $item->item_id);
                $i++;
            }
            if (count($item->features) < $_POST['countFeature']) {
                for ($i; $i <= $_POST['countFeature']; $i++) {
                    var_dump('feature');
                    AA_Item::addNewFeature($_POST['feature_' . $i], $item->item_id);
                }
            }
        } elseif (count($item->features) == 0 && $_POST['countFeature'] > 0) {
            for ($j = 1; $j < $_POST['countFeature'] + 1; $j++) {
                AA_Item::addNewFeature($_POST['feature_' . $j], $item->item_id);
            }
        }
        if (AA_Item::update($item) == 0) {
            function aa_item_saved_notice()
            {
                ?>
			<div class="updated"><p><strong><?php 
                echo 'Änderungen wurden übernommen';
                ?>
</strong></p></div>

			<?php 
            }
            add_action('admin_notices', 'aa_item_saved_notice');
        } else {
            function aa_item_not_saved_notice()
            {
                ?>
			<div class="updated"><p><strong><?php 
                echo 'Die Änderungen könnten nicht gespeichert werden';
                ?>
</strong></p></div>

			<?php 
            }
            add_action('admin_notices', 'aa_item_not_saved_notice');
        }
    }
}