idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
55,400
protected function validateEditProductClass ( ) { $ this -> setSubmitted ( 'product_class' ) ; $ this -> setSubmittedBool ( 'status' ) ; $ this -> setSubmitted ( 'update' , $ this -> data_product_class ) ; $ this -> validateComponent ( 'product_class' ) ; return ! $ this -> hasErrors ( ) ; }
Validates a products class data
55,401
protected function deleteProductClass ( ) { $ this -> controlAccess ( 'product_class_delete' ) ; if ( $ this -> product_class -> delete ( $ this -> data_product_class [ 'product_class_id' ] ) ) { $ this -> redirect ( 'admin/content/product-class' , $ this -> text ( 'Product class has been deleted' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Product class has not been deleted' ) , 'warning' ) ; }
Deletes a product class
55,402
protected function addProductClass ( ) { $ this -> controlAccess ( 'product_class_add' ) ; if ( $ this -> product_class -> add ( $ this -> getSubmitted ( ) ) ) { $ this -> redirect ( 'admin/content/product-class' , $ this -> text ( 'Product class has been added' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Product class has not been added' ) , 'warning' ) ; }
Adds a new product class
55,403
protected function setTitleEditProductClass ( ) { if ( isset ( $ this -> data_product_class [ 'product_class_id' ] ) ) { $ title = $ this -> text ( 'Edit %name' , array ( '%name' => $ this -> data_product_class [ 'title' ] ) ) ; } else { $ title = $ this -> text ( 'Add product class' ) ; } $ this -> setTitle ( $ title ) ; }
Sets title on the edit product class page
55,404
protected function setBreadcrumbEditProductClass ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ breadcrumbs [ ] = array ( 'text' => $ this -> text ( 'Product classes' ) , 'url' => $ this -> url ( 'admin/content/product-class' ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
Sets breadcrumbs on the edit product class page
55,405
public function get ( $ order_id ) { $ result = null ; $ this -> hook -> attach ( 'order.get.before' , $ order_id , $ result , $ this ) ; if ( isset ( $ result ) ) { return $ result ; } $ conditions = array ( 'limit' => array ( 0 , 1 ) , 'order_id' => $ order_id ) ; $ list = ( array ) $ this -> getList ( $ conditions ) ; $ result = empty ( $ list ) ? array ( ) : reset ( $ list ) ; $ this -> setCart ( $ result ) ; $ this -> hook -> attach ( 'order.get.after' , $ order_id , $ result , $ this ) ; return $ result ; }
Loads an order from the database
55,406
public function update ( $ order_id , array $ data ) { $ result = null ; $ this -> hook -> attach ( 'order.update.before' , $ order_id , $ data , $ result , $ this ) ; if ( isset ( $ result ) ) { return ( bool ) $ result ; } $ data [ 'modified' ] = GC_TIME ; $ this -> prepareComponents ( $ data ) ; $ result = ( bool ) $ this -> db -> update ( 'orders' , $ data , array ( 'order_id' => $ order_id ) ) ; $ this -> hook -> attach ( 'order.update.after' , $ order_id , $ data , $ result , $ this ) ; return ( bool ) $ result ; }
Updates an order
55,407
public function getStatuses ( ) { $ statuses = & gplcart_static ( 'order.statuses' ) ; if ( isset ( $ statuses ) ) { return $ statuses ; } $ statuses = array ( 'pending' => $ this -> translation -> text ( 'Pending' ) , 'canceled' => $ this -> translation -> text ( 'Canceled' ) , 'delivered' => $ this -> translation -> text ( 'Delivered' ) , 'completed' => $ this -> translation -> text ( 'Completed' ) , 'processing' => $ this -> translation -> text ( 'Processing' ) , 'dispatched' => $ this -> translation -> text ( 'Dispatched' ) , 'pending_payment' => $ this -> translation -> text ( 'Awaiting payment' ) ) ; $ this -> hook -> attach ( 'order.statuses' , $ statuses , $ this ) ; return $ statuses ; }
Returns an array of order statuses
55,408
public function getStatusName ( $ id ) { $ statuses = $ this -> getStatuses ( ) ; return isset ( $ statuses [ $ id ] ) ? $ statuses [ $ id ] : '' ; }
Returns a status name
55,409
public function getComponentTypes ( ) { $ types = array ( 'cart' => $ this -> translation -> text ( 'Cart' ) , 'payment' => $ this -> translation -> text ( 'Payment' ) , 'shipping' => $ this -> translation -> text ( 'Shipping' ) ) ; $ this -> hook -> attach ( 'order.component.types' , $ types ) ; return $ types ; }
Returns an array of order component types
55,410
public function getComponentType ( $ name ) { $ types = $ this -> getComponentTypes ( ) ; return empty ( $ types [ $ name ] ) ? '' : $ types [ $ name ] ; }
Returns a component type name
55,411
public function calculate ( array & $ data ) { $ result = array ( ) ; $ this -> hook -> attach ( 'order.calculate.before' , $ data , $ result , $ this ) ; if ( ! empty ( $ result ) ) { return ( array ) $ result ; } $ components = array ( ) ; $ total = $ data [ 'cart' ] [ 'total' ] ; $ this -> calculateComponents ( $ total , $ data , $ components ) ; $ this -> calculatePriceRules ( $ total , $ data , $ components ) ; $ result = array ( 'total' => $ total , 'components' => $ components , 'currency' => $ data [ 'cart' ] [ 'currency' ] , 'total_decimal' => $ this -> price -> decimal ( $ total , $ data [ 'cart' ] [ 'currency' ] ) , 'total_formatted' => $ this -> price -> format ( $ total , $ data [ 'cart' ] [ 'currency' ] ) , 'total_formatted_number' => $ this -> price -> format ( $ total , $ data [ 'cart' ] [ 'currency' ] , true , false ) , ) ; $ this -> hook -> attach ( 'order.calculate.after' , $ data , $ result , $ this ) ; return ( array ) $ result ; }
Calculates order totals
55,412
public function getCompleteMessage ( array $ order ) { $ vars = array ( '@num' => $ order [ 'order_id' ] , '@status' => $ this -> getStatusName ( $ order [ 'status' ] ) ) ; if ( is_numeric ( $ order [ 'user_id' ] ) ) { $ message = $ this -> translation -> text ( 'Thank you for your order! Order ID: @num, status: @status' , $ vars ) ; } else { $ message = $ this -> translation -> text ( 'Thank you for your order! Order ID: @num, status: @status' , $ vars ) ; } $ this -> hook -> attach ( 'order.complete.message' , $ message , $ order , $ this ) ; return $ message ; }
Returns the checkout complete message
55,413
protected function calculatePriceRules ( & $ total , array & $ data , array & $ components ) { $ options = array ( 'status' => 1 , 'store_id' => $ data [ 'order' ] [ 'store_id' ] ) ; $ code = null ; if ( isset ( $ data [ 'order' ] [ 'data' ] [ 'pricerule_code' ] ) ) { $ code = $ data [ 'order' ] [ 'data' ] [ 'pricerule_code' ] ; } foreach ( $ this -> price_rule -> getTriggered ( $ data , $ options ) as $ price_rule ) { if ( $ price_rule [ 'code' ] !== '' && ! isset ( $ code ) ) { $ components [ $ price_rule [ 'price_rule_id' ] ] = array ( 'rule' => $ price_rule , 'price' => 0 ) ; continue ; } if ( isset ( $ code ) && ! $ this -> priceRuleCodeMatches ( $ price_rule [ 'price_rule_id' ] , $ code ) ) { $ components [ $ price_rule [ 'price_rule_id' ] ] = array ( 'rule' => $ price_rule , 'price' => 0 ) ; continue ; } $ this -> price_rule -> calculate ( $ total , $ data , $ components , $ price_rule ) ; } }
Calculate order price rules
55,414
protected function deleteLinked ( $ order_id ) { $ this -> db -> delete ( 'cart' , array ( 'order_id' => $ order_id ) ) ; $ this -> db -> delete ( 'order_log' , array ( 'order_id' => $ order_id ) ) ; $ this -> db -> delete ( 'history' , array ( 'entity' => 'order' , 'entity_id' => $ order_id ) ) ; }
Deletes all database records related to the order ID
55,415
protected function prepareComponents ( array & $ order ) { if ( ! empty ( $ order [ 'cart' ] [ 'items' ] ) ) { foreach ( $ order [ 'cart' ] [ 'items' ] as $ sku => $ item ) { $ price = isset ( $ item [ 'total' ] ) ? $ item [ 'total' ] : null ; $ order [ 'data' ] [ 'components' ] [ 'cart' ] [ 'items' ] [ $ sku ] [ 'price' ] = $ price ; } } }
Prepares order components
55,416
protected function deleteLinked ( $ page_id ) { $ this -> db -> delete ( 'page_translation' , array ( 'page_id' => $ page_id ) ) ; $ this -> db -> delete ( 'file' , array ( 'entity' => 'page' , 'entity_id' => $ page_id ) ) ; $ this -> db -> delete ( 'alias' , array ( 'entity' => 'page' , 'entity_id' => $ page_id ) ) ; $ sql = 'DELETE ci FROM collection_item ci INNER JOIN collection c ON(ci.collection_id = c.collection_id) WHERE c.type = ? AND ci.entity_id = ?' ; $ this -> db -> run ( $ sql , array ( 'page' , $ page_id ) ) ; }
Deletes all database records related to the page ID
55,417
public function createService ( ServiceLocatorInterface $ serviceLocator ) { if ( ! $ serviceLocator -> has ( 'ServiceListener' ) ) { $ serviceLocator -> setFactory ( 'ServiceListener' , 'PPI\Framework\ServiceManager\Factory\ServiceListenerFactory' ) ; } $ config = $ serviceLocator -> get ( 'ApplicationConfig' ) ; $ defaultListeners = $ serviceLocator -> get ( 'ModuleDefaultListener' ) ; $ serviceListener = $ serviceLocator -> get ( 'ServiceListener' ) ; $ serviceListener -> addServiceManager ( $ serviceLocator , 'service_manager' , 'Zend\ModuleManager\Feature\ServiceProviderInterface' , 'getServiceConfig' ) ; $ serviceListener -> addServiceManager ( 'RoutePluginManager' , 'route_manager' , 'Zend\ModuleManager\Feature\RouteProviderInterface' , 'getRouteConfig' ) ; $ modules = isset ( $ config [ 'modules' ] ) ? $ config [ 'modules' ] : array ( ) ; $ events = $ serviceLocator -> get ( 'EventManager' ) ; $ events -> attach ( $ defaultListeners ) ; $ events -> attach ( $ serviceListener ) ; $ moduleEvent = new ModuleEvent ( ) ; $ moduleEvent -> setParam ( 'ServiceManager' , $ serviceLocator ) ; $ moduleManager = new ModuleManager ( $ modules , $ events ) ; $ moduleManager -> setEvent ( $ moduleEvent ) ; return $ moduleManager ; }
Creates and returns the module manager .
55,418
public function id ( array $ condition ) { $ user_id = $ this -> user -> getId ( ) ; return $ this -> compare ( $ user_id , $ condition [ 'value' ] , $ condition [ 'operator' ] ) ; }
Whether the user ID condition is met
55,419
public function roleId ( array $ condition ) { $ role_id = $ this -> user -> getRoleId ( ) ; return $ this -> compare ( $ role_id , $ condition [ 'value' ] , $ condition [ 'operator' ] ) ; }
Whether the user role condition is met
55,420
public function getPath ( ) { $ controller = str_replace ( '\\' , '/' , $ this -> get ( 'controller' ) ) ; $ path = ( empty ( $ controller ) ? '' : $ controller . '/' ) . $ this -> get ( 'name' ) . '.' . $ this -> get ( 'format' ) . '.' . $ this -> get ( 'engine' ) ; return empty ( $ this -> parameters [ 'module' ] ) ? self :: APP_VIEWS_DIRECTORY . '/' . $ path : '@' . $ this -> get ( 'module' ) . '/' . self :: MODULE_VIEWS_DIRECTORY . '/' . $ path ; }
Returns the path to the template - as a path when the template is not part of a module - as a resource when the template is part of a module .
55,421
public function imageStyle ( array & $ submitted , array $ options = array ( ) ) { $ this -> options = $ options ; $ this -> submitted = & $ submitted ; $ this -> validateImageStyle ( ) ; $ this -> validateName ( ) ; $ this -> validateBool ( 'status' ) ; $ this -> validateActionsImageStyle ( ) ; $ this -> unsetSubmitted ( 'update' ) ; return $ this -> getResult ( ) ; }
Performs full image style data validation
55,422
protected function validateImageStyle ( ) { $ id = $ this -> getUpdatingId ( ) ; if ( $ id === false ) { return null ; } $ data = $ this -> image_style -> get ( $ id ) ; if ( empty ( $ data ) ) { $ this -> setErrorUnavailable ( 'update' , $ this -> translation -> text ( 'Image style' ) ) ; return false ; } $ this -> setSubmitted ( 'update' , $ data ) ; return true ; }
Validates an image style to be updated
55,423
public function validateActionsImageStyle ( ) { $ field = 'actions' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ actions = $ this -> getSubmitted ( $ field ) ; if ( $ this -> isUpdating ( ) && ! isset ( $ actions ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } $ label = $ this -> translation -> text ( 'Actions' ) ; if ( empty ( $ actions ) ) { $ this -> setErrorRequired ( $ field , $ label ) ; return false ; } if ( ! is_array ( $ actions ) ) { $ this -> setErrorInvalid ( $ field , $ label ) ; return false ; } $ modified = $ errors = array ( ) ; foreach ( $ actions as $ line => $ action ) { $ line ++ ; $ parts = gplcart_string_explode_whitespace ( $ action , 2 ) ; $ action_id = array_shift ( $ parts ) ; $ value = array_filter ( explode ( ',' , implode ( '' , $ parts ) ) ) ; if ( ! $ this -> validateActionImageStyle ( $ action_id , $ value ) ) { $ errors [ ] = $ line ; continue ; } $ modified [ $ action_id ] = array ( 'value' => $ value , 'weight' => $ line ) ; } if ( ! empty ( $ errors ) ) { $ error = $ this -> translation -> text ( 'Error in @num definition' , array ( '@num' => implode ( ',' , $ errors ) ) ) ; $ this -> setError ( $ field , $ error ) ; } if ( $ this -> isError ( ) ) { return false ; } $ this -> setSubmitted ( $ field , $ modified ) ; return true ; }
Validates image actions
55,424
protected function validateActionImageStyle ( $ action_id , array & $ value ) { $ handler = $ this -> image_style -> getActionHandler ( $ action_id ) ; if ( empty ( $ handler ) ) { return false ; } try { $ callback = static :: get ( $ handler , null , 'validate' ) ; return call_user_func_array ( $ callback , array ( & $ value ) ) ; } catch ( Exception $ ex ) { return false ; } }
Calls an appropriate validator method for the given action ID
55,425
public function route ( array $ values , $ operator ) { if ( ! in_array ( $ operator , array ( '=' , '!=' ) ) ) { return $ this -> translation -> text ( 'Unsupported operator' ) ; } $ existing = $ this -> route -> getList ( ) ; foreach ( $ values as $ pattern ) { if ( empty ( $ existing [ $ pattern ] ) ) { return $ this -> translation -> text ( '@name is unavailable' , array ( '@name' => $ this -> translation -> text ( 'Condition' ) ) ) ; } } return true ; }
Validates the route pattern
55,426
public function path ( array $ values , $ operator ) { if ( ! in_array ( $ operator , array ( '=' , '!=' ) ) ) { return $ this -> translation -> text ( 'Unsupported operator' ) ; } foreach ( $ values as $ pattern ) { if ( ! gplcart_string_is_regexp ( $ pattern ) ) { return $ this -> translation -> text ( '@field has invalid value' , array ( '@field' => $ this -> translation -> text ( 'Condition' ) ) ) ; } } return true ; }
Validates the path pattern
55,427
public function getHandlers ( ) { $ handlers = & gplcart_static ( 'mail.handlers' ) ; if ( isset ( $ handlers ) ) { return $ handlers ; } $ handlers = ( array ) gplcart_config_get ( GC_FILE_CONFIG_MAIL ) ; $ this -> hook -> attach ( 'mail.handlers' , $ handlers , $ this ) ; return $ handlers ; }
Returns an array of email handlers
55,428
public function send ( $ to , $ subject , $ message , $ options ) { if ( ! is_array ( $ options ) ) { $ options = array ( 'from' => ( string ) $ options ) ; } settype ( $ to , 'array' ) ; $ result = null ; $ this -> hook -> attach ( 'mail.send' , $ to , $ subject , $ message , $ options , $ result ) ; if ( isset ( $ result ) ) { return $ result ; } return $ this -> mail ( $ to , $ subject , $ message , $ options ) ; }
Sends an e - mail
55,429
public function set ( $ handler_id , array $ arguments ) { try { $ handlers = $ this -> getHandlers ( ) ; $ data = Handler :: call ( $ handlers , $ handler_id , 'data' , $ arguments ) ; return call_user_func_array ( array ( $ this , 'send' ) , $ data ) ; } catch ( Exception $ ex ) { trigger_error ( $ ex -> getMessage ( ) ) ; return false ; } }
Sends E - mail with predefined parameters using a handler ID
55,430
public static function get ( $ name , $ config = NULL ) { if ( isset ( $ _COOKIE [ $ name ] ) ) { if ( $ v = json_decode ( Cipher :: decrypt ( base64_decode ( $ _COOKIE [ $ name ] ) , Config :: config ( ) -> key ) , true ) ) { return $ v ; } } return FALSE ; }
Decrypt and fetch cookie data
55,431
public static function set ( $ name , $ value , $ config = array ( ) ) { extract ( array_merge ( static :: $ settings , $ config ) ) ; $ value = $ value ? base64_encode ( Cipher :: encrypt ( json_encode ( $ value ) , Config :: config ( ) -> key ) ) : null ; setcookie ( $ name , $ value , $ expires , $ path , $ domain , $ secure , $ httponly ) ; }
Called before any output is sent to create an encrypted cookie with the given value .
55,432
public function add ( array $ data ) { $ result = array ( ) ; $ this -> hook -> attach ( 'wishlist.add.product.before' , $ data , $ result , $ this ) ; if ( ! empty ( $ result ) ) { return ( array ) $ result ; } if ( $ this -> wishlist -> exists ( $ data ) ) { return $ this -> getResultErrorExists ( $ data ) ; } if ( $ this -> wishlist -> exceedsLimit ( $ data [ 'user_id' ] , $ data [ 'store_id' ] ) ) { return $ this -> getResultErrorExceeds ( $ data ) ; } $ data [ 'wishlist_id' ] = $ this -> wishlist -> add ( $ data ) ; if ( empty ( $ data [ 'wishlist_id' ] ) ) { return $ this -> getResultError ( ) ; } $ result = $ this -> getResultAdded ( $ data ) ; $ this -> hook -> attach ( 'wishlist.add.product.after' , $ data , $ result , $ this ) ; return ( array ) $ result ; }
Adds a product to a wishlist and returns an array of result data
55,433
public function delete ( array $ data ) { $ result = array ( ) ; $ this -> hook -> attach ( 'wishlist.delete.product.before' , $ data , $ result , $ this ) ; if ( ! empty ( $ result ) ) { return ( array ) $ result ; } if ( ! $ this -> wishlist -> delete ( $ data ) ) { return $ this -> getResultError ( ) ; } $ result = $ this -> getResultDelete ( $ data ) ; $ this -> hook -> attach ( 'wishlist.delete.product.after' , $ data , $ result , $ this ) ; return ( array ) $ result ; }
Delete a product from the wishlist
55,434
protected function getResultAdded ( array $ data ) { $ options = array ( 'user_id' => $ data [ 'user_id' ] , 'store_id' => $ data [ 'store_id' ] ) ; $ href = $ this -> url -> get ( 'wishlist' ) ; $ existing = $ this -> wishlist -> getList ( $ options ) ; return array ( 'redirect' => '' , 'severity' => 'success' , 'quantity' => count ( $ existing ) , 'wishlist_id' => $ data [ 'wishlist_id' ] , 'message' => $ this -> translation -> text ( 'Product has been added to your <a href="@url">wishlist</a>' , array ( '@url' => $ href ) ) ) ; }
Returns an array of resulting data when a product has been added to the wishlist
55,435
protected function getResultErrorExceeds ( array $ data ) { $ vars = array ( '%num' => $ this -> wishlist -> getLimit ( $ data [ 'user_id' ] ) ) ; return array ( 'redirect' => '' , 'severity' => 'warning' , 'message' => $ this -> translation -> text ( "You're exceeding limit of %num items" , $ vars ) ) ; }
Returns an array of resulting data when a user exceeds the max allowed number of products in the wishlist
55,436
protected function getResultErrorExists ( array $ data ) { $ vars = array ( '@url' => $ this -> url -> get ( 'wishlist' ) ) ; return array ( 'redirect' => '' , 'severity' => 'warning' , 'wishlist_id' => $ data [ 'wishlist_id' ] , 'message' => $ this -> translation -> text ( 'Product already in your <a href="@url">wishlist</a>' , $ vars ) ) ; }
Returns an array of resulting data when a product already exists in the wishlist
55,437
protected function getResultDelete ( array $ data ) { unset ( $ data [ 'product_id' ] ) ; $ existing = $ this -> wishlist -> getList ( $ data ) ; return array ( 'message' => '' , 'severity' => 'success' , 'quantity' => count ( $ existing ) , 'redirect' => empty ( $ existing ) ? 'wishlist' : '' ) ; }
Returns an array of resulting data when a product has been deleted from a wishlist
55,438
public function listReportEvent ( ) { $ this -> clearReportEvent ( ) ; $ this -> actionListReportEvent ( ) ; $ this -> setTitleListReportEvent ( ) ; $ this -> setBreadcrumbListReportEvent ( ) ; $ this -> setFilterListReportEvent ( ) ; $ this -> setPagerListReportEvent ( ) ; $ this -> setData ( 'types' , $ this -> report -> getTypes ( ) ) ; $ this -> setData ( 'severities' , $ this -> report -> getSeverities ( ) ) ; $ this -> setData ( 'records' , $ this -> getListReportEvent ( ) ) ; $ this -> outputListReportEvent ( ) ; }
Displays the event overview page
55,439
protected function clearReportEvent ( ) { $ key = 'clear' ; $ this -> controlToken ( $ key ) ; if ( $ this -> isQuery ( $ key ) ) { $ this -> report -> delete ( ) ; $ this -> redirect ( 'admin/report/events' ) ; } }
Deletes all system events from the database
55,440
protected function getListReportEvent ( ) { $ conditions = $ this -> query_filter ; $ conditions [ 'limit' ] = $ this -> data_limit ; $ list = ( array ) $ this -> report -> getList ( $ conditions ) ; $ this -> prepareListReportEvent ( $ list ) ; return $ list ; }
Returns an array of system events
55,441
protected function prepareListReportEvent ( array & $ list ) { foreach ( $ list as & $ item ) { $ variables = array ( ) ; if ( ! empty ( $ item [ 'data' ] [ 'variables' ] ) ) { $ variables = $ item [ 'data' ] [ 'variables' ] ; } $ item [ 'created' ] = $ this -> date ( $ item [ 'created' ] ) ; $ type = "event_{$item['type']}" ; $ item [ 'type' ] = $ this -> text ( $ type ) ; if ( ! empty ( $ item [ 'translatable' ] ) ) { $ item [ 'text' ] = $ this -> text ( $ item [ 'text' ] , $ variables ) ; } $ item [ 'summary' ] = $ this -> truncate ( $ item [ 'text' ] ) ; $ item [ 'severity_text' ] = $ this -> text ( $ item [ 'severity' ] ) ; } }
Prepare an array of system events
55,442
public function getList ( array $ options ) { $ result = null ; $ this -> hook -> attach ( 'translation.entity.list.before' , $ options , $ result , $ this ) ; if ( isset ( $ result ) ) { return ( array ) $ result ; } $ table = $ this -> getTable ( $ options [ 'entity' ] ) ; $ sql = "SELECT * FROM `$table` WHERE {$options['entity']}_id = ?" ; $ conditions = array ( $ options [ 'entity_id' ] ) ; if ( isset ( $ options [ 'language' ] ) ) { $ sql .= ' AND language = ?' ; $ conditions [ ] = $ options [ 'language' ] ; } $ result = $ this -> db -> fetchAll ( $ sql , $ conditions ) ; $ this -> hook -> attach ( 'translation.entity.list.after' , $ options , $ result , $ this ) ; return ( array ) $ result ; }
Returns an array of translations
55,443
public function getTable ( $ entity ) { $ tables = $ this -> getTables ( ) ; if ( empty ( $ tables [ $ entity ] ) ) { throw new OutOfBoundsException ( "Entity $entity is not supported for translations" ) ; } return $ tables [ $ entity ] ; }
Returns a database table name for the entity
55,444
public function categoryGroup ( array & $ submitted , array $ options = array ( ) ) { $ this -> options = $ options ; $ this -> submitted = & $ submitted ; $ this -> validateCategoryGroup ( ) ; $ this -> validateTitle ( ) ; $ this -> validateTranslation ( ) ; $ this -> validateStoreId ( ) ; $ this -> validateTypeCategoryGroup ( ) ; $ this -> unsetSubmitted ( 'update' ) ; return $ this -> getResult ( ) ; }
Performs full category group data validation
55,445
protected function validateCategoryGroup ( ) { $ id = $ this -> getUpdatingId ( ) ; if ( $ id === false ) { return null ; } $ data = $ this -> category_group -> get ( $ id ) ; if ( empty ( $ data ) ) { $ this -> setErrorUnavailable ( 'update' , $ this -> translation -> text ( 'Category group' ) ) ; return false ; } $ this -> setUpdating ( $ data ) ; return true ; }
Validates a category group to be updated
55,446
protected function validateTypeCategoryGroup ( ) { $ field = 'type' ; if ( $ this -> isExcluded ( $ field ) || $ this -> isError ( 'store_id' ) ) { return null ; } $ type = $ this -> getSubmitted ( $ field ) ; if ( $ this -> isUpdating ( ) && ! isset ( $ type ) ) { return null ; } $ store_id = $ this -> getSubmitted ( 'store_id' ) ; if ( ! isset ( $ store_id ) ) { $ this -> setErrorRequired ( $ field , $ this -> translation -> text ( 'Store' ) ) ; return false ; } $ label = $ this -> translation -> text ( 'Type' ) ; if ( empty ( $ type ) ) { $ this -> setErrorRequired ( $ field , $ label ) ; return false ; } $ types = $ this -> category_group -> getTypes ( ) ; if ( ! isset ( $ types [ $ type ] ) ) { $ this -> setErrorUnavailable ( $ field , $ label ) ; return false ; } $ updating = $ this -> getUpdating ( ) ; $ list = $ this -> category_group -> getList ( array ( 'type' => $ type , 'store_id' => $ store_id ) ) ; if ( isset ( $ updating [ 'category_group_id' ] ) ) { unset ( $ list [ $ updating [ 'category_group_id' ] ] ) ; } if ( empty ( $ list ) ) { return true ; } $ error = $ this -> translation -> text ( 'Category group of this type already exists for this store' ) ; $ this -> setError ( 'type' , $ error ) ; return false ; }
Validates category group type
55,447
public function fitWidth ( & $ source , $ target , array $ action ) { $ width = reset ( $ action [ 'value' ] ) ; if ( $ this -> image -> set ( $ source ) -> fitToWidth ( $ width ) -> save ( $ target ) ) { $ source = $ target ; return true ; } return false ; }
Fit to width
55,448
public function fitHeight ( & $ source , $ target , array $ action ) { $ height = reset ( $ action [ 'value' ] ) ; if ( $ this -> image -> set ( $ source ) -> fitToHeight ( $ height ) -> save ( $ target ) ) { $ source = $ target ; return true ; } return false ; }
Fit to height
55,449
protected function helper ( $ helperName ) { if ( ! isset ( $ this -> helpers [ $ helperName ] ) ) { throw new \ InvalidArgumentException ( 'Unable to locate controller helper: ' . $ helperName ) ; } return $ this -> helpers [ $ helperName ] ; }
Obtain a controller helper by its key name .
55,450
protected function post ( $ key = null , $ default = null , $ deep = false ) { return $ key === null ? $ this -> getPost ( ) -> all ( ) : $ this -> getPost ( ) -> get ( $ key , $ default , $ deep ) ; }
Returns a post parameter by name .
55,451
protected function files ( $ key = null , $ default = null , $ deep = false ) { return $ key === null ? $ this -> getFiles ( ) -> all ( ) : $ this -> getFiles ( ) -> get ( $ key , $ default , $ deep ) ; }
Returns a files parameter by name .
55,452
protected function queryString ( $ key = null , $ default = null , $ deep = false ) { return $ key === null ? $ this -> getQueryString ( ) -> all ( ) : $ this -> getQueryString ( ) -> get ( $ key , $ default , $ deep ) ; }
Returns a query string parameter by name .
55,453
protected function is ( $ key ) { switch ( $ key = strtolower ( $ key ) ) { case 'ajax' : if ( ! isset ( $ this -> isCache [ 'ajax' ] ) ) { return $ this -> isCache [ 'ajax' ] = $ this -> getService ( 'Request' ) -> isXmlHttpRequest ( ) ; } return $ this -> isCache [ 'ajax' ] ; case 'put' : case 'delete' : case 'post' : case 'patch' : if ( ! isset ( $ this -> isCache [ 'requestMethod' ] [ $ key ] ) ) { $ this -> isCache [ 'requestMethod' ] [ $ key ] = $ this -> getService ( 'Request' ) -> getMethod ( ) === strtoupper ( $ key ) ; } return $ this -> isCache [ 'requestMethod' ] [ $ key ] ; case 'ssl' : case 'https' : case 'secure' : if ( ! isset ( $ this -> isCache [ 'secure' ] ) ) { $ this -> isCache [ 'secure' ] = $ this -> getService ( 'Request' ) -> isSecure ( ) ; } return $ this -> isCache [ 'secure' ] ; default : throw new \ InvalidArgumentException ( "Invalid 'is' key supplied: {$key}" ) ; } }
Check if a condition is true .
55,454
protected function generateUrl ( $ route , $ parameters = array ( ) , $ absolute = false ) { return $ this -> getService ( 'Router' ) -> generate ( $ route , $ parameters , $ absolute ) ; }
Generate a URL from the specified route name .
55,455
public function shippingMethod ( array $ condition , array $ data ) { if ( ! isset ( $ data [ 'order' ] [ 'shipping' ] ) ) { return false ; } return $ this -> compare ( $ data [ 'order' ] [ 'shipping' ] , $ condition [ 'value' ] , $ condition [ 'operator' ] ) ; }
Whether the shipping service condition is met
55,456
public function paymentMethod ( array $ condition , array $ data ) { if ( ! isset ( $ data [ 'order' ] [ 'payment' ] ) ) { return false ; } return $ this -> compare ( $ data [ 'order' ] [ 'payment' ] , $ condition [ 'value' ] , $ condition [ 'operator' ] ) ; }
Whether the payment service condition is met
55,457
protected function setProductClassProductClassField ( $ product_class_id ) { $ this -> data_product_class = array ( ) ; if ( is_numeric ( $ product_class_id ) ) { $ this -> data_product_class = $ this -> product_class -> get ( $ product_class_id ) ; if ( empty ( $ this -> data_product_class ) ) { $ this -> outputHttpStatus ( 404 ) ; } } }
Sets the product class data
55,458
public function listProductClassField ( $ product_class_id ) { $ this -> setProductClassProductClassField ( $ product_class_id ) ; $ this -> setTitleListProductClassField ( ) ; $ this -> setBreadcrumbListProductClassField ( ) ; $ this -> setFilterListProductClassField ( ) ; $ this -> setData ( 'field_types' , $ this -> field -> getTypes ( ) ) ; $ this -> setData ( 'fields' , $ this -> getListProductClassField ( ) ) ; $ this -> setData ( 'product_class' , $ this -> data_product_class ) ; $ this -> submitListProductClassField ( ) ; $ this -> outputListProductClassField ( ) ; }
Route callback for the product class field overview page
55,459
protected function getListProductClassField ( array $ conditions = array ( ) ) { $ conditions += $ this -> query_filter ; $ conditions [ 'product_class_id' ] = $ this -> data_product_class [ 'product_class_id' ] ; return ( array ) $ this -> product_class_field -> getList ( $ conditions ) ; }
Returns an array of fields for the given product class
55,460
protected function getUniqueListProductClassField ( ) { $ types = $ this -> field -> getTypes ( ) ; $ fields = $ this -> getListProductClassField ( array ( 'index' => 'field_id' ) ) ; $ unique = array ( ) ; foreach ( ( array ) $ this -> field -> getList ( ) as $ field ) { if ( empty ( $ fields [ $ field [ 'field_id' ] ] ) ) { $ type = empty ( $ types [ $ field [ 'type' ] ] ) ? $ this -> text ( 'Unknown' ) : $ types [ $ field [ 'type' ] ] ; $ unique [ $ field [ 'field_id' ] ] = "{$field['title']} ($type)" ; } } return $ unique ; }
Returns an array of product class fields indexed by field ID which are unique for the product class
55,461
protected function updateListProductClassField ( ) { $ this -> controlAccess ( 'product_class_edit' ) ; foreach ( ( array ) $ this -> setSubmitted ( 'fields' ) as $ id => $ field ) { if ( ! empty ( $ field [ 'remove' ] ) ) { $ this -> product_class_field -> delete ( $ id ) ; continue ; } $ field [ 'required' ] = ! empty ( $ field [ 'required' ] ) ; $ field [ 'multiple' ] = ! empty ( $ field [ 'multiple' ] ) ; $ this -> product_class_field -> update ( $ id , $ field ) ; } $ this -> redirect ( '' , $ this -> text ( 'Product class has been updated' ) , 'success' ) ; }
Updates product class fields
55,462
protected function setBreadcrumbListProductClassField ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ breadcrumbs [ ] = array ( 'text' => $ this -> text ( 'Product classes' ) , 'url' => $ this -> url ( 'admin/content/product-class' ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
Sets breadcrumbs on the product class field overview page
55,463
public function editProductClassField ( $ product_class_id ) { $ this -> setProductClassProductClassField ( $ product_class_id ) ; $ this -> setTitleEditProductClassField ( ) ; $ this -> setBreadcrumbEditProductClassField ( ) ; $ this -> setData ( 'product_class' , $ this -> data_product_class ) ; $ this -> setData ( 'fields' , $ this -> getUniqueListProductClassField ( ) ) ; $ this -> submitEditProductClassField ( ) ; $ this -> outputEditProductClassField ( ) ; }
Route callback Displays the edit product class field page
55,464
protected function validateEditProductClassField ( ) { $ this -> setSubmitted ( 'product_class' ) ; $ this -> setSubmitted ( 'product_class_id' , $ this -> data_product_class [ 'product_class_id' ] ) ; $ this -> validateComponent ( 'product_class_field' ) ; return ! $ this -> hasErrors ( false ) ; }
Validates an array of submitted product class fields
55,465
protected function addProductClassField ( ) { $ this -> controlAccess ( 'product_class_edit' ) ; foreach ( ( array ) $ this -> getSubmitted ( 'field_id' , array ( ) ) as $ field_id ) { $ field = array ( 'field_id' => $ field_id , 'product_class_id' => $ this -> data_product_class [ 'product_class_id' ] ) ; $ this -> product_class_field -> add ( $ field ) ; } $ url = "admin/content/product-class/field/{$this->data_product_class['product_class_id']}" ; $ this -> redirect ( $ url , $ this -> text ( 'Product class has been updated' ) , 'success' ) ; }
Adds product class fields
55,466
protected function setBreadcrumbEditProductClassField ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ breadcrumbs [ ] = array ( 'text' => $ this -> text ( 'Product classes' ) , 'url' => $ this -> url ( 'admin/content/product-class' ) ) ; $ breadcrumbs [ ] = array ( 'text' => $ this -> text ( 'Fields of %name' , array ( '%name' => $ this -> data_product_class [ 'title' ] ) ) , 'url' => $ this -> url ( "admin/content/product-class/field/{$this->data_product_class['product_class_id']}" ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
Sets breadcrumbs on the edit product class field page
55,467
public function listCollection ( ) { $ this -> actionListCollection ( ) ; $ this -> setTitleListCollection ( ) ; $ this -> setBreadcrumbListCollection ( ) ; $ this -> setFilterListCollection ( ) ; $ this -> setPagerListCollection ( ) ; $ this -> setData ( 'collections' , $ this -> getListCollection ( ) ) ; $ this -> setData ( 'handlers' , $ this -> collection -> getHandlers ( ) ) ; $ this -> outputListCollection ( ) ; }
Displays the collection overview page
55,468
public function editCollection ( $ collection_id = null ) { $ this -> setCollection ( $ collection_id ) ; $ this -> setTitleEditCollection ( ) ; $ this -> setBreadcrumbEditCollection ( ) ; $ this -> setData ( 'types' , $ this -> collection -> getTypes ( ) ) ; $ this -> setData ( 'collection' , $ this -> data_collection ) ; $ this -> setData ( 'can_delete' , $ this -> canDeleteCollection ( ) ) ; $ this -> setData ( 'languages' , $ this -> language -> getList ( array ( 'enabled' => true ) ) ) ; $ this -> submitEditCollection ( ) ; $ this -> outputEditCollection ( ) ; }
Displays the edit collection page
55,469
protected function submitEditCollection ( ) { if ( $ this -> isPosted ( 'delete' ) ) { $ this -> deleteCollection ( ) ; } else if ( $ this -> isPosted ( 'save' ) && $ this -> validateEditCollection ( ) ) { if ( isset ( $ this -> data_collection [ 'collection_id' ] ) ) { $ this -> updateCollection ( ) ; } else { $ this -> addCollection ( ) ; } } }
Saves an array of submitted collection data
55,470
protected function validateEditCollection ( ) { $ this -> setSubmitted ( 'collection' ) ; $ this -> setSubmittedBool ( 'status' ) ; $ this -> setSubmitted ( 'update' , $ this -> data_collection ) ; $ this -> validateComponent ( 'collection' ) ; return ! $ this -> hasErrors ( ) ; }
Validates a submitted collection
55,471
protected function canDeleteCollection ( ) { return isset ( $ this -> data_collection [ 'collection_id' ] ) && $ this -> access ( 'collection_delete' ) && $ this -> collection -> canDelete ( $ this -> data_collection [ 'collection_id' ] ) ; }
Whether the current collection can be deleted
55,472
protected function deleteCollection ( ) { $ this -> controlAccess ( 'collection_delete' ) ; if ( $ this -> collection -> delete ( $ this -> data_collection [ 'collection_id' ] ) ) { $ this -> redirect ( 'admin/content/collection' , $ this -> text ( 'Collection has been deleted' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Collection has not been deleted' ) , 'warning' ) ; }
Deletes a collection
55,473
protected function addCollection ( ) { $ this -> controlAccess ( 'collection_add' ) ; if ( $ this -> collection -> add ( $ this -> getSubmitted ( ) ) ) { $ this -> redirect ( 'admin/content/collection' , $ this -> text ( 'Collection has been added' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Collection has not been added' ) , 'danger' ) ; }
Adds a new collection
55,474
protected function setTitleEditCollection ( ) { if ( isset ( $ this -> data_collection [ 'title' ] ) ) { $ title = $ this -> text ( 'Edit %name' , array ( '%name' => $ this -> data_collection [ 'title' ] ) ) ; } else { $ title = $ this -> text ( 'Add collection' ) ; } $ this -> setTitle ( $ title ) ; }
Sets title on the edit collection page
55,475
protected function setBreadcrumbEditCollection ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ breadcrumbs [ ] = array ( 'text' => $ this -> text ( 'Collections' ) , 'url' => $ this -> url ( 'admin/content/collection' ) , ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
Sets breadcrumbs on the edit collection page
55,476
protected function setAdminModeCheckout ( $ mode ) { $ this -> admin = null ; if ( $ this -> access ( 'order_add' ) ) { if ( $ mode === 'add' ) { $ this -> admin = 'add' ; } if ( $ mode === 'clone' && $ this -> access ( 'order_edit' ) ) { $ this -> admin = 'clone' ; } } }
Sets the current admin mode
55,477
protected function setUserCheckout ( $ user_id ) { $ this -> data_user = array ( ) ; if ( ! is_numeric ( $ user_id ) ) { $ this -> outputHttpStatus ( 403 ) ; } $ this -> data_user = $ this -> user -> get ( $ user_id ) ; if ( empty ( $ this -> data_user [ 'status' ] ) ) { $ this -> outputHttpStatus ( 404 ) ; } $ this -> order_user_id = $ user_id ; $ this -> order_store_id = $ this -> data_user [ 'store_id' ] ; }
Loads a user from the database
55,478
public function editCheckout ( ) { $ this -> setCartContentCheckout ( ) ; $ this -> setTitleEditCheckout ( ) ; $ this -> setBreadcrumbEditCheckout ( ) ; $ this -> controlAccessCheckout ( ) ; $ this -> setFormDataBeforeCheckout ( ) ; $ this -> submitEditCheckout ( ) ; $ this -> setFormDataAfterCheckout ( ) ; $ this -> setDataFormCheckout ( ) ; $ this -> outputEditCheckout ( ) ; }
Page callback Displays the checkout page
55,479
protected function setCartContentCheckout ( ) { $ options = array ( 'user_id' => $ this -> cart_uid , 'order_id' => $ this -> order_id , 'store_id' => $ this -> order_store_id ) ; return $ this -> data_cart = $ this -> getCart ( $ options ) ; }
Load and set the current cart content
55,480
protected function setTitleEditCheckout ( ) { if ( $ this -> admin === 'clone' ) { $ text = $ this -> text ( 'Cloning order #@num' , array ( '@num' => $ this -> data_order [ 'order_id' ] ) ) ; } else if ( $ this -> admin === 'add' ) { $ text = $ this -> text ( 'Add order for user %name' , array ( '%name' => $ this -> data_user [ 'name' ] ) ) ; } else { $ text = $ this -> text ( 'Checkout' ) ; } $ this -> setTitle ( $ text ) ; }
Sets title on the checkout page
55,481
protected function controlAccessCheckout ( ) { if ( empty ( $ this -> data_cart [ 'items' ] ) ) { $ form = $ this -> render ( 'checkout/form' , array ( 'admin' => $ this -> admin ) , true ) ; $ this -> setData ( 'checkout_form' , $ form ) ; $ this -> output ( 'checkout/checkout' ) ; } }
Controls access to the checkout page
55,482
protected function setFormDataBeforeCheckout ( ) { $ this -> data_form = array ( ) ; $ default_order = $ this -> getDefaultOrder ( ) ; $ order = gplcart_array_merge ( $ default_order , $ this -> data_order ) ; $ payment_methods = $ this -> getPaymentMethodsCheckout ( ) ; $ shipping_methods = $ this -> getShippingMethodsCheckout ( ) ; if ( count ( $ payment_methods ) == 1 ) { reset ( $ payment_methods ) ; $ order [ 'payment' ] = key ( $ payment_methods ) ; } if ( count ( $ shipping_methods ) ) { reset ( $ shipping_methods ) ; $ order [ 'shipping' ] = key ( $ shipping_methods ) ; } $ this -> data_form [ 'order' ] = $ order ; $ this -> data_form [ 'messages' ] = array ( ) ; $ this -> data_form [ 'admin' ] = $ this -> admin ; $ this -> data_form [ 'user' ] = $ this -> data_user ; $ this -> data_form [ 'statuses' ] = $ this -> order -> getStatuses ( ) ; $ this -> data_form [ 'payment_methods' ] = $ payment_methods ; $ this -> data_form [ 'shipping_methods' ] = $ shipping_methods ; $ this -> data_form [ 'has_dynamic_payment_methods' ] = $ this -> hasDynamicMethods ( $ payment_methods ) ; $ this -> data_form [ 'has_dynamic_shipping_methods' ] = $ this -> hasDynamicMethods ( $ shipping_methods ) ; $ this -> data_form [ 'store_id' ] = $ this -> order_store_id ; $ this -> data_form [ 'currency' ] = $ this -> data_cart [ 'currency' ] ; $ this -> setFormDataDimensionsCheckout ( ) ; }
Sets initial form data
55,483
protected function getDefaultOrder ( ) { return array ( 'comment' => '' , 'payment' => '' , 'shipping' => '' , 'user_id' => $ this -> order_user_id , 'creator' => $ this -> admin_user_id , 'store_id' => $ this -> order_store_id , 'currency' => $ this -> data_cart [ 'currency' ] , 'status' => $ this -> order -> getStatusInitial ( ) , 'size_unit' => $ this -> config ( 'order_size_unit' , 'mm' ) , 'weight_unit' => $ this -> config ( 'order_weight_unit' , 'g' ) , 'data' => array ( ) ) ; }
Returns an array of default order data
55,484
protected function getPaymentMethodsCheckout ( ) { $ list = $ this -> payment -> getList ( array ( 'status' => true ) ) ; $ this -> prepareMethodsCheckout ( $ list ) ; return $ list ; }
Returns an array of enabled payment methods
55,485
protected function getShippingMethodsCheckout ( ) { $ list = $ this -> shipping -> getList ( array ( 'status' => true ) ) ; $ this -> prepareMethodsCheckout ( $ list ) ; return $ list ; }
Returns an array of enabled shipping methods
55,486
protected function prepareMethodsCheckout ( array & $ list ) { foreach ( $ list as & $ item ) { if ( isset ( $ item [ 'module' ] ) && isset ( $ item [ 'image' ] ) ) { $ path = GC_DIR_MODULE . "/{$item['module']}/{$item['image']}" ; $ item [ 'image' ] = $ this -> url ( gplcart_path_relative ( $ path ) ) ; } } }
Prepare payment and shipping methods
55,487
protected function setFormDataAfterCheckout ( ) { if ( empty ( $ this -> data_cart ) ) { return null ; } $ this -> data_form [ 'cart' ] = $ this -> data_cart ; $ this -> setFormDataAddressCheckout ( ) ; if ( empty ( $ this -> data_form [ 'addresses' ] ) ) { $ this -> show_shipping_address_form = true ; } $ this -> data_form [ 'default_payment_method' ] = false ; $ this -> data_form [ 'default_shipping_method' ] = false ; $ this -> data_form [ 'same_payment_address' ] = $ this -> same_payment_address ; $ this -> data_form [ 'get_payment_methods' ] = $ this -> isPosted ( 'get_payment_methods' ) ; $ this -> data_form [ 'get_shipping_methods' ] = $ this -> isPosted ( 'get_shipping_methods' ) ; $ this -> data_form [ 'show_login_form' ] = $ this -> show_login_form ; $ this -> data_form [ 'show_payment_address_form' ] = $ this -> show_payment_address_form ; $ this -> data_form [ 'show_shipping_address_form' ] = $ this -> show_shipping_address_form ; $ this -> data_form [ 'show_payment_methods' ] = ! $ this -> data_form [ 'has_dynamic_payment_methods' ] ; $ this -> data_form [ 'show_shipping_methods' ] = ! $ this -> data_form [ 'has_dynamic_shipping_methods' ] ; $ submitted = array ( 'order' => $ this -> getSubmitted ( ) ) ; $ this -> data_form [ 'context_templates' ] = array ( 'payment' => $ this -> getPaymentMethodTemplate ( 'context' , $ submitted [ 'order' ] , $ this -> payment ) , 'shipping' => $ this -> getShippingMethodTemplate ( 'context' , $ submitted [ 'order' ] , $ this -> shipping ) , ) ; $ this -> data_form = gplcart_array_merge ( $ this -> data_form , $ submitted ) ; $ this -> setFormDataRequestServicesCheckout ( 'payment' ) ; $ this -> setFormDataRequestServicesCheckout ( 'shipping' ) ; $ this -> setFormDataCalculatedCheckout ( ) ; $ this -> setFormDataPanesCheckout ( ) ; }
Prepares the form data before passing to the templates
55,488
protected function setFormDataAddressCheckout ( ) { $ countries = array ( ) ; foreach ( ( array ) $ this -> country -> getList ( array ( 'status' => true ) ) as $ code => $ country ) { $ countries [ $ code ] = $ country [ 'native_name' ] ; } $ default_country = count ( $ countries ) == 1 ? key ( $ countries ) : '' ; $ address = $ this -> getSubmitted ( 'address' , array ( ) ) ; if ( ! isset ( $ address [ 'payment' ] [ 'country' ] ) ) { $ address [ 'payment' ] [ 'country' ] = $ default_country ; } if ( ! isset ( $ address [ 'shipping' ] [ 'country' ] ) ) { $ address [ 'shipping' ] [ 'country' ] = $ default_country ; } $ this -> data_form [ 'address' ] = $ address ; $ this -> data_form [ 'countries' ] = $ countries ; $ this -> data_form [ 'addresses' ] = $ this -> address -> getTranslatedList ( $ this -> order_user_id ) ; $ excessed = $ this -> address -> getExceeded ( $ this -> order_user_id , $ this -> data_form [ 'addresses' ] ) ; $ this -> data_form [ 'can_add_address' ] = empty ( $ excessed ) ; $ this -> data_form [ 'can_save_address' ] = empty ( $ excessed ) && ! empty ( $ this -> uid ) ; foreach ( $ address as $ type => $ fields ) { $ this -> data_form [ 'format' ] [ $ type ] = $ this -> country -> getFormat ( $ fields [ 'country' ] ) ; $ this -> data_form [ 'states' ] [ $ type ] = $ this -> state -> getList ( array ( 'country' => $ fields [ 'country' ] , 'status' => 1 ) ) ; if ( empty ( $ this -> data_form [ 'states' ] [ $ type ] ) ) { unset ( $ this -> data_form [ 'format' ] [ $ type ] [ 'state_id' ] ) ; } } }
Sets the checkout address variables
55,489
protected function setFormDataDimensionsCheckout ( ) { if ( ! empty ( $ this -> data_cart ) ) { $ order = $ this -> data_form [ 'order' ] ; $ this -> data_form [ 'order' ] [ 'volume' ] = $ this -> order_dimension -> getVolume ( $ order , $ this -> data_cart ) ; $ this -> data_form [ 'order' ] [ 'weight' ] = $ this -> order_dimension -> getWeight ( $ order , $ this -> data_cart ) ; } }
Calculates and sets order dimensions
55,490
protected function setFormDataCalculatedCheckout ( ) { $ result = $ this -> order -> calculate ( $ this -> data_form ) ; $ this -> data_form [ 'total' ] = $ result [ 'total' ] ; $ this -> data_form [ 'total_decimal' ] = $ result [ 'total_decimal' ] ; $ this -> data_form [ 'total_formatted' ] = $ result [ 'total_formatted' ] ; $ this -> data_form [ 'price_components' ] = $ this -> prepareOrderComponentsCheckout ( $ result ) ; }
Calculates order total and price components
55,491
protected function setFormDataPanesCheckout ( ) { $ panes = array ( 'login' , 'review' , 'payment_methods' , 'shipping_methods' , 'shipping_address' , 'payment_address' , 'comment' , 'action' ) ; foreach ( $ panes as $ pane ) { $ this -> data_form [ "pane_$pane" ] = $ this -> render ( "checkout/panes/$pane" , $ this -> data_form ) ; } }
Sets rendered panes
55,492
protected function submitEditCheckout ( ) { $ this -> setSubmitted ( 'order' ) ; $ this -> setAddressFormCheckout ( ) ; $ this -> submitAddAddressCheckout ( ) ; if ( $ this -> isPosted ( 'checkout_login' ) && empty ( $ this -> uid ) ) { $ this -> show_login_form = true ; } $ this -> same_payment_address = ( bool ) $ this -> getPosted ( 'same_payment_address' , true , false , 'bool' ) ; if ( $ this -> isPosted ( 'update' ) ) { $ this -> setMessage ( $ this -> text ( 'Form has been updated' ) , 'success' , false ) ; } $ this -> submitLoginCheckout ( ) ; if ( $ this -> isPosted ( 'checkout_anonymous' ) ) { $ this -> show_login_form = false ; } $ this -> validateCouponCheckout ( ) ; $ this -> submitCartCheckout ( ) ; $ this -> submitOrderCheckout ( ) ; }
Handles submitted actions
55,493
protected function submitAddAddressCheckout ( ) { $ type = $ this -> getPosted ( 'save_address' , '' , true , 'string' ) ; if ( empty ( $ type ) ) { return null ; } $ errors = $ this -> validateAddressCheckout ( $ type ) ; if ( empty ( $ errors ) ) { $ this -> addAddressCheckout ( $ type ) ; $ this -> { "show_{$type}_address_form" } = false ; } }
Saves a submitted address
55,494
protected function loginCheckout ( ) { $ result = $ this -> user_action -> login ( $ this -> getSubmitted ( 'user' ) ) ; if ( isset ( $ result [ 'user' ] ) ) { $ result = $ this -> cart_action -> login ( $ result [ 'user' ] , $ this -> data_cart ) ; } if ( ! empty ( $ result [ 'user' ] ) ) { $ this -> redirect ( $ result [ 'redirect' ] , $ result [ 'message' ] , $ result [ 'severity' ] ) ; } $ this -> setError ( 'login' , $ result [ 'message' ] ) ; }
Log in a customer during checkout
55,495
protected function validateCouponCheckout ( ) { $ price_rule_id = $ this -> getPosted ( 'check_pricerule' , null , true , 'integer' ) ; if ( empty ( $ price_rule_id ) ) { return null ; } $ code = $ this -> getSubmitted ( 'data.pricerule_code' , '' ) ; if ( $ code === '' ) { return null ; } if ( ! $ this -> order -> priceRuleCodeMatches ( $ price_rule_id , $ code ) ) { $ this -> setError ( 'pricerule_code' , $ this -> text ( 'Invalid code' ) ) ; $ this -> setMessageFormCheckout ( 'components.danger' , $ this -> text ( 'Invalid code' ) ) ; } }
Validates a coupon code
55,496
protected function submitCartItemsCheckout ( ) { $ items = $ this -> getSubmitted ( 'cart.items' ) ; if ( empty ( $ items ) ) { return null ; } $ errors = array ( ) ; foreach ( $ items as $ sku => $ item ) { $ errors += $ this -> validateCartItemCheckout ( $ sku , $ item ) ; if ( empty ( $ errors ) ) { $ this -> updateCartQuantityCheckout ( $ sku , $ item ) ; } } if ( empty ( $ errors ) ) { $ this -> setSubmitted ( 'cart.action.update' , true ) ; } else { $ this -> setMessageFormCheckout ( 'cart.danger' , $ errors ) ; } }
Applies an action to the cart items
55,497
protected function setMessageFormCheckout ( $ key , $ message ) { gplcart_array_set ( $ this -> data_form [ 'messages' ] , $ key , $ this -> format ( $ message ) ) ; }
Sets an array of messages on the checkout form
55,498
protected function updateCartQuantityCheckout ( $ sku , array $ item ) { if ( isset ( $ this -> data_cart [ 'items' ] [ $ sku ] [ 'cart_id' ] ) ) { $ cart_id = $ this -> data_cart [ 'items' ] [ $ sku ] [ 'cart_id' ] ; $ this -> cart -> update ( $ cart_id , array ( 'quantity' => $ item [ 'quantity' ] ) ) ; } }
Updates cart quantity
55,499
protected function validateCartItemCheckout ( $ sku , $ item ) { $ item += array ( 'sku' => $ sku , 'increment' => false , 'admin' => ! empty ( $ this -> admin ) , 'user_id' => $ this -> order_user_id , 'store_id' => $ this -> order_store_id ) ; $ this -> setSubmitted ( 'update' , $ item ) ; $ this -> setSubmitted ( "cart.items.$sku" , $ item ) ; return $ this -> validateComponent ( 'cart' , array ( 'parents' => "cart.items.$sku" ) ) ; }
Validates a cart item and returns possible errors