/trunk/manage/controllers/store/products.php
PHP | 729 lines | 575 code | 98 blank | 56 comment | 61 complexity | e499dbc989dd404536b557da60ec0f0d MD5 | raw file
Possible License(s): LGPL-2.1
- <?php
-
- class Productscontroller extends Contentelementcontroller{
-
- public function __construct( PeacockCarterFrameworkRegistry $registry, $directCall )
- {
- $this->registry = $registry;
- $this->registry->getObject('adminmenubuilder')->buildMenu( 'store.products' );
- if( $this->registry->getObject('authenticate')->isAuthorised('store_products') == true )
- {
- if( $this->registry->getURLBit(2) != '' )
- {
-
- switch( $this->registry->getURLBit(2) )
- {
- case 'toggle-visibility':
- $this->toggleCategoryActive( $this->registry->getURLBit(3), $this->registry->getURLBit(4) );
- break;
- case 'toggle-security':
- $this->toggleCategorySecurity( $this->registry->getURLBit(3), $this->registry->getURLBit(4) );
- break;
- case 'create':
- $this->createProduct();
- break;
- case 'edit':
- $this->editProduct( intval( $this->registry->getURLBit(3) ) );
- break;
- case 'move-down':
- $this->moveCategoryDown( intval( $this->registry->getURLBit(3) ) );
- break;
- case 'move-up':
- $this->moveCategoryUp( intval( $this->registry->getURLBit(3) ) );
- break;
- case 'move-right':
- $this->moveCategoryRight( intval( $this->registry->getURLBit(3) ) );
- break;
- case 'move-left':
- $this->moveCategoryLeft( intval( $this->registry->getURLBit(3) ) );
- break;
- case 'delete':
- $this->deleteCategory( intval( $this->registry->getURLBit(3) ) );
- break;
- case 'by-category':
- $this->productsByCategory( intval( $this->registry->getURLBit(3) ) );
- break;
- case 'view-revision':
- $this->viewRevision( intval( $this->registry->getURLBit(3) ) );
- break;
- default:
- $this->listContent();
- break;
-
- }
- }
- else
- {
- $this->listContent();
- }
- }
- else
- {
- $this->registry->getObject('authenticate')->redirectToAuthorised('store');
- }
-
- }
-
- private function viewRevision( $revision )
- {
- $sql = "SELECT f.ID as fid, v.*, c.price, c.weight, c.sku, c.stock, c.image, IF( c.featured > 0, 'checked=\"checked\"', '' ) as featured, IF( c.allow_upload > 0, 'checked=\"checked\"', '' ) as recfiles FROM content_versions v, content f, content_versions_store_products c WHERE f.current_revision = v.ID AND v.ID = c.version_id AND v.ID = {$revision} LIMIT 1";
- $this->registry->getObject('db')->executeQuery( $sql );
- if( $this->registry->getObject('db')->numRows() > 0 )
- {
- //version data
- $data = $this->registry->getObject('db')->getRows();
- $fid = $data['fid'];
- $this->registry->getObject('template')->dataToTags( $data, 'pd_' );
- $this->registry->getObject('template')->getPage()->addTag( 'uploads_url', $this->registry->getSetting('uploads_url') );
-
- //categories
- $sql = "SELECT v.name as category_name, c.ID as category_id FROM content_versions v, content c, content_types t WHERE v.ID = c.current_revision AND c.type = t.ID and t.reference = 'product-cat' AND c.deleted = 0 AND c.approved = 1";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'categories', array( 'SQL', $cache ) );
-
- // SELECTED CATEGORIES
- $cats = array();
- $sql = "SELECT category_id FROM store_product_category_associations WHERE product_id=" . $fid;
- $this->registry->getObject('db')->executeQuery($sql);
- while( $row = $this->registry->getObject('db')->getRows() )
- {
- $cats[] = $row;
- }
-
- if( ! empty($cats) )
- {
- foreach( $cats as $cat )
- {
- $this->registry->getObject('template')->getPage()->addPPTag($cat['category_id'].'_cat', "checked='checked'");
- }
- }
-
- // variation groupings
- $sql = "SELECT ID as attribute_id, name as attribute_name FROM store_product_variations";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'variations', array( 'SQL', $cache ) );
- $sql = "SELECT ID, name as attribute_value_name, attribute FROM store_product_variation_values ORDER BY attribute, `order`";
- $this->registry->getObject('db')->executeQuery( $sql );
- $attributeValues = array();
- while( $row = $this->registry->getObject('db')->getRows() )
- {
-
- $attributeValues[ $row['attribute'] ][] = $row;
- }
- // variation values
- foreach( $attributeValues as $attribute => $data )
- {
- $cache = $this->registry->getObject('db')->cacheData( $data );
- $this->registry->getObject('template')->getPage()->addTag( 'variation_values_' . $attribute , array( 'DATA', $cache ) );
- }
-
- // selected variations
- $sql = "SELECT v.ID, a.cost_difference FROM store_product_variation_values v, store_product_variation_associations a WHERE a.variation_value = v.ID AND a.product_id =" . $fid;
- $this->registry->getObject('db')->executeQuery( $sql );
- $p = array();
- while ( $row = $this->registry->getObject('db')->getRows() )
- {
- $p[$row['ID']] = $row['cost_difference'];
- }
-
- if( ! empty( $p ) )
- {
- foreach( $p as $v => $c )
- {
- $this->registry->getObject('template')->getPage()->addPPTag( $v.'_v', "checked='checked'");
- $this->registry->getObject('template')->getPage()->addPPTag( 'form_' . $v.'_v_c', $c );
- }
- }
-
- // product attributes
- $sql = "SELECT ID as attribute_id, name as attribute_name FROM store_product_filter_attribute_types WHERE productContainedAttribute=0";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'attributes', array( 'SQL', $cache ) );
- $sql = "SELECT ID, name as attribute_value_name, attribute FROM store_product_filter_attribute_values ORDER BY attribute, `order`";
- $this->registry->getObject('db')->executeQuery( $sql );
- $attributeValues = array();
- while( $row = $this->registry->getObject('db')->getRows() )
- {
- $attributeValues[ $row['attribute'] ][] = $row;
- }
- // attribute values
- foreach( $attributeValues as $attribute => $data )
- {
- //echo '<pre>' . print_r( $data, true ) . '</pre>';
- $cache = $this->registry->getObject('db')->cacheData( $data );
- $this->registry->getObject('template')->getPage()->addTag( 'attribute_values_' . $attribute , array( 'DATA', $cache ) );
- }
-
- // selected attributes
- $sql = "SELECT v.ID FROM store_product_filter_attribute_values v, store_product_attribute_associations a WHERE v.ID = a.attribute_value AND a.product_id=" .$fid;
- $this->registry->getObject('db')->executeQuery( $sql );
- $a = array();
- while( $row = $this->registry->getObject('db')->getRows() )
- {
- $a[] = $row;
- }
-
- if( ! empty( $a ) )
- {
- foreach( $a as $atype => $avalue )
- {
- $this->registry->getObject('template')->getPage()->addPPTag( $avalue['ID'].'_sel', "selected='selected'");
- }
- }
-
- // shipping methods:
- $sql = "SELECT ID as method_id, name as method_name, default_cost as method_cost FROM store_shipping_methods";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'shipping_methods', array( 'SQL', $cache ) );
-
- $sql = "SELECT * FROM store_product_shipping_costs WHERE product_id=" .$fid;
- $this->registry->getObject('db')->executeQuery( $sql );
- $sc = array();
- while( $row = $this->registry->getObject('db')->getRows() )
- {
- $sc[$row['shipping_id']] = $row['cost'];
- }
-
- if( ! empty($sc) )
- {
- foreach( $sc as $m => $c )
- {
- $this->registry->getObject('template')->getPage()->addPPTag( $m.'_sc', $c);
- }
- }
-
- $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'store/products/viewrevision.tpl.php', 'footer.tpl.php');
- }
- else
- {
- $this->registry->errorPage('Content not found', 'Sorry there was an error locating the content.');
- }
-
- }
-
- private function productsByCategory( $category )
- {
- $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'store/products/list.tpl.php', 'footer.tpl.php');
- $this->buildSiteStructure( $category );
- }
-
- public function moveProductDown( $page )
- {
- parent::setType('product');
- parent::moveDown( $page );
- header('Location: ' . $this->registry->buildURL(array('store'), '', true ) );
- exit();
- }
-
- public function moveProductUp( $page )
- {
- parent::setType('product');
- parent::moveUp( $page );
- header('Location: ' . $this->registry->buildURL(array('store'), '', true ) );
- exit();
- }
-
- public function moveProductLeft( $page )
- {
- parent::setType('product');
- parent::moveLeft( $page );
- header('Location: ' . $this->registry->buildURL(array('store'), '', true ) );
- exit();
- }
-
- public function moveProductRight( $page )
- {
- parent::setType('product');
- parent::moveRight( $page );
- header('Location: ' . $this->registry->buildURL(array('store'), '', true ) );
- exit();
- }
-
- private function editProduct( $pid )
- {
- $this->registry->getObject('template')->getPage()->addTag( 'pID', $pid );
- //$this->buildSiteStructure();
- require_once( FRAMEWORK_PATH . 'models/content.php');
- require_once( FRAMEWORK_PATH . 'models/store/product.php');
- $product = new Product( $this->registry, '', $pid );
-
- if( isset( $_POST['edit_product'] ) )
- {
- $product->setName( $this->registry->getObject('db')->sanitizeData( $_POST['page_name'] ) );
- $product->setTitle( $this->registry->getObject('db')->sanitizeData( $_POST['page_metatitle'] ) );
- $product->setHeading( $this->registry->getObject('db')->sanitizeData( $_POST['page_heading'] ) );
- $product->setContent( $this->registry->getObject('db')->sanitizeData( $_POST['page_content'] ) );
- $product->generateType();
- $product->setAuthor( $this->registry->getObject('authenticate')->getUserID() );
- $product->setMetadescription( $this->registry->getObject('db')->sanitizeData( $_POST['page_metadescription'] ) );
- $product->setMetakeywords( $this->registry->getObject('db')->sanitizeData( $_POST['page_metakeywords'] ) );
-
- // product specific
- //$product->setOverview( $this->registry->getObject('db')->sanitizeData( $_POST['page_overview'] ) );
- // process image upload
- if( isset( $_FILES['imageupload'] ) )
- {
- include( FRAMEWORK_PATH . 'lib/images/imagemanager.class.php');
- $manager = new Imagemanager();
- if ( $manager->loadFromPost( 'imageupload', $this->registry->getSetting('uploads_path') . 'store/products/original/' ))
- {
- $manager->resizeScaleHeight( $this->registry->getSetting('image.large_width') );
- $manager->save( $this->registry->getSetting('uploads_path') . 'store/products/large/' . $manager->getName() );
- $manager->resizeScaleHeight( $this->registry->getSetting('image.thumb_width') );
- $manager->save( $this->registry->getSetting('uploads_path') . 'store/products/small/' . $manager->getName() );
- $product->setImage( $this->registry->getObject('db')->sanitizeData( $manager->getName() ) );
- }
- }
-
- $product->setPrice( $this->registry->getObject('db')->sanitizeData( $_POST['price'] ) );
- $product->setWeight( $this->registry->getObject('db')->sanitizeData( $_POST['weight'] ) );
- $product->setSKU( $this->registry->getObject('db')->sanitizeData( $_POST['sku'] ) );
- $product->setStock( $this->registry->getObject('db')->sanitizeData( $_POST['stock'] ) );
- if( isset( $_POST['featured'] ) && $_POST['featured'] == 'yes' )
- {
- $product->setFeatured( 1 );
- }
- else
- {
- $product->setFeatured( 0 );
- }
- if( isset( $_POST['receives_files'] ) && $_POST['receives_files'] == 'yes' )
- {
- $product->setAllowUploads( 1 );
- }
- else
- {
- $product->setAllowUploads( 0 );
- }
-
-
-
- // variations
- $variations = ( isset( $_POST['variations'] ) && is_array( $_POST['variations'] ) ) ? $_POST['variations'] : array();
- $variations_new = array();
- foreach( $variations as $v )
- {
- $variations_new[ $v ] = $this->registry->getObject('db')->sanitizeData( $_POST['variation_cost_' . $v] );
- }
- $product->setVariations( $variations_new );
-
- // attributes
- $sql = "SELECT ID FROM store_product_filter_attribute_types WHERE productContainedAttribute=0";
- $this->registry->getObject('db')->executeQuery( $sql );
- $attributes = array();
- while( $r = $this->registry->getObject('db')->getRows() )
- {
- $attributes[ $r['ID'] ] = intval( $_POST['attribute_' . $r['ID'] ] );
- }
- $product->setAttributes( $attributes );
-
- // categories
- $categories = ( isset( $_POST['cats'] ) && is_array( $_POST['cats'] ) ) ? $_POST['cats'] : array();
- $product->setCategories( $categories );
-
- // shipping costs
- $sql = "SELECT ID FROM store_shipping_methods";
- $this->registry->getObject('db')->executeQuery( $sql );
- $shipping = array();
- while( $r = $this->registry->getObject('db')->getRows() )
- {
- $shipping[ $r['ID'] ] = $this->registry->getObject('db')->sanitizeData( $_POST['shipping_' . $r['ID'] ] );
- }
- $product->setShippingCosts( $shipping );
-
- // validity
- if( isset( $_POST['page_valid_from'] ) && $_POST['page_valid_from'] != '' )
- {
- $date = ( isset( $_POST['page_valid_from'] ) && $_POST['page_valid_from'] != '' ) ? $this->registry->getObject('db')->sanitizeData( $_POST['page_valid_from'] ) : date('Y-m-d');
- $time = ( isset( $_POST['page_valid_from_time'] ) ) ? $this->registry->getObject('db')->sanitizeData( $_POST['page_valid_from_time'] ) : '';
- $product->setAndProcessValidFrom( $date, $time );
- }
-
- if( isset( $_POST['page_valid_to'] ) && $_POST['page_valid_to'] != '' )
- {
- $date = ( isset( $_POST['page_valid_to'] ) && $_POST['page_valid_to'] != '' ) ? $this->registry->getObject('db')->sanitizeData( $_POST['page_valid_to'] ) : date('Y-m-d');
- $time = ( isset( $_POST['page_valid_to_time'] ) ) ? $this->registry->getObject('db')->sanitizeData( $_POST['page_valid_to_time'] ) : '';
- $product->setAndProcessValidTo( $date, $time );
- }
-
- $product->save();
- $this->registry->redirectUser( array('store', 'products'), 'Product saved','The product has been updated and saved in the CMS', true);
- //$this->registry->getObject('template')->getPage()->removeTag('productcats');
- //$this->registry->redirectUser( array('store'), 'Category created','The category has been created and saved in the CMS', true);
- }
- else
- {
-
- $data = $product->getData();
- //echo '<pre>' . print_r( $data, true ) . '</pre>';
- $data['validTo'] = ( $data['validToDate'] == '00/00/0000' ) ? '' : $data['validToDate'] ;
- $data['validFrom'] = $data['validFromDate'];
- $this->registry->getObject('template')->dataToTags( $data, 'pd_' );
- // product variations
- // variation groupings
- $sql = "SELECT ID as attribute_id, name as attribute_name FROM store_product_variations";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'variations', array( 'SQL', $cache ) );
- $sql = "SELECT ID, name as attribute_value_name, attribute FROM store_product_variation_values ORDER BY attribute, `order`";
- $this->registry->getObject('db')->executeQuery( $sql );
- $attributeValues = array();
- while( $row = $this->registry->getObject('db')->getRows() )
- {
-
- $attributeValues[ $row['attribute'] ][] = $row;
- }
- // variation values
- foreach( $attributeValues as $attribute => $data )
- {
- $cache = $this->registry->getObject('db')->cacheData( $data );
- $this->registry->getObject('template')->getPage()->addTag( 'variation_values_' . $attribute , array( 'DATA', $cache ) );
- }
-
- // selected variations
- $p = $product->getVariations();
- if( ! empty( $p ) )
- {
- $vs = $product->getVariations();
- foreach( $vs as $v => $c )
- {
- $this->registry->getObject('template')->getPage()->addPPTag( $v.'_v', "checked='checked'");
- $this->registry->getObject('template')->getPage()->addPPTag( 'form_' . $v.'_v_c', $c );
- }
- }
-
-
-
- // product attributes
- $sql = "SELECT ID as attribute_id, name as attribute_name FROM store_product_filter_attribute_types WHERE productContainedAttribute=0";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'attributes', array( 'SQL', $cache ) );
- $sql = "SELECT ID, name as attribute_value_name, attribute FROM store_product_filter_attribute_values ORDER BY attribute, `order`";
- $this->registry->getObject('db')->executeQuery( $sql );
- $attributeValues = array();
- while( $row = $this->registry->getObject('db')->getRows() )
- {
- $attributeValues[ $row['attribute'] ][] = $row;
- }
- // attribute values
- foreach( $attributeValues as $attribute => $data )
- {
- //echo '<pre>' . print_r( $data, true ) . '</pre>';
- $cache = $this->registry->getObject('db')->cacheData( $data );
- $this->registry->getObject('template')->getPage()->addTag( 'attribute_values_' . $attribute , array( 'DATA', $cache ) );
- }
-
- // selected attributes
- $a = $product->getAttributes();
- if( ! empty( $a ) )
- {
- $a = $product->getAttributes();
- foreach( $a as $atype => $avalue )
- {
- $this->registry->getObject('template')->getPage()->addPPTag( $avalue.'_sel', "selected='selected'");
- }
- }
-
-
- // categories
- $sql = "SELECT v.name as category_name, c.ID as category_id FROM content c, content_types t, content_versions v WHERE c.type=t.ID and t.reference='product-cat' AND v.ID=c.current_revision";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'categories', array( 'SQL', $cache ) );
-
- // SELECTED CATEGORIES
- $cats = $product->getCategories();
- if( ! empty($cats) )
- {
- foreach( $cats as $cat )
- {
- $this->registry->getObject('template')->getPage()->addPPTag( $cat.'_cat', "checked='checked'");
- }
- }
-
-
-
- // shipping methods:
- $sql = "SELECT ID as method_id, name as method_name, default_cost as method_cost FROM store_shipping_methods";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'shipping_methods', array( 'SQL', $cache ) );
-
- $sc = $product->getShippingCosts();
- if( ! empty($sc) )
- {
- foreach( $sc as $m => $c )
- {
- $this->registry->getObject('template')->getPage()->addPPTag( $m.'_sc', $c);
- }
- }
-
- // featured
- if( $product->isFeatured() )
- {
- $this->registry->getObject('template')->getPage()->addTag( 'featured', "checked='checked'");
- }
- else
- {
- $this->registry->getObject('template')->getPage()->addTag('featured', '');
- }
- if( $product->receivesFiles() )
- {
- $this->registry->getObject('template')->getPage()->addTag( 'recfiles', "checked='checked'");
- }
- else
- {
- $this->registry->getObject('template')->getPage()->addTag('recfiles', '');
- }
-
-
-
-
-
- // template
- $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'store/products/edit.tpl.php', 'footer.tpl.php');
-
- }
- }
-
- private function createProduct()
- {
- //$this->buildSiteStructure();
- if( isset( $_POST['new_product'] ) )
- {
- require_once( FRAMEWORK_PATH . 'models/content.php');
- require_once( FRAMEWORK_PATH . 'models/store/product.php');
-
- $product = new Product( $this->registry, "", 0);
- $product->setName( $this->registry->getObject('db')->sanitizeData( $_POST['page_name'] ) );
- $product->setTitle( $this->registry->getObject('db')->sanitizeData( $_POST['page_metatitle'] ) );
- $product->setHeading( $this->registry->getObject('db')->sanitizeData( $_POST['page_heading'] ) );
- $product->setContent( $this->registry->getObject('db')->sanitizeData( $_POST['page_content'] ) );
- $endpath = preg_replace('/[^a-zA-Z0-9\s]/', '', $_POST['page_name'] );
- $endpath = str_replace( ' ', '-', $endpath );
- $endpath = strtolower( $endpath );
- $path = $endpath;
- $path = $this->registry->getObject('db')->sanitizeData( $path );
- //$cat->setTemplate( $this->registry->getObject('db')->sanitizeData( $_POST['page_template'] ) );
- $product->setPath( $path );
- $product->setActive(1);
- $product->setSecure(0);
- $product->generateType();
- $product->setAuthor( $this->registry->getObject('authenticate')->getUserID() );
- $product->setMetadescription( $this->registry->getObject('db')->sanitizeData( $_POST['page_metadescription'] ) );
- $product->setMetakeywords( $this->registry->getObject('db')->sanitizeData( $_POST['page_metakeywords'] ) );
-
-
- // process image upload
- if( isset( $_FILES['imageupload'] ) )
- {
- include( FRAMEWORK_PATH . 'lib/images/imagemanager.class.php');
- $manager = new Imagemanager();
- if ( $manager->loadFromPost( 'imageupload', $this->registry->getSetting('uploads_path') . 'store/products/original/' ))
- {
- $manager->resizeScaleHeight( $this->registry->getSetting('image.large_width') );
- $manager->save( $this->registry->getSetting('uploads_path') . 'store/products/large/' . $manager->getName() );
- $manager->resizeScaleHeight( $this->registry->getSetting('image.thumb_width') );
- $manager->save( $this->registry->getSetting('uploads_path') . 'store/products/small/' . $manager->getName() );
- $product->setImage( $this->registry->getObject('db')->sanitizeData( $manager->getName() ) );
- }
- else
- {
- $product->setImage('default.png');
- }
- }
-
- $product->setPrice( $this->registry->getObject('db')->sanitizeData( $_POST['price'] ) );
- $product->setWeight( $this->registry->getObject('db')->sanitizeData( $_POST['weight'] ) );
- $product->setSKU( $this->registry->getObject('db')->sanitizeData( $_POST['sku'] ) );
- $product->setStock( $this->registry->getObject('db')->sanitizeData( $_POST['stock'] ) );
- if( isset( $_POST['featured'] ) && $_POST['featured'] == 'yes' )
- {
- $product->setFeatured( 1 );
- }
- else
- {
- $product->setFeatured( 0 );
- }
- if( isset( $_POST['receives_files'] ) && $_POST['receives_files'] == 'yes' )
- {
- $product->setAllowUploads( 1 );
- }
- else
- {
- $product->setAllowUploads( 0 );
- }
-
-
-
- // variations
- $variations = ( isset( $_POST['variations'] ) && is_array( $_POST['variations'] ) ) ? $_POST['variations'] : array();
- $variations_new = array();
- foreach( $variations as $v )
- {
- $variations_new[ $v ] = $this->registry->getObject('db')->sanitizeData( $_POST['variation_cost_' . $v] );
- }
- $product->setVariations( $variations_new );
-
- // attributes
- $sql = "SELECT ID FROM store_product_filter_attribute_types WHERE productContainedAttribute=0";
- $this->registry->getObject('db')->executeQuery( $sql );
- $attributes = array();
- while( $r = $this->registry->getObject('db')->getRows() )
- {
- $attributes[ $r['ID'] ] = intval( $_POST['attribute_' . $r['ID'] ] );
- }
- $product->setAttributes( $attributes );
-
- // categories
- $categories = ( isset( $_POST['cats'] ) && is_array( $_POST['cats'] ) ) ? $_POST['cats'] : array();
- $product->setCategories( $categories );
-
- // shipping costs
- $sql = "SELECT ID FROM store_shipping_methods";
- $this->registry->getObject('db')->executeQuery( $sql );
- $shipping = array();
- while( $r = $this->registry->getObject('db')->getRows() )
- {
- $shipping[ $r['ID'] ] = $this->registry->getObject('db')->sanitizeData( $_POST['shipping_' . $r['ID'] ] );
- }
- $product->setShippingCosts( $shipping );
- $product->overideMicrosite();
-
- // validity
- if( isset( $_POST['page_valid_from'] ) && $_POST['page_valid_from'] != '' )
- {
- $date = ( isset( $_POST['page_valid_from'] ) && $_POST['page_valid_from'] != '' ) ? $this->registry->getObject('db')->sanitizeData( $_POST['page_valid_from'] ) : date('Y-m-d');
- $time = ( isset( $_POST['page_valid_from_time'] ) ) ? $this->registry->getObject('db')->sanitizeData( $_POST['page_valid_from_time'] ) : '';
- $product->setAndProcessValidFrom( $date, $time );
- }
-
- if( isset( $_POST['page_valid_to'] ) && $_POST['page_valid_to'] != '' )
- {
- $date = ( isset( $_POST['page_valid_to'] ) && $_POST['page_valid_to'] != '' ) ? $this->registry->getObject('db')->sanitizeData( $_POST['page_valid_to'] ) : date('Y-m-d');
- $time = ( isset( $_POST['page_valid_to_time'] ) ) ? $this->registry->getObject('db')->sanitizeData( $_POST['page_valid_to_time'] ) : '';
- $product->setAndProcessValidTo( $date, $time );
- }
-
-
- $product->save();
- $this->registry->redirectUser( array('store', 'products'), 'Product created','The product has been created and saved in the CMS', true);
- //$this->registry->getObject('template')->getPage()->removeTag('productcats');
- //$this->registry->redirectUser( array('store'), 'Category created','The category has been created and saved in the CMS', true);
- }
- else
- {
- $this->registry->getObject('template')->getPage()->addTag( 'default_date', date('m/d/Y') );
- // product variations
- // variation groupings
- $sql = "SELECT ID as attribute_id, name as attribute_name FROM store_product_variations";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'variations', array( 'SQL', $cache ) );
- $sql = "SELECT ID, name as attribute_value_name, attribute FROM store_product_variation_values ORDER BY attribute, `order`";
- $this->registry->getObject('db')->executeQuery( $sql );
- $attributeValues = array();
- while( $row = $this->registry->getObject('db')->getRows() )
- {
-
- $attributeValues[ $row['attribute'] ][] = $row;
- }
- // variation values
- foreach( $attributeValues as $attribute => $data )
- {
-
- $cache = $this->registry->getObject('db')->cacheData( $data );
- $this->registry->getObject('template')->getPage()->addTag( 'variation_values_' . $attribute , array( 'DATA', $cache ) );
- }
-
- // product attributes
- $sql = "SELECT ID as attribute_id, name as attribute_name FROM store_product_filter_attribute_types WHERE productContainedAttribute=0";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'attributes', array( 'SQL', $cache ) );
- $sql = "SELECT ID, name as attribute_value_name, attribute FROM store_product_filter_attribute_values ORDER BY attribute, `order`";
- $this->registry->getObject('db')->executeQuery( $sql );
- $attributeValues = array();
- while( $row = $this->registry->getObject('db')->getRows() )
- {
- $attributeValues[ $row['attribute'] ][] = $row;
- }
- // attribute values
- foreach( $attributeValues as $attribute => $data )
- {
- $cache = $this->registry->getObject('db')->cacheData( $data );
- $this->registry->getObject('template')->getPage()->addTag( 'attribute_values_' . $attribute , array( 'DATA', $cache ) );
- }
-
- // categories
- $sql = "SELECT v.name as category_name, c.ID as category_id FROM content c, content_types t, content_versions v WHERE c.type=t.ID and t.reference='product-cat' AND v.ID=c.current_revision AND c.deleted = 0";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'categories', array( 'SQL', $cache ) );
-
-
- // shipping methods
- $sql = "SELECT ID as method_id, name as method_name, default_cost as method_cost FROM store_shipping_methods";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'shipping_methods', array( 'SQL', $cache ) );
-
-
- // template
- $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'store/products/create.tpl.php', 'footer.tpl.php');
-
- }
- }
-
-
- private function listContent()
- {
- // template
-
- $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'store/products/list.tpl.php', 'footer.tpl.php');
- $this->buildSiteStructure();
-
- }
-
- private function toggleCategoryActive( $cat, $newvalue )
- {
-
- $cat = intval($cat);
- $this->toggleActive( $cat );
- header('Location: ' . $this->registry->buildURL(array('store', 'products'), '', true ) );
- exit();
- }
-
-
- private function toggleCategorySecurity( $cat, $newvalue )
- {
-
- $cat = intval($cat);
- $this->toggleSecurity( $cat );
- header('Location: ' . $this->registry->buildURL(array('store', 'products'), '', true ) );
- exit();
- //$this->listContent();
- }
-
- private function buildSiteStructure( $category=0)
- {
- parent::setType('product');
- $typeSQL = "SELECT ID FROM content_types WHERE reference='product'";
- $this->registry->getObject('db')->executeQuery( $typeSQL );
- $data = $this->registry->getObject('db')->getRows();
- $extrafields = array( 'p.price', 'p.sku', 'p.stock', 'p.image' );
- $extratables = array( 'content_versions_store_products p');
- $extraconditions = array( 'p.version_id=f.current_revision');
- if( $category != 0 )
- {
- $extratables[] = 'store_product_category_associations a';
- $extraconditions[] = 'a.category_id=' . $category;
- $extraconditions[] = 'a.product_id=f.ID';
- }
- $this->buildStructure( $extrafields, $extratables, $extraconditions, array(), array(), $microsite = false );
- }
-
- private function deleteCategory( $content )
- {
- $this->delete( $content );
- header('Location: ' . $this->registry->buildURL(array('store'), '', true ) );
- exit();
- }
-
- }
-
-
- ?>