idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
32,900
protected function _createCombineExpression ( $ operator , array $ list ) { $ results = array ( ) ; $ operators = $ this -> getOperators ( ) ; foreach ( $ list as $ entry ) { $ entry = ( array ) $ entry ; if ( ( list ( $ op , $ value ) = each ( $ entry ) ) === false ) { throw new MW_Common_Exception ( sprintf ( 'Invalid combine condition array "%1$s"' , json_encode ( $ entry ) ) ) ; } if ( in_array ( $ op , $ operators [ 'combine' ] ) ) { $ results [ ] = $ this -> _createCombineExpression ( $ op , ( array ) $ entry [ $ op ] ) ; } else if ( in_array ( $ op , $ operators [ 'compare' ] ) ) { $ results [ ] = $ this -> _createCompareExpression ( $ op , ( array ) $ entry [ $ op ] ) ; } else { throw new MW_Common_Exception ( sprintf ( 'Invalid operator "%1$s"' , $ op ) ) ; } } return $ this -> combine ( $ operator , $ results ) ; }
Creates a combine expression .
32,901
protected function _createCompareExpression ( $ op , array $ pair ) { if ( ( list ( $ name , $ value ) = each ( $ pair ) ) === false ) { throw new MW_Common_Exception ( sprintf ( 'Invalid compare condition array "%1$s"' , json_encode ( $ pair ) ) ) ; } return $ this -> compare ( $ op , $ name , $ value ) ; }
Creates a compare expression .
32,902
protected function _addCodes ( $ couponId , array $ data ) { $ manager = MShop_Factory :: createManager ( $ this -> _getContext ( ) , 'coupon/code' ) ; foreach ( $ data as $ entry ) { $ item = $ manager -> createItem ( ) ; $ item -> setCouponId ( $ couponId ) ; $ item -> setCode ( $ entry [ 'code' ] ) ; $ item -> setCount ( $ entry [ 'count' ] ) ; $ item -> setDateStart ( $ entry [ 'datestart' ] ) ; $ item -> setDateEnd ( $ entry [ 'dateend' ] ) ; $ manager -> saveItem ( $ item ) ; } }
Adds the coupon codes to the database .
32,903
public function setup_on_plugins_loaded ( ) { \ load_plugin_textdomain ( 'hogan-core' , false , HOGAN_CORE_DIR . '/languages' ) ; add_action ( 'acf/include_fields' , [ $ this , 'include_modules' ] ) ; add_action ( 'hogan/include_field_groups' , [ $ this , 'register_default_field_group' ] ) ; add_action ( 'acf/include_fields' , [ $ this , 'include_field_groups' ] ) ; add_action ( 'admin_enqueue_scripts' , [ $ this , 'enqueue_admin_assets' ] ) ; add_action ( 'wp_enqueue_scripts' , [ $ this , 'enqueue_core_assets' ] ) ; add_action ( 'wp_enqueue_scripts' , [ $ this , 'enqueue_current_post_modules_assets' ] ) ; }
Init hooks and filter on plugins_loaded .
32,904
public function setup_on_after_setup_theme ( ) { $ this -> _the_content_priority = absint ( apply_filters ( 'hogan/the_content_priority' , 10 ) ) ; add_filter ( 'the_content' , [ $ this , 'append_modules_content' ] , $ this -> _the_content_priority , 1 ) ; if ( true === apply_filters ( 'hogan/searchwp/index_modules_as_post_content' , true ) ) { add_filter ( 'searchwp_pre_set_post' , [ $ this , 'populate_post_content_for_indexing' ] ) ; } add_filter ( 'acf/fields/wysiwyg/toolbars' , [ $ this , 'append_hogan_wysiwyg_toolbar' ] ) ; add_filter ( 'tiny_mce_before_init' , [ $ this , 'override_tinymce_settings' ] ) ; if ( true === apply_filters ( 'hogan/flexible_content_layouts_collapsed_by_default' , false ) && is_admin ( ) ) { add_action ( 'acf/input/admin_footer' , [ $ this , 'append_footer_script_for_collapsed_flexible_content_layouts' ] ) ; } ; add_filter ( 'acf/fields/flexible_content/layout_title' , [ $ this , 'extend_layout_titles' ] , 10 , 3 ) ; }
Init hooks and filter on after_setup_theme .
32,905
public static function get_instance ( ) : Core { if ( null === self :: $ _instance ) { self :: $ _instance = new Core ( ) ; } return self :: $ _instance ; }
Get Core instance .
32,906
public function enqueue_core_assets ( ) { wp_enqueue_style ( 'hogan-core' , HOGAN_CORE_URL . 'assets/css/hogan-core.css' , [ ] , $ this -> assets_version ) ; $ content_width = ( int ) apply_filters ( 'hogan/frontend/content_width' , 1360 ) ; wp_add_inline_style ( 'hogan-core' , sprintf ( '.hogan-module-inner { max-width: %spx; }' , $ content_width ) ) ; }
Load plugin core assets .
32,907
public function register_default_field_group ( ) { $ location = [ ] ; $ post_types = apply_filters ( 'hogan/field_group/default/supported_post_types' , [ 'page' ] ) ; $ post_types = apply_filters_deprecated ( 'hogan/supported_post_types' , [ $ post_types ] , '1.3.0' , 'hogan/field_group/default/supported_post_types' ) ; if ( is_array ( $ post_types ) && ! empty ( $ post_types ) ) { foreach ( $ post_types as $ post_type ) { $ location [ ] = [ [ 'param' => 'post_type' , 'operator' => '==' , 'value' => $ post_type , ] , ] ; } } $ this -> register_field_group ( [ 'name' => 'default' , 'location' => $ location , 'hide_on_screen' => [ 'the_content' , 'custom_fields' , 'discussion' , 'comments' , 'revisions' , 'slug' , 'author' , 'format' , 'tags' , 'send-trackbacks' , ] , ] ) ; }
Register default field group for all modules .
32,908
private function is_current_post_flexible ( $ post , $ more ) { return $ post instanceof \ WP_Post && function_exists ( 'get_field' ) && ( $ more || is_search ( ) || ( defined ( 'REST_REQUEST' ) && REST_REQUEST ) ) && ! post_password_required ( $ post ) ; }
Check if current post is flexible .
32,909
private function get_current_post_layouts ( \ WP_Post $ post ) : array { $ key = 'post-' . $ post -> ID ; if ( ! array_key_exists ( $ key , $ this -> _current_layouts ) || empty ( $ this -> _current_layouts [ $ key ] ) ) { $ this -> _current_layouts [ $ key ] = [ ] ; foreach ( $ this -> _field_groups as $ field_group ) { $ layouts = get_field ( 'hogan_' . $ field_group . '_modules_name' , $ post ) ; if ( is_array ( $ layouts ) && ! empty ( $ layouts ) ) { $ this -> _current_layouts [ $ key ] = array_merge ( $ this -> _current_layouts [ $ key ] , $ layouts ) ; } } } return $ this -> _current_layouts [ $ key ] ; }
Build an array of active layouts for current post .
32,910
public function enqueue_current_post_modules_assets ( ) { global $ more , $ post ; if ( $ this -> is_current_post_flexible ( $ post , $ more ) ) { $ layouts = $ this -> get_current_post_layouts ( $ post ) ; foreach ( $ layouts as $ layout ) { if ( ! isset ( $ layout [ 'acf_fc_layout' ] ) || empty ( $ layout [ 'acf_fc_layout' ] ) ) { continue ; } $ this -> enqueue_module_assets ( $ layout [ 'acf_fc_layout' ] ) ; } } }
Enqueue module assets on current page .
32,911
public function enqueue_module_assets ( $ name ) { if ( ! in_array ( $ name , $ this -> _enqueued_modules , true ) ) { $ module = $ this -> get_module ( $ name ) ; if ( $ module instanceof Module && method_exists ( $ module , 'enqueue_assets' ) ) { $ this -> _enqueued_modules [ ] = $ name ; $ module -> enqueue_assets ( ) ; } } }
Enqueue module assets .
32,912
public function append_modules_content ( string $ content ) : string { global $ more , $ post ; $ flexible_content = '' ; remove_filter ( 'the_content' , [ $ this , 'append_modules_content' ] , $ this -> _the_content_priority ) ; if ( $ this -> is_current_post_flexible ( $ post , $ more ) ) { $ flexible_content = $ this -> get_modules_content ( $ post ) ; } add_filter ( 'the_content' , [ $ this , 'append_modules_content' ] , $ this -> _the_content_priority , 1 ) ; return $ content . $ flexible_content ; }
Append modules HTML content to the_content for the global post object .
32,913
private function get_modules_content ( \ WP_Post $ post ) : string { $ flexible_content = $ this -> _flexible_content [ $ post -> ID ] ?? null ; if ( empty ( $ flexible_content ) ) { $ layouts = $ this -> get_current_post_layouts ( $ post ) ; foreach ( $ layouts as $ layout ) { if ( ! isset ( $ layout [ 'acf_fc_layout' ] ) || empty ( $ layout [ 'acf_fc_layout' ] ) ) { continue ; } ob_start ( ) ; $ this -> render_module_template ( $ layout [ 'acf_fc_layout' ] , $ layout ) ; $ flexible_content .= ob_get_clean ( ) ; } $ this -> _flexible_content [ $ post -> ID ] = $ flexible_content ; } return ( string ) $ flexible_content ; }
Get modules HTML content .
32,914
public function populate_post_content_for_indexing ( \ WP_Post $ post ) : \ WP_Post { $ module_content = $ this -> get_modules_content ( $ post ) ; if ( ! empty ( $ module_content ) ) { $ post -> post_content = $ module_content ; } return $ post ; }
Populate the post_content with modules HTML before SearchWP indexing .
32,915
public function extend_layout_titles ( $ title , $ field , $ layout ) : string { if ( ! empty ( get_sub_field ( 'heading' ) ) ) { $ title .= ': ' . get_sub_field ( 'heading' ) ; } return apply_filters ( 'hogan/extend_layout_title' , $ title ) ; }
Extend layout titles .
32,916
final public function get_layout_definition ( ) : array { $ standard_fields = [ ] ; if ( true === apply_filters ( 'hogan/module/' . $ this -> name . '/heading/enabled' , false ) ) { hogan_append_heading_field ( $ standard_fields , $ this ) ; } if ( true === apply_filters ( 'hogan/module/' . $ this -> name . '/lead/enabled' , false ) ) { hogan_append_lead_field ( $ standard_fields , $ this ) ; } $ sub_fields = array_merge ( apply_filters ( 'hogan/module/' . $ this -> name . '/fields_before' , [ ] ) , $ standard_fields , $ this -> get_fields ( ) , apply_filters ( 'hogan/module/' . $ this -> name . '/fields_after' , [ ] ) ) ; return [ 'key' => $ this -> field_key , 'name' => $ this -> name , 'label' => $ this -> label , 'display' => apply_filters ( 'hogan/module/' . $ this -> name . '/layout/display' , 'block' ) , 'sub_fields' => apply_filters ( 'hogan/module/' . $ this -> name . '/layout/sub_fields' , $ sub_fields ) , 'min' => apply_filters ( 'hogan/module/' . $ this -> name . '/layout/min' , '' ) , 'max' => apply_filters ( 'hogan/module/' . $ this -> name . '/layout/max' , '' ) , ] ; }
Base class for field definitions .
32,917
public function load_args_from_layout_content ( array $ raw_content , int $ counter = 0 ) { foreach ( $ this -> helper_fields as $ helper_field ) { $ this -> { $ helper_field } = $ raw_content [ $ helper_field ] ?? '' ; } $ this -> raw_content = $ raw_content ; $ this -> counter = $ counter ; }
Map raw fields from acf to object variable .
32,918
protected function render_opening_template_wrappers ( $ counter = 0 ) { $ this -> outer_wrapper_tag = apply_filters ( 'hogan/module/outer_wrapper_tag' , $ this -> outer_wrapper_tag , $ this ) ; $ this -> inner_wrapper_tag = apply_filters ( 'hogan/module/inner_wrapper_tag' , $ this -> inner_wrapper_tag , $ this ) ; if ( ! empty ( $ this -> outer_wrapper_tag ) ) { $ outer_wrapper_default_classnames = [ 'hogan-module' , 'hogan-module-' . $ this -> name , 'hogan-module-' . $ counter , ] ; $ outer_wrapper_classnames = hogan_classnames ( apply_filters ( 'hogan/module/outer_wrapper_classes' , array_merge ( $ outer_wrapper_default_classnames , $ this -> outer_wrapper_classnames ) , $ this ) ) ; $ outer_wrapper_attributes = apply_filters ( 'hogan/module/outer_wrapper_attributes' , [ ] , $ this ) ; printf ( '<%s id="%s" class="%s"%s>' , esc_attr ( $ this -> outer_wrapper_tag ) , esc_attr ( 'module-' . $ counter ) , esc_attr ( $ outer_wrapper_classnames ) , hogan_attributes ( $ outer_wrapper_attributes ) ) ; } if ( ! empty ( $ this -> inner_wrapper_tag ) ) { $ inner_wrapper_classnames = hogan_classnames ( apply_filters ( 'hogan/module/inner_wrapper_classes' , array_merge ( [ 'hogan-module-inner' ] , $ this -> inner_wrapper_classnames ) , $ this ) ) ; $ inner_wrapper_attributes = apply_filters ( 'hogan/module/inner_wrapper_attributes' , [ ] , $ this ) ; printf ( '<%s class="%s"%s>' , esc_attr ( $ this -> inner_wrapper_tag ) , esc_attr ( $ inner_wrapper_classnames ) , hogan_attributes ( $ inner_wrapper_attributes ) ) ; } }
Render module wrappers opening tags before template include .
32,919
protected function render_closing_template_wrappers ( ) { if ( ! empty ( $ this -> inner_wrapper_tag ) ) { printf ( '</%s>' , esc_attr ( $ this -> inner_wrapper_tag ) ) ; } if ( ! empty ( $ this -> outer_wrapper_tag ) ) { printf ( '</%s>' , esc_attr ( $ this -> outer_wrapper_tag ) ) ; } }
Render module wrapper closing tags after template include .
32,920
final public function render_template ( $ raw_content , $ counter = 0 , $ echo = true ) : string { $ this -> load_args_from_layout_content ( $ raw_content , $ counter ) ; if ( true !== $ this -> validate_args ( ) ) { return '' ; } $ template = apply_filters ( 'hogan/module/' . $ this -> name . '/template' , $ this -> template , $ this ) ; if ( ! file_exists ( $ template ) || 0 !== validate_file ( $ template ) ) { return '' ; } if ( false === $ echo ) { ob_start ( ) ; } $ this -> render_opening_template_wrappers ( $ counter ) ; $ output_heading_component = true === apply_filters ( 'hogan/module/' . $ this -> name . '/heading/enabled' , false ) && ! empty ( $ this -> heading ) ; $ output_lead_component = true === apply_filters ( 'hogan/module/' . $ this -> name . '/lead/enabled' , false ) && ! empty ( $ this -> lead ) ; $ wrap_heading_and_lead = true === apply_filters ( 'hogan/module/wrap_heading_and_lead' , false , $ this ) && ( $ output_heading_component || $ output_lead_component ) ; if ( true === $ wrap_heading_and_lead ) { printf ( '<div class="%s">' , esc_attr ( hogan_classnames ( 'hogan-module-header' , 'hogan-module-' . $ this -> name . '-header' ) ) ) ; } if ( true === $ output_heading_component ) { hogan_component ( 'heading' , [ 'title' => $ this -> heading , ] ) ; } if ( true === $ output_lead_component ) { hogan_component ( 'lead' , [ 'content' => $ this -> lead , ] ) ; } if ( true === $ wrap_heading_and_lead ) { echo '</div>' ; } do_action ( 'hogan/module/render_fields_before' , $ raw_content , $ this ) ; include $ template ; do_action ( 'hogan/module/render_fields_after' , $ raw_content , $ this ) ; $ this -> render_closing_template_wrappers ( ) ; if ( false === $ echo ) { return ob_get_clean ( ) ; } return '' ; }
Render module template .
32,921
public function setMimeType ( $ mimetype ) { if ( $ mimetype == $ this -> getMimeType ( ) ) { return ; } if ( preg_match ( '/^[a-z\-]+\/[a-zA-Z0-9\.\-\+]+$/' , $ mimetype ) !== 1 ) { throw new MShop_Media_Exception ( sprintf ( 'Invalid mime type "%1$s"' , $ mimetype ) ) ; } $ this -> _values [ 'mimetype' ] = ( string ) $ mimetype ; $ this -> setModified ( ) ; }
Sets the new mime type of the media .
32,922
public function setUrl ( $ url ) { if ( $ url == $ this -> getUrl ( ) ) { return ; } $ this -> _values [ 'url' ] = ( string ) $ url ; $ this -> setModified ( ) ; }
Sets the new url of the media item .
32,923
public function setPreview ( $ url ) { if ( $ url == $ this -> getPreview ( ) ) { return ; } $ this -> _values [ 'preview' ] = ( string ) $ url ; $ this -> setModified ( ) ; }
Sets the new preview url of the media item .
32,924
public function saveItem ( MShop_Common_Item_Interface $ item , $ fetch = true ) { $ iface = 'MShop_Service_Item_Interface' ; if ( ! ( $ item instanceof $ iface ) ) { throw new MShop_Service_Exception ( sprintf ( 'Object is not of required type "%1$s"' , $ iface ) ) ; } if ( ! $ item -> isModified ( ) ) { return ; } $ context = $ this -> _getContext ( ) ; $ dbm = $ context -> getDatabaseManager ( ) ; $ dbname = $ this -> _getResourceName ( ) ; $ conn = $ dbm -> acquire ( $ dbname ) ; try { $ id = $ item -> getId ( ) ; $ date = date ( 'Y-m-d H:i:s' ) ; if ( $ id === null ) { $ path = 'mshop/service/manager/default/item/insert' ; } else { $ path = 'mshop/service/manager/default/item/update' ; } $ stmt = $ this -> _getCachedStatement ( $ conn , $ path ) ; $ stmt -> bind ( 1 , $ context -> getLocale ( ) -> getSiteId ( ) , MW_DB_Statement_Abstract :: PARAM_INT ) ; $ stmt -> bind ( 2 , $ item -> getPosition ( ) , MW_DB_Statement_Abstract :: PARAM_INT ) ; $ stmt -> bind ( 3 , $ item -> getTypeId ( ) ) ; $ stmt -> bind ( 4 , $ item -> getCode ( ) ) ; $ stmt -> bind ( 5 , $ item -> getLabel ( ) ) ; $ stmt -> bind ( 6 , $ item -> getProvider ( ) ) ; $ stmt -> bind ( 7 , json_encode ( $ item -> getConfig ( ) ) ) ; $ stmt -> bind ( 8 , $ item -> getStatus ( ) , MW_DB_Statement_Abstract :: PARAM_INT ) ; $ stmt -> bind ( 9 , $ date ) ; $ stmt -> bind ( 10 , $ context -> getEditor ( ) ) ; if ( $ id !== null ) { $ stmt -> bind ( 11 , $ id , MW_DB_Statement_Abstract :: PARAM_INT ) ; $ item -> setId ( $ id ) ; } else { $ stmt -> bind ( 11 , $ date ) ; } $ stmt -> execute ( ) -> finish ( ) ; if ( $ id === null && $ fetch === true ) { $ path = 'mshop/service/manager/default/item/newid' ; $ item -> setId ( $ this -> _newId ( $ conn , $ context -> getConfig ( ) -> get ( $ path , $ path ) ) ) ; } $ dbm -> release ( $ conn , $ dbname ) ; } catch ( Exception $ e ) { $ dbm -> release ( $ conn , $ dbname ) ; throw $ e ; } }
Adds a new or updates an existing service item in the storage .
32,925
public function searchItems ( MW_Common_Criteria_Interface $ search , array $ ref = array ( ) , & $ total = null ) { $ map = $ typeIds = array ( ) ; $ context = $ this -> _getContext ( ) ; $ dbm = $ context -> getDatabaseManager ( ) ; $ dbname = $ this -> _getResourceName ( ) ; $ conn = $ dbm -> acquire ( $ dbname ) ; try { $ required = array ( 'service' ) ; $ level = MShop_Locale_Manager_Abstract :: SITE_PATH ; $ cfgPathSearch = 'mshop/service/manager/default/item/search' ; $ cfgPathCount = 'mshop/service/manager/default/item/count' ; $ results = $ this -> _searchItems ( $ conn , $ search , $ cfgPathSearch , $ cfgPathCount , $ required , $ total , $ level ) ; while ( ( $ row = $ results -> fetch ( ) ) !== false ) { $ config = $ row [ 'config' ] ; if ( ( $ row [ 'config' ] = json_decode ( $ row [ 'config' ] , true ) ) === null ) { $ msg = sprintf ( 'Invalid JSON as result of search for ID "%2$s" in "%1$s": %3$s' , 'mshop_service.config' , $ row [ 'id' ] , $ config ) ; $ this -> _getContext ( ) -> getLogger ( ) -> log ( $ msg , MW_Logger_Abstract :: WARN ) ; } $ map [ $ row [ 'id' ] ] = $ row ; $ typeIds [ $ row [ 'typeid' ] ] = null ; } $ dbm -> release ( $ conn , $ dbname ) ; } catch ( Exception $ e ) { $ dbm -> release ( $ conn , $ dbname ) ; throw $ e ; } if ( ! empty ( $ typeIds ) ) { $ typeManager = $ this -> getSubManager ( 'type' ) ; $ typeSearch = $ typeManager -> createSearch ( ) ; $ typeSearch -> setConditions ( $ typeSearch -> compare ( '==' , 'service.type.id' , array_keys ( $ typeIds ) ) ) ; $ typeSearch -> setSlice ( 0 , $ search -> getSliceSize ( ) ) ; $ typeItems = $ typeManager -> searchItems ( $ typeSearch ) ; foreach ( $ map as $ id => $ row ) { if ( isset ( $ typeItems [ $ row [ 'typeid' ] ] ) ) { $ map [ $ id ] [ 'type' ] = $ typeItems [ $ row [ 'typeid' ] ] -> getCode ( ) ; } } } return $ this -> _buildItems ( $ map , $ ref , 'service' ) ; }
Searches for service items based on the given criteria .
32,926
public function getProvider ( MShop_Service_Item_Interface $ item ) { $ domain = ucwords ( $ item -> getType ( ) ) ; $ names = explode ( ',' , $ item -> getProvider ( ) ) ; if ( ctype_alnum ( $ domain ) === false ) { throw new MShop_Service_Exception ( sprintf ( 'Invalid characters in domain name "%1$s"' , $ domain ) ) ; } if ( ( $ provider = array_shift ( $ names ) ) === null ) { throw new MShop_Service_Exception ( sprintf ( 'Provider in "%1$s" not available' , $ item -> getProvider ( ) ) ) ; } if ( ctype_alnum ( $ provider ) === false ) { throw new MShop_Service_Exception ( sprintf ( 'Invalid characters in provider name "%1$s"' , $ provider ) ) ; } $ interface = 'MShop_Service_Provider_Factory_Interface' ; $ classname = 'MShop_Service_Provider_' . $ domain . '_' . $ provider ; if ( class_exists ( $ classname ) === false ) { throw new MShop_Service_Exception ( sprintf ( 'Class "%1$s" not available' , $ classname ) ) ; } $ context = $ this -> _getContext ( ) ; $ provider = new $ classname ( $ context , $ item ) ; if ( ( $ provider instanceof $ interface ) === false ) { $ msg = sprintf ( 'Class "%1$s" does not implement interface "%2$s"' , $ classname , $ interface ) ; throw new MShop_Service_Exception ( $ msg ) ; } $ config = $ context -> getConfig ( ) ; $ decorators = $ config -> get ( 'mshop/service/provider/' . $ item -> getType ( ) . '/decorators' , array ( ) ) ; $ provider = $ this -> _addServiceDecorators ( $ item , $ provider , $ names ) ; return $ this -> _addServiceDecorators ( $ item , $ provider , $ decorators ) ; }
Returns the service provider which is responsible for the service item .
32,927
public function createItem ( ) { $ locale = $ this -> _getContext ( ) -> getLocale ( ) ; $ values = array ( 'siteid' => $ locale -> getSiteId ( ) ) ; if ( $ locale -> getCurrencyId ( ) !== null ) { $ values [ 'currencyid' ] = $ locale -> getCurrencyId ( ) ; } return $ this -> _createItem ( $ values ) ; }
Instantiates a new price item object .
32,928
public function saveItem ( MShop_Common_Item_Interface $ item , $ fetch = true ) { $ iface = 'MShop_Price_Item_Interface' ; if ( ! ( $ item instanceof $ iface ) ) { throw new MShop_Price_Exception ( sprintf ( 'Object is not of required type "%1$s"' , $ iface ) ) ; } $ context = $ this -> _getContext ( ) ; $ dbm = $ context -> getDatabaseManager ( ) ; $ dbname = $ this -> _getResourceName ( ) ; $ conn = $ dbm -> acquire ( $ dbname ) ; try { $ id = $ item -> getId ( ) ; $ date = date ( 'Y-m-d H:i:s' ) ; if ( $ id === null ) { $ path = 'mshop/price/manager/default/item/insert' ; } else { $ path = 'mshop/price/manager/default/item/update' ; } $ stmt = $ this -> _getCachedStatement ( $ conn , $ path ) ; $ stmt -> bind ( 1 , $ context -> getLocale ( ) -> getSiteId ( ) , MW_DB_Statement_Abstract :: PARAM_INT ) ; $ stmt -> bind ( 2 , $ item -> getTypeId ( ) ) ; $ stmt -> bind ( 3 , $ item -> getCurrencyId ( ) ) ; $ stmt -> bind ( 4 , $ item -> getDomain ( ) ) ; $ stmt -> bind ( 5 , $ item -> getLabel ( ) ) ; $ stmt -> bind ( 6 , $ item -> getQuantity ( ) , MW_DB_Statement_Abstract :: PARAM_INT ) ; $ stmt -> bind ( 7 , $ item -> getValue ( ) ) ; $ stmt -> bind ( 8 , $ item -> getCosts ( ) ) ; $ stmt -> bind ( 9 , $ item -> getRebate ( ) ) ; $ stmt -> bind ( 10 , $ item -> getTaxRate ( ) ) ; $ stmt -> bind ( 11 , $ item -> getStatus ( ) , MW_DB_Statement_Abstract :: PARAM_INT ) ; $ stmt -> bind ( 12 , $ date ) ; $ stmt -> bind ( 13 , $ context -> getEditor ( ) ) ; if ( $ id !== null ) { $ stmt -> bind ( 14 , $ id , MW_DB_Statement_Abstract :: PARAM_INT ) ; $ item -> setId ( $ id ) ; } else { $ stmt -> bind ( 14 , $ date ) ; } $ stmt -> execute ( ) -> finish ( ) ; if ( $ id === null && $ fetch === true ) { $ path = 'mshop/price/manager/default/item/newid' ; $ item -> setId ( $ this -> _newId ( $ conn , $ context -> getConfig ( ) -> get ( $ path , $ path ) ) ) ; } $ dbm -> release ( $ conn , $ dbname ) ; } catch ( Exception $ e ) { $ dbm -> release ( $ conn , $ dbname ) ; throw $ e ; } }
Saves a price item object .
32,929
protected function _process ( array $ stmts ) { $ this -> _msg ( 'Change order siteid foreign key constraints' , 0 ) ; $ this -> _status ( '' ) ; foreach ( $ stmts as $ table => $ stmtList ) { foreach ( $ stmtList as $ constraint => $ stmts ) { $ this -> _msg ( sprintf ( 'Checking constraint "%1$s": ' , $ constraint ) , 1 ) ; if ( $ this -> _schema -> tableExists ( $ table ) && $ this -> _schema -> getColumnDetails ( $ table , 'siteid' ) -> isNullable ( ) === false ) { $ this -> _execute ( $ stmts [ 'column' ] ) ; if ( $ this -> _schema -> constraintExists ( $ table , $ constraint ) === true ) { $ this -> _execute ( $ stmts [ 'drop' ] ) ; } $ this -> _status ( 'changed' ) ; } else { $ this -> _status ( 'OK' ) ; } } } }
Changes CONSTRAINT action ON DELETE for order tables .
32,930
public static function toISO1366Alpha2 ( $ countryCode ) { if ( ! static :: $ data ) { $ file = fopen ( __DIR__ . '../../../data/countries.csv' , 'r' ) ; while ( ! feof ( $ file ) ) { $ line = fgetcsv ( $ file ) ; static :: $ data [ reset ( $ line ) ] = end ( $ line ) ; } } return isset ( static :: $ data [ $ countryCode ] ) ? static :: $ data [ $ countryCode ] : false ; }
Return the corresponding ISO 1366 - Alpha2 for the given ISO 1366 - Alpha3 .
32,931
public static function buildDataDefinition ( BuildDataDefinitionEvent $ event ) { $ container = $ event -> getContainer ( ) ; if ( ! $ container -> hasDefinition ( 'metamodels.translatedfile-attributes' ) ) { return ; } foreach ( $ container -> getDefinition ( 'metamodels.translatedfile-attributes' ) -> get ( ) as $ propertyName ) { foreach ( $ container -> getPalettesDefinition ( ) -> getPalettes ( ) as $ palette ) { foreach ( $ palette -> getLegends ( ) as $ legend ) { if ( ( $ legend -> hasProperty ( $ propertyName ) ) && ( $ container -> getPropertiesDefinition ( ) -> hasProperty ( $ propertyName . '__sort' ) ) ) { $ file = $ legend -> getProperty ( $ propertyName ) ; $ legend -> addProperty ( $ order = new Property ( $ propertyName . '__sort' ) , $ file ) ; $ order -> setEditableCondition ( $ file -> getEditableCondition ( ) ) ; $ order -> setVisibleCondition ( $ file -> getVisibleCondition ( ) ) ; } } } } }
This handles all translated file attributes and clones the visible conditions to reflect those of the translated file attribute .
32,932
protected function _createItem ( array $ entry ) { $ item = $ this -> _manager -> createItem ( ) ; foreach ( $ entry as $ name => $ value ) { switch ( $ name ) { case 'coupon.code.id' : $ item -> setId ( $ value ) ; break ; case 'coupon.code.code' : $ item -> setCode ( $ value ) ; break ; case 'coupon.code.count' : $ item -> setCount ( $ value ) ; break ; case 'coupon.code.couponid' : $ item -> setCouponId ( $ value ) ; break ; case 'coupon.code.datestart' : if ( $ value != '' ) { $ value = str_replace ( 'T' , ' ' , $ value ) ; $ entry -> { 'coupon.code.datestart' } = $ value ; $ item -> setDateStart ( $ value ) ; } break ; case 'coupon.code.dateend' : if ( $ value != '' ) { $ value = str_replace ( 'T' , ' ' , $ value ) ; $ entry -> { 'coupon.code.dateend' } = $ value ; $ item -> setDateEnd ( $ value ) ; } break ; } } return $ item ; }
Creates a new coupon code item and sets the properties from the given array .
32,933
public function transform ( $ url ) { if ( strncmp ( $ url , 'http' , 4 ) !== 0 && strncmp ( $ url , 'data' , 4 ) !== 0 ) { $ url = $ this -> _baseurl . $ url ; } return $ this -> _enc -> attr ( $ url ) ; }
Returns the complete encoded content URL .
32,934
public function getItem ( $ id , array $ ref = array ( ) ) { $ criteria = $ this -> createSearch ( ) ; $ criteria -> setConditions ( $ criteria -> compare ( '==' , 'job.id' , $ id ) ) ; $ items = $ this -> searchItems ( $ criteria , $ ref ) ; if ( ( $ item = reset ( $ items ) ) === false ) { throw new MAdmin_Job_Exception ( sprintf ( 'Job with ID "%1$s" not found' , $ id ) ) ; } return $ item ; }
Creates the job object for the given job ID .
32,935
public function setId ( $ id ) { if ( $ id === null ) { $ this -> _modified = true ; } $ this -> _values [ 'id' ] = $ id ; }
Sets the unique ID of the node .
32,936
public function setLabel ( $ name ) { if ( $ name == $ this -> getLabel ( ) ) { return ; } $ this -> _values [ 'label' ] = ( string ) $ name ; $ this -> _modified = true ; }
Sets the new name of the node .
32,937
public function setCode ( $ name ) { if ( $ name == $ this -> getCode ( ) ) { return ; } $ this -> _values [ 'code' ] = ( string ) $ name ; $ this -> _modified = true ; }
Sets the new code of the node .
32,938
public function setStatus ( $ status ) { if ( $ status == $ this -> getStatus ( ) ) { return ; } $ this -> _values [ 'status' ] = ( int ) $ status ; $ this -> _modified = true ; }
Sets the new status of the node .
32,939
public function optimize ( ) { $ context = $ this -> _getContext ( ) ; $ dbm = $ context -> getDatabaseManager ( ) ; $ dbname = $ this -> _getResourceName ( ) ; $ conn = $ dbm -> acquire ( $ dbname ) ; try { $ path = 'mshop/catalog/manager/index/text/default/optimize' ; foreach ( $ context -> getConfig ( ) -> get ( $ path , array ( ) ) as $ sql ) { $ conn -> create ( $ sql ) -> execute ( ) -> finish ( ) ; } $ dbm -> release ( $ conn , $ dbname ) ; } catch ( Exception $ e ) { $ dbm -> release ( $ conn , $ dbname ) ; throw $ e ; } foreach ( $ this -> _getSubManagers ( ) as $ submanager ) { $ submanager -> optimize ( ) ; } }
Optimizes the index if necessary . Execution of this operation can take a very long time and shouldn t be called through a web server enviroment .
32,940
public function cleanupIndex ( $ timestamp ) { $ context = $ this -> _getContext ( ) ; $ siteid = $ context -> getLocale ( ) -> getSiteId ( ) ; $ this -> begin ( ) ; $ dbm = $ context -> getDatabaseManager ( ) ; $ dbname = $ this -> _getResourceName ( ) ; $ conn = $ dbm -> acquire ( $ dbname ) ; try { $ stmt = $ this -> _getCachedStatement ( $ conn , 'mshop/catalog/manager/index/text/default/cleanup' ) ; $ stmt -> bind ( 1 , $ timestamp ) ; $ stmt -> bind ( 2 , $ siteid , MW_DB_Statement_Abstract :: PARAM_INT ) ; $ stmt -> execute ( ) -> finish ( ) ; $ dbm -> release ( $ conn , $ dbname ) ; } catch ( Exception $ e ) { $ dbm -> release ( $ conn , $ dbname ) ; $ this -> rollback ( ) ; throw $ e ; } $ this -> commit ( ) ; foreach ( $ this -> _getSubManagers ( ) as $ submanager ) { $ submanager -> cleanupIndex ( $ timestamp ) ; } }
Removes all entries not touched after the given timestamp in the catalog index . This can be a long lasting operation .
32,941
public function rebuildIndex ( array $ items = array ( ) ) { if ( empty ( $ items ) ) { return ; } MW_Common_Abstract :: checkClassList ( 'MShop_Product_Item_Interface' , $ items ) ; $ context = $ this -> _getContext ( ) ; $ locale = $ context -> getLocale ( ) ; $ siteid = $ context -> getLocale ( ) -> getSiteId ( ) ; $ editor = $ context -> getEditor ( ) ; $ date = date ( 'Y-m-d H:i:s' ) ; $ dbm = $ context -> getDatabaseManager ( ) ; $ dbname = $ this -> _getResourceName ( ) ; $ conn = $ dbm -> acquire ( $ dbname ) ; try { foreach ( $ items as $ item ) { $ parentId = $ item -> getId ( ) ; $ listTypes = array ( ) ; foreach ( $ item -> getListItems ( 'text' ) as $ listItem ) { $ listTypes [ $ listItem -> getRefId ( ) ] [ ] = $ listItem -> getType ( ) ; } $ stmt = $ this -> _getCachedStatement ( $ conn , 'mshop/catalog/manager/index/text/default/item/insert' ) ; foreach ( $ item -> getRefItems ( 'text' ) as $ refId => $ refItem ) { if ( ! isset ( $ listTypes [ $ refId ] ) ) { $ msg = sprintf ( 'List type for text item with ID "%1$s" not available' , $ refId ) ; throw new MShop_Catalog_Exception ( $ msg ) ; } foreach ( $ listTypes [ $ refId ] as $ listType ) { $ this -> _saveText ( $ stmt , $ parentId , $ siteid , $ refId , $ refItem -> getLanguageId ( ) , $ listType , $ refItem -> getType ( ) , 'product' , $ refItem -> getContent ( ) , $ date , $ editor ) ; } } $ names = $ item -> getRefItems ( 'text' , 'name' ) ; if ( empty ( $ names ) ) { $ this -> _saveText ( $ stmt , $ parentId , $ siteid , null , $ locale -> getLanguageId ( ) , 'default' , 'name' , 'product' , $ item -> getLabel ( ) , $ date , $ editor ) ; } } $ dbm -> release ( $ conn , $ dbname ) ; } catch ( Exception $ e ) { $ dbm -> release ( $ conn , $ dbname ) ; throw $ e ; } $ this -> _saveAttributeTexts ( $ items ) ; foreach ( $ this -> _getSubManagers ( ) as $ submanager ) { $ submanager -> rebuildIndex ( $ items ) ; } }
Rebuilds the catalog index text for searching products or specified list of products . This can be a long lasting operation .
32,942
public function searchItems ( MW_Common_Criteria_Interface $ search , array $ ref = array ( ) , & $ total = null ) { $ items = $ ids = array ( ) ; $ context = $ this -> _getContext ( ) ; $ dbm = $ context -> getDatabaseManager ( ) ; $ dbname = $ this -> _getResourceName ( ) ; $ conn = $ dbm -> acquire ( $ dbname ) ; try { $ level = MShop_Locale_Manager_Abstract :: SITE_ALL ; $ cfgPathSearch = 'mshop/catalog/manager/index/text/default/item/search' ; $ cfgPathCount = 'mshop/catalog/manager/index/text/default/item/count' ; $ required = array ( 'product' ) ; $ results = $ this -> _searchItems ( $ conn , $ search , $ cfgPathSearch , $ cfgPathCount , $ required , $ total , $ level ) ; while ( ( $ row = $ results -> fetch ( ) ) !== false ) { $ ids [ ] = $ row [ 'id' ] ; } $ dbm -> release ( $ conn , $ dbname ) ; } catch ( Exception $ e ) { $ dbm -> release ( $ conn , $ dbname ) ; throw $ e ; } $ manager = MShop_Factory :: createManager ( $ context , 'product' ) ; $ search = $ manager -> createSearch ( ) ; $ search -> setConditions ( $ search -> compare ( '==' , 'product.id' , $ ids ) ) ; $ products = $ manager -> searchItems ( $ search , $ ref , $ total ) ; foreach ( $ ids as $ id ) { if ( isset ( $ products [ $ id ] ) ) { $ items [ $ id ] = $ products [ $ id ] ; } } return $ items ; }
Searches for items matching the given criteria .
32,943
public function searchTexts ( MW_Common_Criteria_Interface $ search ) { $ list = array ( ) ; $ context = $ this -> _getContext ( ) ; $ dbm = $ context -> getDatabaseManager ( ) ; $ dbname = $ this -> _getResourceName ( ) ; $ conn = $ dbm -> acquire ( $ dbname ) ; try { $ level = MShop_Locale_Manager_Abstract :: SITE_ALL ; $ cfgPathSearch = 'mshop/catalog/manager/index/text/default/text/search' ; $ required = array ( 'product' ) ; $ total = null ; $ results = $ this -> _searchItems ( $ conn , $ search , $ cfgPathSearch , '' , $ required , $ total , $ level ) ; while ( ( $ row = $ results -> fetch ( ) ) !== false ) { $ list [ $ row [ 'prodid' ] ] = $ row [ 'value' ] ; } $ dbm -> release ( $ conn , $ dbname ) ; } catch ( Exception $ e ) { $ dbm -> release ( $ conn , $ dbname ) ; throw $ e ; } return $ list ; }
Returns product IDs and texts that matches the given criteria .
32,944
protected function _saveText ( MW_DB_Statement_Interface $ stmt , $ id , $ siteid , $ refid , $ lang , $ listtype , $ reftype , $ domain , $ content , $ date , $ editor ) { $ stmt -> bind ( 1 , $ id , MW_DB_Statement_Abstract :: PARAM_INT ) ; $ stmt -> bind ( 2 , $ siteid , MW_DB_Statement_Abstract :: PARAM_INT ) ; $ stmt -> bind ( 3 , $ refid ) ; $ stmt -> bind ( 4 , $ lang ) ; $ stmt -> bind ( 5 , $ listtype ) ; $ stmt -> bind ( 6 , $ reftype ) ; $ stmt -> bind ( 7 , $ domain ) ; $ stmt -> bind ( 8 , $ content ) ; $ stmt -> bind ( 9 , $ date ) ; $ stmt -> bind ( 10 , $ editor ) ; $ stmt -> bind ( 11 , $ date ) ; try { $ stmt -> execute ( ) -> finish ( ) ; } catch ( MW_DB_Exception $ e ) { ; } }
Saves the text record with given set of parameters .
32,945
public function _restPutResource ( $ id ) { $ oldUser = clone $ this -> model ; $ this -> model -> loadFromExternalSource ( $ this -> getApp ( ) -> getRequest ( ) -> getBody ( ) ) ; if ( ! empty ( $ this -> model -> password ) ) { if ( strlen ( $ this -> model -> password ) < 6 ) { $ this -> getApp ( ) -> returnError ( Errors :: $ SHORT_PASSWORD ) ; } $ this -> model -> passHash = Identity :: passHash ( $ this -> model -> password , $ oldUser -> salt ) ; $ this -> model -> password = NULL ; $ session = call_user_func ( $ this -> sessionModelClass . '::init' , $ this -> getApp ( ) ) ; $ deleteSessions = $ session -> findAllByField ( 'userId' , $ id ) ; foreach ( $ deleteSessions as $ session ) { if ( $ session -> sessionId == $ this -> getApp ( ) -> getRequest ( ) -> session -> sessionId ) { continue ; } $ session -> delete ( ) ; } } if ( empty ( $ this -> model -> email ) ) { $ this -> getApp ( ) -> returnError ( Errors :: $ EMAIL_REQUIRED ) ; } if ( $ this -> model -> email != $ oldUser -> email && $ this -> model -> findByField ( 'email' , $ this -> model -> email ) ) { $ this -> getApp ( ) -> returnError ( Errors :: $ EMAIL_EXISTS ) ; } $ this -> model -> created = $ oldUser -> created ; $ this -> model -> salt = $ oldUser -> salt ; $ this -> model -> lastAccessed = $ oldUser -> lastAccessed ; $ this -> model -> save ( ) ; echo $ this -> model -> outputJSON ( ) ; }
Updates a user s info . All fields will be replaced with the values given . Empty fields will be set to null .
32,946
private function normalizeEndings ( $ source , Isolator $ isolator ) { $ source = $ isolator -> isolatePHP ( preg_replace ( '/[\n\r]+/' , "\n" , $ source ) ) ; $ sourceLines = explode ( "\n" , $ source ) ; $ sourceLines = array_filter ( $ sourceLines , function ( $ line ) { return trim ( $ line ) ; } ) ; $ source = $ isolator -> repairPHP ( join ( "\n" , $ sourceLines ) ) ; $ isolator -> reset ( ) ; return $ source ; }
Remove blank lines .
32,947
private function normalizeAttributes ( $ source , HtmlTokenizer $ tokenizer ) { $ result = '' ; foreach ( $ tokenizer -> parse ( $ source ) as $ token ) { if ( empty ( $ token [ HtmlTokenizer :: TOKEN_ATTRIBUTES ] ) ) { $ result .= $ tokenizer -> compileToken ( $ token ) ; continue ; } $ attributes = [ ] ; foreach ( $ token [ HtmlTokenizer :: TOKEN_ATTRIBUTES ] as $ attribute => $ value ) { if ( in_array ( $ attribute , $ this -> options [ 'attributes' ] [ 'trim' ] ) ) { $ value = trim ( $ value ) ; } if ( empty ( $ value ) && in_array ( $ attribute , $ this -> options [ 'attributes' ] [ 'drop' ] ) ) { continue ; } $ attributes [ $ attribute ] = $ value ; } $ token [ HtmlTokenizer :: TOKEN_ATTRIBUTES ] = $ attributes ; $ result .= $ tokenizer -> compileToken ( $ token ) ; } return $ result ; }
Normalize attribute values .
32,948
protected function _process ( array $ stmts ) { $ this -> _msg ( 'Migrating "Complete" to "BasketLimits" plugin' , 0 ) ; $ this -> _status ( '' ) ; if ( $ this -> _schema -> columnExists ( 'mshop_plugin' , 'config' ) === true && $ this -> _schema -> columnExists ( 'mshop_plugin' , 'provider' ) === true ) { foreach ( $ stmts as $ key => $ list ) { $ this -> _msg ( sprintf ( 'Migrating "%1$s"' , $ key ) , 1 ) ; if ( $ this -> _getValue ( $ list [ 'select' ] , 'cnt' ) > 0 ) { $ this -> _execute ( $ list [ 'update' ] ) ; $ this -> _status ( 'migrated' ) ; } else { $ this -> _status ( 'OK' ) ; } } } }
Migrates Complete plugin if necessary .
32,949
protected function _process ( ) { $ this -> _msg ( 'Adding catalog promotion performance data' , 0 ) ; $ context = $ this -> _getContext ( ) ; $ catalogManager = MShop_Catalog_Manager_Factory :: createManager ( $ context ) ; $ catalogListManager = $ catalogManager -> getSubManager ( 'list' ) ; $ catalogListTypeManager = $ catalogListManager -> getSubManager ( 'type' ) ; $ search = $ catalogListTypeManager -> createSearch ( ) ; $ expr = array ( $ search -> compare ( '==' , 'catalog.list.type.domain' , 'product' ) , $ search -> compare ( '==' , 'catalog.list.type.code' , 'promotion' ) , ) ; $ search -> setConditions ( $ search -> combine ( '&&' , $ expr ) ) ; $ types = $ catalogListTypeManager -> searchItems ( $ search ) ; if ( ( $ typeItem = reset ( $ types ) ) === false ) { throw new Exception ( 'Catalog list type item not found' ) ; } $ search = $ catalogManager -> createSearch ( ) ; $ search -> setSortations ( array ( $ search -> sort ( '+' , 'catalog.level' ) , $ search -> sort ( '+' , 'catalog.left' ) ) ) ; $ listItem = $ catalogListManager -> createItem ( ) ; $ listItem -> setTypeId ( $ typeItem -> getId ( ) ) ; $ listItem -> setDomain ( 'product' ) ; $ start = 0 ; do { $ this -> _txBegin ( ) ; $ result = $ catalogManager -> searchItems ( $ search ) ; foreach ( $ result as $ catId => $ catItem ) { $ pos = 0 ; $ search = $ catalogListManager -> createSearch ( ) ; $ expr = array ( $ search -> compare ( '==' , 'catalog.list.parentid' , $ catId ) , $ search -> compare ( '==' , 'catalog.list.position' , array ( 20 , 40 , 60 , 80 ) ) , $ search -> compare ( '==' , 'catalog.list.domain' , 'product' ) , $ search -> compare ( '==' , 'catalog.list.type.code' , 'default' ) , ) ; $ search -> setConditions ( $ search -> combine ( '&&' , $ expr ) ) ; foreach ( $ catalogListManager -> searchItems ( $ search ) as $ item ) { $ listItem -> setId ( null ) ; $ listItem -> setParentId ( $ item -> getParentId ( ) ) ; $ listItem -> setRefId ( $ item -> getRefId ( ) ) ; $ listItem -> setPosition ( $ pos ++ ) ; $ catalogListManager -> saveItem ( $ listItem , false ) ; } } $ count = count ( $ result ) ; $ start += $ count ; $ search -> setSlice ( $ start ) ; $ this -> _txCommit ( ) ; } while ( $ count == $ search -> getSliceSize ( ) ) ; $ this -> _status ( 'done' ) ; }
Inserts catalog promotion products .
32,950
public function setSupplierCode ( $ suppliercode ) { if ( $ suppliercode == $ this -> getSupplierCode ( ) ) { return ; } $ this -> _values [ 'suppliercode' ] = ( string ) $ suppliercode ; $ this -> setModified ( ) ; }
Sets the new supplier code of the product item .
32,951
public function updateStream ( $ path , $ resource , Config $ config ) { $ size = Util :: getStreamSize ( $ resource ) ; list ( $ ret , $ err ) = Qiniu_RS_Rput ( $ this -> getClient ( ) , $ this -> bucket , $ path , $ resource , $ size , null ) ; if ( $ err !== null ) { return false ; } return compact ( 'size' , 'path' ) ; }
Update a file using a stream
32,952
public function listContents ( $ directory = '' , $ recursive = false ) { $ files = [ ] ; foreach ( $ this -> listDirContents ( $ directory ) as $ k => $ file ) { $ pathInfo = pathinfo ( $ file [ 'key' ] ) ; $ files [ ] = array_merge ( $ pathInfo , $ this -> normalizeData ( $ file ) , [ 'type' => isset ( $ pathInfo [ 'extension' ] ) ? 'file' : 'dir' , ] ) ; } return $ files ; }
List contents of a directory
32,953
public function getMetadata ( $ path ) { list ( $ ret , $ err ) = Qiniu_RS_Stat ( $ this -> getClient ( ) , $ this -> bucket , $ path ) ; if ( $ err !== null ) { return false ; } $ ret [ 'key' ] = $ path ; return $ this -> normalizeData ( $ ret ) ; }
Get the metadata of a file
32,954
public function initialize ( DataProviderInterface $ dataProvider ) { $ this -> dataProvider = $ dataProvider ; $ contextConfiguration = [ 'workspaceName' => 'live' , 'invisibleContentShown' => true ] ; $ context = $ this -> contextFactory -> create ( $ contextConfiguration ) ; $ this -> rootNode = $ context -> getRootNode ( ) ; $ this -> applyOption ( $ this -> storageNodeNodePath , 'storageNodeNodePath' ) ; $ this -> applyOption ( $ this -> nodeTypeName , 'nodeTypeName' ) ; if ( isset ( $ this -> options [ 'siteNodePath' ] ) || isset ( $ this -> options [ 'siteNodeIdentifier' ] ) ) { $ siteNodePath = isset ( $ this -> options [ 'siteNodePath' ] ) ? trim ( $ this -> options [ 'siteNodePath' ] ) : null ; $ siteNodeIdentifier = isset ( $ this -> options [ 'siteNodeIdentifier' ] ) ? trim ( $ this -> options [ 'siteNodeIdentifier' ] ) : null ; $ this -> siteNode = $ this -> rootNode -> getNode ( $ siteNodePath ) ? : $ context -> getNodeByIdentifier ( $ siteNodeIdentifier ) ; if ( $ this -> siteNode === null ) { throw new Exception ( sprintf ( 'Site node not found (%s)' , $ siteNodePath ? : $ siteNodeIdentifier ) , 1425077201 ) ; } } else { $ this -> log ( get_class ( $ this ) . ': siteNodePath is not defined. Please make sure to set the target siteNodePath in your importer options.' , LOG_WARNING ) ; } }
Initialize import context
32,955
public function process ( ) { $ this -> initializeStorageNode ( $ this -> storageNodeNodePath , $ this -> storageNodeTitle ) ; $ this -> initializeNodeTemplates ( ) ; $ nodeTemplate = new NodeTemplate ( ) ; $ this -> processBatch ( $ nodeTemplate ) ; }
Starts batch processing all commands
32,956
protected function processBatch ( NodeTemplate $ nodeTemplate = null ) { $ records = $ this -> dataProvider -> fetch ( ) ; if ( ! \ is_iterable ( $ records ) ) { throw new Exception ( sprintf ( 'Expected records as an array while calling %s->fetch(), but returned %s instead.' , get_class ( $ this -> dataProvider ) , gettype ( $ records ) ) , 1462960769826 ) ; } $ records = $ this -> preProcessing ( $ records ) ; foreach ( $ records as $ data ) { if ( ! \ is_array ( $ data ) ) { $ data = $ this -> propertyMapper -> convert ( $ data , 'array' ) ; } $ this -> processRecord ( $ nodeTemplate , $ data ) ; ++ $ this -> processedRecords ; } $ this -> postProcessing ( $ records ) ; }
Import data from the given data provider
32,957
public function processRecord ( NodeTemplate $ nodeTemplate , array $ data ) { $ this -> unsetAllNodeTemplateProperties ( $ nodeTemplate ) ; $ externalIdentifier = $ this -> getExternalIdentifierFromRecordData ( $ data ) ; $ nodeName = $ this -> renderNodeName ( $ externalIdentifier ) ; if ( ! isset ( $ data [ 'uriPathSegment' ] ) ) { $ data [ 'uriPathSegment' ] = Slug :: create ( $ this -> getLabelFromRecordData ( $ data ) ) -> getValue ( ) ; } $ recordMapping = $ this -> getNodeProcessing ( $ externalIdentifier ) ; if ( $ recordMapping !== null ) { $ node = $ this -> storageNode -> getContext ( ) -> getNodeByIdentifier ( $ recordMapping -> getNodeIdentifier ( ) ) ; if ( $ node === null ) { throw new \ Exception ( sprintf ( 'Failed retrieving existing node for update. External identifier: %s Node identifier: %s. Maybe the record mapping in the database does not match the existing (imported) nodes anymore.' , $ externalIdentifier , $ recordMapping -> getNodeIdentifier ( ) ) , 1462971366085 ) ; } $ this -> applyProperties ( $ this -> getPropertiesFromDataProviderPayload ( $ data ) , $ node ) ; } else { $ nodeTemplate -> setNodeType ( $ this -> nodeType ) ; $ nodeTemplate -> setName ( $ nodeName ) ; $ this -> applyProperties ( $ this -> getPropertiesFromDataProviderPayload ( $ data ) , $ nodeTemplate ) ; $ node = $ this -> createNodeFromTemplate ( $ nodeTemplate , $ data ) ; $ this -> registerNodeProcessing ( $ node , $ externalIdentifier ) ; } $ this -> dimensionsImporter -> process ( $ node , $ this -> getPropertiesFromDataProviderPayload ( $ data ) , $ this -> currentEvent ) ; return $ node ; }
Processes a single record
32,958
protected function log ( $ message , $ severity = LOG_INFO ) { if ( ! isset ( $ this -> severityLabels [ $ severity ] ) ) { throw new Exception ( 'Invalid severity value' , 1426868867 ) ; } $ this -> importService -> addEventMessage ( sprintf ( 'Record:Import:Log:%s' , $ this -> severityLabels [ $ severity ] ) , $ message , $ severity , $ this -> currentEvent ) ; }
Create an entry in the event log
32,959
protected function renderNodeName ( $ externalIdentifier ) { return Slug :: create ( ( $ this -> nodeNamePrefix !== null ? $ this -> nodeNamePrefix : uniqid ( ) ) . $ externalIdentifier ) -> getValue ( ) ; }
Render a valid node name for a new Node based on the current record
32,960
public static function getContainer ( $ resourcepath , $ type , $ format , array $ options = array ( ) ) { if ( ctype_alnum ( $ type ) === false ) { $ classname = is_string ( $ type ) ? 'MW_Container_' . $ type : '<not a string>' ; throw new MW_Container_Exception ( sprintf ( 'Invalid characters in class name "%1$s"' , $ classname ) ) ; } $ iface = 'MW_Container_Interface' ; $ classname = 'MW_Container_' . $ type ; if ( class_exists ( $ classname ) === false ) { throw new MW_Container_Exception ( sprintf ( 'Class "%1$s" not available' , $ classname ) ) ; } $ object = new $ classname ( $ resourcepath , $ format , $ options ) ; if ( ! ( $ object instanceof $ iface ) ) { throw new MW_Container_Exception ( sprintf ( 'Class "%1$s" does not implement interface "%2$s"' , $ classname , $ iface ) ) ; } return $ object ; }
Opens an existing container or creates a new one .
32,961
public function setProducts ( array $ products ) { MW_Common_Abstract :: checkClassList ( 'MShop_Order_Item_Base_Product_Interface' , $ products ) ; $ this -> _products = $ products ; $ this -> setModified ( ) ; }
Sets a array of order base product items
32,962
public function setProductId ( $ id ) { if ( $ id == $ this -> getProductId ( ) ) { return ; } $ this -> _values [ 'prodid' ] = ( string ) $ id ; $ this -> setModified ( ) ; }
Sets the ID of a product the customer has selected .
32,963
public function setProductCode ( $ code ) { $ this -> _checkCode ( $ code ) ; if ( $ code == $ this -> getProductCode ( ) ) { return ; } $ this -> _values [ 'prodcode' ] = ( string ) $ code ; $ this -> setModified ( ) ; }
Sets the code of a product the customer has selected .
32,964
public function setWarehouseCode ( $ code ) { $ this -> _checkCode ( $ code ) ; if ( $ code == $ this -> getWarehouseCode ( ) ) { return ; } $ this -> _values [ 'warehousecode' ] = ( string ) $ code ; $ this -> setModified ( ) ; }
Sets the code of the warehouse the product should be retrieved from .
32,965
public function setName ( $ value ) { if ( $ value == $ this -> getName ( ) ) { return ; } $ this -> _values [ 'name' ] = ( string ) $ value ; $ this -> setModified ( ) ; }
Sets the localized name of the product .
32,966
public function setQuantity ( $ quantity ) { if ( ! is_numeric ( $ quantity ) ) { throw new MShop_Order_Exception ( 'Quantity is invalid. Please enter a positive integer' ) ; } $ quantity = ( int ) $ quantity ; if ( $ quantity == $ this -> getQuantity ( ) ) { return ; } if ( $ quantity < 1 || $ quantity > 2147483647 ) { throw new MShop_Order_Exception ( sprintf ( 'Quantity must be a positive integer and must not exceed %1$d' , 2147483647 ) ) ; } $ this -> _values [ 'quantity' ] = $ quantity ; $ this -> setModified ( ) ; }
Sets the amount of products the customer has added .
32,967
public function getSumPrice ( ) { $ price = clone $ this -> _price ; $ price -> setValue ( $ price -> getValue ( ) * $ this -> _values [ 'quantity' ] ) ; $ price -> setCosts ( $ price -> getCosts ( ) * $ this -> _values [ 'quantity' ] ) ; $ price -> setRebate ( $ price -> getRebate ( ) * $ this -> _values [ 'quantity' ] ) ; return $ price ; }
Returns the price item for the product whose values are multiplied with the quantity .
32,968
public function setFlags ( $ value ) { if ( $ value == $ this -> getFlags ( ) ) { return ; } $ this -> _checkFlags ( $ value ) ; $ this -> _values [ 'flags' ] = ( int ) $ value ; $ this -> setModified ( ) ; }
Sets the new value for the product item flags .
32,969
public function setPosition ( $ value ) { if ( $ value == $ this -> getPosition ( ) ) { return ; } if ( $ value !== null && $ value < 1 ) { throw new MShop_Order_Exception ( sprintf ( 'Order product position "%1$s" must be greater than 0' , $ value ) ) ; } $ this -> _values [ 'pos' ] = ( $ value !== null ? ( int ) $ value : null ) ; $ this -> setModified ( ) ; }
Sets the position of the product within the list of ordered products .
32,970
public function setAttributes ( array $ attributes ) { MW_Common_Abstract :: checkClassList ( 'MShop_Order_Item_Base_Product_Attribute_Interface' , $ attributes ) ; $ this -> _attributes = $ attributes ; $ this -> _attributesMap = null ; $ this -> setModified ( ) ; }
Sets the new list of attribute items for the product .
32,971
public function toArray ( ) { $ list = parent :: toArray ( ) ; $ list [ 'order.base.product.baseid' ] = $ this -> getBaseId ( ) ; $ list [ 'order.base.product.ordprodid' ] = $ this -> getOrderProductId ( ) ; $ list [ 'order.base.product.type' ] = $ this -> getType ( ) ; $ list [ 'order.base.product.suppliercode' ] = $ this -> getSupplierCode ( ) ; $ list [ 'order.base.product.productid' ] = $ this -> getProductId ( ) ; $ list [ 'order.base.product.prodcode' ] = $ this -> getProductCode ( ) ; $ list [ 'order.base.product.name' ] = $ this -> getName ( ) ; $ list [ 'order.base.product.mediaurl' ] = $ this -> getMediaUrl ( ) ; $ list [ 'order.base.product.position' ] = $ this -> getPosition ( ) ; $ list [ 'order.base.product.price' ] = $ this -> _price -> getValue ( ) ; $ list [ 'order.base.product.costs' ] = $ this -> _price -> getCosts ( ) ; $ list [ 'order.base.product.rebate' ] = $ this -> _price -> getRebate ( ) ; $ list [ 'order.base.product.taxrate' ] = $ this -> _price -> getTaxRate ( ) ; $ list [ 'order.base.product.quantity' ] = $ this -> getQuantity ( ) ; $ list [ 'order.base.product.status' ] = $ this -> getStatus ( ) ; $ list [ 'order.base.product.flags' ] = $ this -> getFlags ( ) ; return $ list ; }
Returns the item values as associative list .
32,972
public function compare ( MShop_Order_Item_Base_Product_Interface $ item ) { if ( $ this -> getFlags ( ) === $ item -> getFlags ( ) && $ this -> getName ( ) === $ item -> getName ( ) && $ this -> getProductCode ( ) === $ item -> getProductCode ( ) && $ this -> getSupplierCode ( ) === $ item -> getSupplierCode ( ) && $ this -> getPrice ( ) -> compare ( $ item -> getPrice ( ) ) === true ) { return true ; } return false ; }
Compares the properties of the given order product item with its own ones .
32,973
public function copyFrom ( MShop_Product_Item_Interface $ product ) { $ this -> setName ( $ product -> getName ( ) ) ; $ this -> setType ( $ product -> getType ( ) ) ; $ this -> setSupplierCode ( $ product -> getSupplierCode ( ) ) ; $ this -> setProductCode ( $ product -> getCode ( ) ) ; $ this -> setProductId ( $ product -> getId ( ) ) ; $ items = $ product -> getRefItems ( 'media' , 'default' , 'default' ) ; if ( ( $ item = reset ( $ items ) ) !== false ) { $ this -> setMediaUrl ( $ item -> getUrl ( ) ) ; } $ this -> setModified ( ) ; }
Copys all data from a given product item .
32,974
static public function clear ( $ id = null , $ path = null ) { if ( $ id !== null ) { if ( $ path !== null ) { self :: $ _managers [ $ id ] [ $ path ] = null ; } else { self :: $ _managers [ $ id ] = array ( ) ; } return ; } self :: $ _managers = array ( ) ; }
Removes all manager objects from the cache .
32,975
static public function createManager ( MShop_Context_Item_Interface $ context , $ path ) { if ( empty ( $ path ) ) { throw new MAdmin_Exception ( sprintf ( 'Manager path is empty' ) ) ; } $ id = ( string ) $ context ; if ( ! isset ( self :: $ _managers [ $ id ] [ $ path ] ) ) { $ parts = explode ( '/' , $ path ) ; foreach ( $ parts as $ part ) { if ( ctype_alnum ( $ part ) === false ) { throw new MAdmin_Exception ( sprintf ( 'Invalid characters in manager name "%1$s" in "%2$s"' , $ part , $ path ) ) ; } } if ( ( $ name = array_shift ( $ parts ) ) === null ) { throw new MAdmin_Exception ( sprintf ( 'Manager path "%1$s" is invalid' , $ path ) ) ; } if ( ! isset ( self :: $ _managers [ $ id ] [ $ name ] ) ) { $ factory = 'MAdmin_' . ucwords ( $ name ) . '_Manager_Factory' ; if ( class_exists ( $ factory ) === false ) { throw new MAdmin_Exception ( sprintf ( 'Class "%1$s" not available' , $ factory ) ) ; } $ manager = @ call_user_func_array ( array ( $ factory , 'createManager' ) , array ( $ context ) ) ; if ( $ manager === false ) { throw new MAdmin_Exception ( sprintf ( 'Invalid factory "%1$s"' , $ factory ) ) ; } self :: $ _managers [ $ id ] [ $ name ] = $ manager ; } foreach ( $ parts as $ part ) { $ tmpname = $ name . '/' . $ part ; if ( ! isset ( self :: $ _managers [ $ id ] [ $ tmpname ] ) ) { self :: $ _managers [ $ id ] [ $ tmpname ] = self :: $ _managers [ $ id ] [ $ name ] -> getSubManager ( $ part ) ; } $ name = $ tmpname ; } } return self :: $ _managers [ $ id ] [ $ path ] ; }
Creates the required manager specified by the given path of manager names .
32,976
public function appendData ( string $ data ) : self { if ( empty ( $ this -> nodes ) ) { $ prevHash = $ this -> firstPrevHash ; } else { $ last = $ this -> getLastNode ( ) ; $ prevHash = $ last -> getHash ( true ) ; } $ newNode = new Node ( $ data , $ prevHash ) ; $ this -> nodes [ ] = $ newNode ; SodiumCompat :: crypto_generichash_update ( $ this -> summaryHashState , $ newNode -> getHash ( true ) ) ; return $ this ; }
Append a new Node .
32,977
public function getSummaryHash ( bool $ rawBinary = false ) : string { $ len = Util :: strlen ( $ this -> summaryHashState ) ; $ pattern = \ random_bytes ( $ len ) ; $ tmp = $ pattern ^ $ this -> summaryHashState ; $ finalHash = SodiumCompat :: crypto_generichash_final ( $ this -> summaryHashState ) ; $ this -> summaryHashState = $ tmp ^ $ pattern ; if ( $ rawBinary ) { return $ finalHash ; } return Base64UrlSafe :: encode ( $ finalHash ) ; }
Get the summary hash
32,978
public function getSummaryHashState ( bool $ rawBinary = false ) : string { if ( $ rawBinary ) { return '' . $ this -> summaryHashState ; } return Base64UrlSafe :: encode ( $ this -> summaryHashState ) ; }
Get a string representing the internals of a crypto_generichash state .
32,979
public function process ( DateTime $ startDate , DateTime $ endDate , DateTime $ cycleDate ) { $ this -> logger -> info ( 'Control Mirakl Settings' , array ( 'miraklId' => null , "action" => "Operations creation" ) ) ; $ boolControl = $ this -> getControlMiraklSettings ( $ this -> documentTypes ) ; if ( $ boolControl === false ) { $ title = $ this -> criticalMessageMiraklSettings ; $ message = $ this -> formatNotification -> formatMessage ( $ title ) ; $ this -> logger -> critical ( $ message , array ( 'miraklId' => null , "action" => "Operations creation" ) ) ; } else { $ this -> logger -> info ( 'Control Mirakl Settings OK' , array ( 'miraklId' => null , "action" => "Operations creation" ) ) ; } $ this -> logger -> info ( 'Cashout Initializer' , array ( 'miraklId' => null , "action" => "Operations creation" ) ) ; $ this -> logger -> info ( 'Fetch invoices documents from Mirakl from ' . $ startDate -> format ( 'Y-m-d H:i' ) . ' to ' . $ endDate -> format ( 'Y-m-d H:i' ) , array ( 'miraklId' => null , "action" => "Operations creation" ) ) ; $ invoices = $ this -> getInvoices ( $ startDate , $ endDate ) ; $ this -> logger -> info ( '[OK] Fetched ' . count ( $ invoices ) . ' invoices' , array ( 'miraklId' => null , "action" => "Operations creation" ) ) ; $ this -> logger -> info ( 'Process invoices' , array ( 'miraklId' => null , "action" => "Operations creation" ) ) ; $ operations = $ this -> processInvoices ( $ invoices , $ cycleDate ) ; $ this -> saveOperations ( $ operations ) ; }
Main processing function Generate and save operations .
32,980
public function isOperationValid ( OperationInterface $ operation ) { if ( $ this -> operationManager -> findByMiraklIdAndPaymentVoucherNumber ( $ operation -> getMiraklId ( ) , $ operation -> getPaymentVoucher ( ) ) ) { throw new AlreadyCreatedOperationException ( $ operation ) ; } if ( ! $ this -> operationManager -> isValid ( $ operation ) ) { throw new InvalidOperationException ( $ operation ) ; } ModelValidator :: validate ( $ operation ) ; return true ; }
Validate an operation
32,981
private function saveAdjustedOperations ( array $ adjustedOperations ) { foreach ( $ adjustedOperations as $ op ) { $ op -> setStatus ( new Status ( Status :: ADJUSTED_OPERATIONS ) ) ; $ this -> operationManager -> save ( $ op ) ; $ this -> logOperation ( $ op -> getMiraklId ( ) , $ op -> getPaymentVoucher ( ) , Status :: ADJUSTED_OPERATIONS , "" ) ; } }
Set adjusted operations to the right status
32,982
private function getAdjustedAmount ( $ originAmount , $ vendor ) { $ adjustedOperations = array ( ) ; $ adjustedOperationsIds = array ( ) ; $ negativeOperations = $ this -> operationManager -> findNegativeOperations ( $ vendor -> getHipayId ( ) ) ; foreach ( $ negativeOperations as $ nop ) { if ( ! in_array ( $ nop , $ this -> adjustedOperations ) && $ originAmount + $ nop -> getAmount ( ) > 0 ) { $ originAmount += $ nop -> getAmount ( ) ; $ adjustedOperations [ ] = $ nop ; $ adjustedOperationsIds [ ] = $ nop -> getId ( ) ; } } return array ( 'adjustedAmount' => $ originAmount , 'adujstedOperations' => $ adjustedOperations , 'adujstedOperationsIds' => $ adjustedOperationsIds ) ; }
Calculate adjusted amount for this invoice
32,983
private function getInvoices ( DateTime $ startDate , DateTime $ endDate ) { $ offset = Mirakl :: MIRAKL_API_MAX_PAGINATE ; $ invoicesData = $ this -> mirakl -> getInvoices ( $ startDate , $ endDate ) ; $ invoices = array_merge ( array ( ) , $ invoicesData [ 'invoices' ] ) ; $ total = $ invoicesData [ 'total_count' ] ; while ( $ total % $ offset !== $ total ) { $ invoicesData = $ this -> mirakl -> getInvoices ( $ startDate , $ endDate , Mirakl :: MIRAKL_API_MAX_PAGINATE , $ offset ) ; $ invoices = array_merge ( $ invoices , $ invoicesData [ 'invoices' ] ) ; $ offset += Mirakl :: MIRAKL_API_MAX_PAGINATE ; } return $ invoices ; }
Get invoices from Mirakl API
32,984
protected function _setValue ( array & $ attributes , $ code , $ value , $ serviceId , $ type = '' ) { if ( isset ( $ attributes [ $ code ] ) ) { $ attributes [ $ code ] -> setValue ( utf8_encode ( $ value ) ) ; return ; } $ attributeManager = MShop_Factory :: createManager ( $ this -> _getContext ( ) , 'order/base/service/attribute' ) ; $ item = $ attributeManager -> createItem ( ) ; $ item -> setType ( $ type ) ; $ item -> setCode ( $ code ) ; $ item -> setValue ( utf8_encode ( $ value ) ) ; $ item -> setServiceId ( $ serviceId ) ; $ attributes [ $ code ] = $ item ; }
Sets or adds a attribute value to the list of service payment items .
32,985
public function setLabel ( $ value ) { if ( $ value == $ this -> getLabel ( ) ) { return ; } $ this -> _values [ 'label' ] = ( string ) $ value ; $ this -> setModified ( ) ; }
Sets the new label of the customer item .
32,986
public function setStatus ( $ value ) { if ( $ value == $ this -> getStatus ( ) ) { return ; } $ this -> _values [ 'status' ] = ( int ) $ value ; $ this -> setModified ( ) ; }
Sets the status of the item .
32,987
public function setPaymentAddress ( MShop_Common_Item_Address_Interface $ address ) { if ( $ address === $ this -> _billingaddress && $ address -> isModified ( ) === false ) { return ; } $ this -> _billingaddress = $ address ; $ this -> setModified ( ) ; }
Sets the billingaddress of the customer item .
32,988
public function setBirthday ( $ value ) { if ( $ value === $ this -> getBirthday ( ) ) { return ; } if ( $ value !== null ) { $ this -> _checkDateOnlyFormat ( $ value ) ; $ value = ( string ) $ value ; } $ this -> _values [ 'birthday' ] = $ value ; $ this -> setModified ( ) ; }
Sets the birthday of the customer item .
32,989
public function setDateVerified ( $ value ) { if ( $ value === $ this -> getDateVerified ( ) ) { return ; } $ this -> _checkDateOnlyFormat ( $ value ) ; $ this -> _values [ 'vdate' ] = ( $ value ? ( string ) $ value : null ) ; $ this -> setModified ( ) ; }
Sets the latest verification date of the customer .
32,990
public function getCMSFields ( ) { $ this -> beforeUpdateCMSFields ( function ( $ fields ) { $ main = $ fields -> findOrMakeTab ( "Root.Main" ) ; $ details = null ; $ enddate_field = $ fields -> dataFieldByName ( "EndDate" ) ; $ enddate_field -> setTitle ( _t ( "OrdersAdmin.Due" , "Due" ) ) ; foreach ( $ main -> getChildren ( ) as $ field ) { if ( $ field -> getName ( ) == "OrdersDetails" ) { foreach ( $ field -> getChildren ( ) as $ field ) { if ( $ field -> getName ( ) == "OrdersDetailsInfo" ) { $ details = $ field ; } } } } if ( $ details ) { $ details -> insertBefore ( "StartDate" , DropdownField :: create ( 'Status' , null , $ this -> config ( ) -> get ( "statuses" ) ) ) ; } } ) ; return parent :: getCMSFields ( ) ; }
Scaffold admin form feilds
32,991
public function canEdit ( $ member = null ) { $ extended = $ this -> extendedCan ( __FUNCTION__ , $ member ) ; if ( $ extended !== null ) { return $ extended ; } if ( ! $ member ) { $ member = Member :: currentUser ( ) ; } if ( $ member && Permission :: checkMember ( $ member -> ID , [ "ADMIN" , "ORDERS_EDIT_INVOICES" ] ) && in_array ( $ this -> Status , $ this -> config ( ) -> editable_statuses ) ) { return true ; } return false ; }
Only users with EDIT admin rights can view an order
32,992
public function addProduct ( $ prodid , $ quantity = 1 , array $ options = array ( ) , array $ variantAttributeIds = array ( ) , array $ configAttributeIds = array ( ) , array $ hiddenAttributeIds = array ( ) , $ warehouse = 'default' ) { $ this -> _checkCategory ( $ prodid ) ; $ context = $ this -> _getContext ( ) ; $ productManager = MShop_Factory :: createManager ( $ context , 'product' ) ; $ productItem = $ productManager -> getItem ( $ prodid , array ( 'media' , 'price' , 'product' , 'text' ) ) ; $ orderBaseProductItem = MShop_Factory :: createManager ( $ context , 'order/base/product' ) -> createItem ( ) ; $ orderBaseProductItem -> copyFrom ( $ productItem ) ; $ orderBaseProductItem -> setQuantity ( $ quantity ) ; $ orderBaseProductItem -> setWarehouseCode ( $ warehouse ) ; $ attr = array ( ) ; $ prices = $ productItem -> getRefItems ( 'price' , 'default' , 'default' ) ; switch ( $ productItem -> getType ( ) ) { case 'select' : $ attr = $ this -> _getVariantDetails ( $ orderBaseProductItem , $ productItem , $ prices , $ variantAttributeIds , $ options ) ; break ; case 'bundle' : $ this -> _addBundleProducts ( $ orderBaseProductItem , $ productItem , $ variantAttributeIds , $ warehouse ) ; break ; } $ priceManager = MShop_Factory :: createManager ( $ context , 'price' ) ; $ price = $ priceManager -> getLowestPrice ( $ prices , $ quantity ) ; $ attr = array_merge ( $ attr , $ this -> _createOrderProductAttributes ( $ price , $ prodid , $ quantity , $ configAttributeIds , 'config' ) ) ; $ attr = array_merge ( $ attr , $ this -> _createOrderProductAttributes ( $ price , $ prodid , $ quantity , $ hiddenAttributeIds , 'hidden' ) ) ; $ price -> setRebate ( '0.00' ) ; $ orderBaseProductItem -> setPrice ( $ price ) ; $ orderBaseProductItem -> setAttributes ( $ attr ) ; $ this -> _addProductInStock ( $ orderBaseProductItem , $ productItem -> getId ( ) , $ quantity , $ options , $ warehouse ) ; }
Adds a categorized product to the basket of the user stored in the session .
32,993
public function setAddress ( $ type , $ value ) { $ address = MShop_Factory :: createManager ( $ this -> _getContext ( ) , 'order/base/address' ) -> createItem ( ) ; $ address -> setType ( $ type ) ; if ( $ value instanceof MShop_Common_Item_Address_Interface ) { $ address -> copyFrom ( $ value ) ; $ this -> _basket -> setAddress ( $ address , $ type ) ; } else if ( is_array ( $ value ) ) { $ this -> _setAddressFromArray ( $ address , $ value ) ; $ this -> _basket -> setAddress ( $ address , $ type ) ; } else if ( $ value === null ) { $ this -> _basket -> deleteAddress ( $ type ) ; } else { throw new Controller_Frontend_Basket_Exception ( sprintf ( 'Invalid value for address type "%1$s"' , $ type ) ) ; } $ this -> _domainManager -> setSession ( $ this -> _basket ) ; }
Sets the address of the customer in the basket .
32,994
protected function _checkCategory ( $ prodid ) { $ catalogListManager = MShop_Factory :: createManager ( $ this -> _getContext ( ) , 'catalog/list' ) ; $ search = $ catalogListManager -> createSearch ( true ) ; $ expr = array ( $ search -> compare ( '==' , 'catalog.list.refid' , $ prodid ) , $ search -> getConditions ( ) ) ; $ search -> setConditions ( $ search -> combine ( '&&' , $ expr ) ) ; $ search -> setSlice ( 0 , 1 ) ; $ result = $ catalogListManager -> searchItems ( $ search ) ; if ( reset ( $ result ) === false ) { $ msg = sprintf ( 'Adding product with ID "%1$s" is not allowed' , $ prodid ) ; throw new Controller_Frontend_Basket_Exception ( $ msg ) ; } }
Checks if the product is part of at least one category in the product catalog .
32,995
protected function _checkReferences ( $ prodId , $ domain , $ listTypeId , array $ refIds ) { $ productManager = MShop_Factory :: createManager ( $ this -> _getContext ( ) , 'product' ) ; $ search = $ productManager -> createSearch ( true ) ; $ expr = array ( $ search -> compare ( '==' , 'product.id' , $ prodId ) , $ search -> getConditions ( ) , ) ; if ( count ( $ refIds ) > 0 ) { $ param = array ( $ domain , $ listTypeId , $ refIds ) ; $ cmpfunc = $ search -> createFunction ( 'product.contains' , $ param ) ; $ expr [ ] = $ search -> compare ( '==' , $ cmpfunc , count ( $ refIds ) ) ; } $ search -> setConditions ( $ search -> combine ( '&&' , $ expr ) ) ; if ( count ( $ productManager -> searchItems ( $ search , array ( ) ) ) === 0 ) { $ msg = sprintf ( 'Invalid "%1$s" references for product with ID "%2$s"' , $ domain , $ prodId ) ; throw new Controller_Frontend_Basket_Exception ( $ msg ) ; } }
Checks if the IDs of the given items are really associated to the product .
32,996
protected function _getStockLevel ( $ prodid , $ warehouse ) { $ manager = MShop_Factory :: createManager ( $ this -> _getContext ( ) , 'product/stock' ) ; $ search = $ manager -> createSearch ( true ) ; $ expr = array ( $ search -> compare ( '==' , 'product.stock.productid' , $ prodid ) , $ search -> getConditions ( ) , $ search -> compare ( '==' , 'product.stock.warehouse.code' , $ warehouse ) , ) ; $ search -> setConditions ( $ search -> combine ( '&&' , $ expr ) ) ; $ result = $ manager -> searchItems ( $ search ) ; if ( empty ( $ result ) ) { $ msg = sprintf ( 'No stock for product ID "%1$s" and warehouse "%2$s" available' , $ prodid , $ warehouse ) ; throw new Controller_Frontend_Basket_Exception ( $ msg ) ; } $ stocklevel = null ; foreach ( $ result as $ item ) { if ( ( $ stock = $ item -> getStockLevel ( ) ) === null ) { return null ; } $ stocklevel = max ( ( int ) $ stocklevel , $ item -> getStockLevel ( ) ) ; } return $ stocklevel ; }
Returns the highest stock level for the product .
32,997
protected function _createOrderProductAttributes ( MShop_Price_Item_Interface $ price , $ prodid , $ quantity , array $ attributeIds , $ type ) { if ( empty ( $ attributeIds ) ) { return array ( ) ; } $ attrTypeId = $ this -> _getProductListTypeItem ( 'attribute' , $ type ) -> getId ( ) ; $ this -> _checkReferences ( $ prodid , 'attribute' , $ attrTypeId , $ attributeIds ) ; $ list = array ( ) ; $ context = $ this -> _getContext ( ) ; $ priceManager = MShop_Factory :: createManager ( $ context , 'price' ) ; $ orderProductAttributeManager = MShop_Factory :: createManager ( $ context , 'order/base/product/attribute' ) ; foreach ( $ this -> _getAttributes ( $ attributeIds ) as $ attrItem ) { $ prices = $ attrItem -> getRefItems ( 'price' , 'default' , 'default' ) ; if ( ! empty ( $ prices ) ) { $ price -> addItem ( $ priceManager -> getLowestPrice ( $ prices , $ quantity ) ) ; } $ item = $ orderProductAttributeManager -> createItem ( ) ; $ item -> copyFrom ( $ attrItem ) ; $ item -> setType ( $ type ) ; $ list [ ] = $ item ; } return $ list ; }
Creates the order product attribute items from the given attribute IDs and updates the price item if necessary .
32,998
protected function _setAddressFromArray ( MShop_Order_Item_Base_Address_Interface $ address , array $ map ) { foreach ( $ map as $ key => $ value ) { $ map [ $ key ] = strip_tags ( $ value ) ; } $ errors = $ address -> fromArray ( $ map ) ; if ( count ( $ errors ) > 0 ) { $ msg = sprintf ( 'Invalid address properties, please check your input' ) ; throw new Controller_Frontend_Basket_Exception ( $ msg , 0 , null , $ errors ) ; } }
Fills the order address object with the values from the array .
32,999
protected function _getProductItem ( $ code ) { $ productManager = MShop_Factory :: createManager ( $ this -> _getContext ( ) , 'product' ) ; $ search = $ productManager -> createSearch ( true ) ; $ expr = array ( $ search -> compare ( '==' , 'product.code' , $ code ) , $ search -> getConditions ( ) , ) ; $ search -> setConditions ( $ search -> combine ( '&&' , $ expr ) ) ; $ result = $ productManager -> searchItems ( $ search , array ( 'price' , 'text' ) ) ; if ( ( $ productItem = reset ( $ result ) ) === false ) { $ msg = sprintf ( 'No product with code "%1$s" found' , $ code ) ; throw new Controller_Frontend_Basket_Exception ( $ msg ) ; } return $ productItem ; }
Retrieves the product item specified by the given code .