/** * Handles saving updated category information from the category editor * * @since 1.0 * @return void **/ function save ($Category) { global $Ecart; $Settings = &EcartSettings(); $db = DB::get(); check_admin_referer('ecart-save-category'); if ( !(is_ecart_userlevel() || current_user_can('ecart_categories')) ) wp_die(__('You do not have sufficient permissions to access this page.')); $Settings->saveform(); // Save workflow setting $Ecart->Catalog = new Catalog(); $Ecart->Catalog->load_categories(array( 'columns' => "cat.id,cat.parent,cat.name,cat.description,cat.uri,cat.slug", 'where' => array(), 'joins' => array(), 'orderby' => false, 'order' => false, 'outofstock' => true )); $Category->update_slug(); if (!empty($_POST['deleteImages'])) { $deletes = array(); if (strpos($_POST['deleteImages'],",")) $deletes = explode(',',$_POST['deleteImages']); else $deletes = array($_POST['deleteImages']); $Category->delete_images($deletes); } // Variation price templates if (!empty($_POST['price']) && is_array($_POST['price'])) { foreach ($_POST['price'] as &$pricing) { $pricing['price'] = floatvalue($pricing['price'],false); $pricing['saleprice'] = floatvalue($pricing['saleprice'],false); $pricing['shipfee'] = floatvalue($pricing['shipfee'],false); } $Category->prices = stripslashes_deep($_POST['price']); } else $Category->prices = array(); if (empty($_POST['specs'])) $Category->specs = array(); else $_POST['specs'] = stripslashes_deep($_POST['specs']); if (empty($_POST['options']) || (count($_POST['options']['v'])) == 1 && !isset($_POST['options']['v'][1]['options'])) { $_POST['options'] = $Category->options = array(); $_POST['prices'] = $Category->prices = array(); } else $_POST['options'] = stripslashes_deep($_POST['options']); if (isset($_POST['content'])) $_POST['description'] = $_POST['content']; $Category->updates($_POST); $Category->save(); if (!empty($_POST['images']) && is_array($_POST['images'])) { $Category->link_images($_POST['images']); $Category->save_imageorder($_POST['images']); if (!empty($_POST['imagedetails']) && is_array($_POST['imagedetails'])) { foreach($_POST['imagedetails'] as $i => $data) { $Image = new CategoryImage($data['id']); $Image->title = $data['title']; $Image->alt = $data['alt']; $Image->save(); } } } do_action_ref_array('ecart_category_saved',array(&$Category)); $updated = '<strong>'.$Category->name.'</strong> '.__('category saved.','Ecart'); }
/** * shopp_rmv_image * * remove an image record from the database * * @api * @since 1.2 * * @param int $image the image id * @param string $context the object type the image asset is attached to. This can be product or category * @return mixed false on failure, int image asset id on success. **/ function shopp_rmv_image($image, $context) { if (empty($image) || empty($context)) { shopp_debug(__FUNCTION__ . " failed: Missing parameters"); return false; } if ('product' == $context) { $Image = new ProductImage($image); } else { if ('category' == $context) { $Image = new CategoryImage($image); } else { shopp_debug(__FUNCTION__ . " failed: Invalid context {$context}."); return false; } } if (empty($Image->id)) { shopp_debug(__FUNCTION__ . " failed: No such {$context} image with id {$image}"); return false; } return $Image->delete(); }
/** * Handles saving updated category information from the category editor * * @author Jonathan Davis * @since 1.0 * @return void **/ public function save($Category) { $Shopp = Shopp::object(); check_admin_referer('shopp-save-category'); if (!current_user_can('shopp_categories')) { wp_die(__('You do not have sufficient permissions to access this page.')); } shopp_set_formsettings(); // Save workflow setting if (empty($Category->meta)) { $Category->load_meta(); } if (isset($_POST['content'])) { $_POST['description'] = $_POST['content']; } $Category->name = $_POST['name']; $Category->description = $_POST['description']; $Category->parent = $_POST['parent']; $Category->prices = array(); // Variation price templates if (!empty($_POST['price']) && is_array($_POST['price'])) { foreach ($_POST['price'] as &$pricing) { $pricing['price'] = Shopp::floatval($pricing['price'], false); $pricing['saleprice'] = Shopp::floatval($pricing['saleprice'], false); $pricing['shipfee'] = Shopp::floatval($pricing['shipfee'], false); $pricing['dimensions'] = array_map(array('Shopp', 'floatval'), $pricing['dimensions']); } } $_POST['prices'] = isset($_POST['price']) ? $_POST['price'] : array(); if (empty($_POST['specs'])) { $Category->specs = array(); } /* @todo Move the rest of category meta inputs to [meta] inputs eventually */ if (isset($_POST['meta']) && isset($_POST['meta']['options'])) { // Moves the meta options input to 'options' index for compatibility $_POST['options'] = $_POST['meta']['options']; } if (empty($_POST['meta']['options']) || count($_POST['meta']['options']['v']) == 1 && !isset($_POST['meta']['options']['v'][1]['options'])) { $_POST['options'] = $Category->options = array(); $_POST['prices'] = $Category->prices = array(); } $metaprops = array('spectemplate', 'facetedmenus', 'variations', 'pricerange', 'priceranges', 'specs', 'options', 'prices'); $metadata = array_filter_keys($_POST, $metaprops); // Update existing entries $updates = array(); foreach ($Category->meta as $id => $MetaObject) { $name = $MetaObject->name; if (isset($metadata[$name])) { $MetaObject->value = stripslashes_deep($metadata[$name]); $updates[] = $name; } } // Create any new missing meta entries $new = array_diff(array_keys($metadata), $updates); // Determine new entries from the exsting updates foreach ($new as $name) { if (!isset($metadata[$name])) { continue; } $Meta = new MetaObject(); $Meta->name = $name; $Meta->value = stripslashes_deep($metadata[$name]); $Category->meta[] = $Meta; } $Category->save(); if (!empty($_POST['deleteImages'])) { $deletes = array(); if (strpos($_POST['deleteImages'], ",")) { $deletes = explode(',', $_POST['deleteImages']); } else { $deletes = array($_POST['deleteImages']); } $Category->delete_images($deletes); } if (!empty($_POST['images']) && is_array($_POST['images'])) { $Category->link_images($_POST['images']); $Category->save_imageorder($_POST['images']); if (!empty($_POST['imagedetails']) && is_array($_POST['imagedetails'])) { foreach ($_POST['imagedetails'] as $i => $data) { $Image = new CategoryImage($data['id']); $Image->title = $data['title']; $Image->alt = $data['alt']; $Image->save(); } } } do_action_ref_array('shopp_category_saved', array($Category)); $this->notice(Shopp::__('%s category saved.', '<strong>' . $Category->name . '</strong>')); }
/** * Loads images assigned to this category * * @since 1.0 * @version 1.1 * * @return boolean Successful load or not **/ function load_images () { $db = DB::get(); $Settings =& EcartSettings(); $ordering = $Settings->get('product_image_order'); $orderby = $Settings->get('product_image_orderby'); if ($ordering == "RAND()") $orderby = $ordering; else $orderby .= ' '.$ordering; $table = DatabaseObject::tablename(CategoryImage::$table); if (empty($this->id)) return false; $records = $db->query("SELECT * FROM $table WHERE parent=$this->id AND context='category' AND type='image' ORDER BY $orderby",AS_ARRAY); foreach ($records as $r) { $image = new CategoryImage(); $image->copydata($r,false,array()); $image->value = unserialize($image->value); $image->expopulate(); $this->images[] = $image; } return true; }
public function saveCategory(Category $category) { $category->save(ActiveRecord::PERFORM_INSERT); if (!empty($category->importedImages)) { foreach ($category->importedImages as $imageFile) { $image = CategoryImage::getNewInstance($category); $image->save(); $image->setFile($imageFile); } } }