idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
54,300
|
protected function submitEditCountryState ( ) { if ( $ this -> isPosted ( 'delete' ) ) { $ this -> deleteCountryState ( ) ; } else if ( $ this -> isPosted ( 'save' ) && $ this -> validateEditCountryState ( ) ) { if ( isset ( $ this -> data_state [ 'state_id' ] ) ) { $ this -> updateCountryState ( ) ; } else { $ this -> addCountryState ( ) ; } } }
|
Handles a submitted country state data
|
54,301
|
protected function validateEditCountryState ( ) { $ this -> setSubmitted ( 'state' ) ; $ this -> setSubmittedBool ( 'status' ) ; $ this -> setSubmitted ( 'update' , $ this -> data_state ) ; $ this -> setSubmitted ( 'country' , $ this -> data_country [ 'code' ] ) ; $ this -> validateComponent ( 'country_state' ) ; return ! $ this -> hasErrors ( ) ; }
|
Validates a submitted country state data
|
54,302
|
protected function addCountryState ( ) { $ this -> controlAccess ( 'state_add' ) ; if ( $ this -> state -> add ( $ this -> getSubmitted ( ) ) ) { $ url = "admin/settings/states/{$this->data_country['code']}" ; $ this -> redirect ( $ url , $ this -> text ( 'Country state has been added' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Country state has not been added' ) , 'warning' ) ; }
|
Adds a new country state
|
54,303
|
protected function setTitleEditCountryState ( ) { if ( isset ( $ this -> data_state [ 'state_id' ] ) ) { $ title = $ this -> text ( 'Edit %name' , array ( '%name' => $ this -> data_state [ 'name' ] ) ) ; } else { $ title = $ this -> text ( 'Add country state for %name' , array ( '%name' => $ this -> data_country [ 'name' ] ) ) ; } $ this -> setTitle ( $ title ) ; }
|
Sets titles on the edit country state page
|
54,304
|
protected function setBreadcrumbEditCountryState ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin/settings/country' ) , 'text' => $ this -> text ( 'Countries' ) ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( "admin/settings/states/{$this->data_country['code']}" ) , 'text' => $ this -> text ( 'Country states of %name' , array ( '%name' => $ this -> data_country [ 'code' ] ) ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
|
Set breadcrumbs on the edit country state page
|
54,305
|
public function productBundle ( array & $ submitted , array $ options = array ( ) ) { $ this -> options = $ options ; $ this -> submitted = & $ submitted ; $ this -> validateProductProductBundle ( ) ; $ this -> validateItemsProductBundle ( ) ; return $ this -> getResult ( ) ; }
|
Performs validation of submitted product bundle data
|
54,306
|
protected function validateItemsProductBundle ( ) { $ field = 'bundle' ; $ value = $ this -> getSubmitted ( $ field ) ; if ( empty ( $ value ) ) { return null ; } if ( ! is_array ( $ value ) ) { $ this -> setErrorInvalid ( $ field , $ this -> translation -> text ( 'Product bundle' ) ) ; return false ; } $ main_product = $ this -> getSubmitted ( 'product' ) ; $ loaded = array ( ) ; foreach ( $ value as $ product_id ) { if ( isset ( $ loaded [ $ product_id ] ) ) { $ this -> setError ( $ field , $ this -> translation -> text ( 'All bundled products must be unique' ) ) ; return false ; } $ product = $ this -> product -> get ( $ product_id ) ; $ loaded [ $ product_id ] = $ product ; if ( empty ( $ product [ 'status' ] ) ) { $ this -> setError ( $ field , $ this -> translation -> text ( 'Some of bundled products are unavailable' ) ) ; return false ; } if ( $ main_product [ 'product_id' ] == $ product [ 'product_id' ] ) { $ this -> setError ( $ field , $ this -> translation -> text ( 'Bundled products cannot be the same as the main product' ) ) ; return false ; } if ( $ main_product [ 'store_id' ] != $ product [ 'store_id' ] ) { $ this -> setError ( $ field , $ this -> translation -> text ( 'All bundled products must belong to the same store' ) ) ; return false ; } } $ this -> setSubmitted ( 'products' , $ loaded ) ; return true ; }
|
Validates bundled products
|
54,307
|
public function compare ( array & $ submitted , array $ options = array ( ) ) { $ this -> options = $ options ; $ this -> submitted = & $ submitted ; $ this -> validateProductCompare ( ) ; return $ this -> getResult ( ) ; }
|
Performs full product comparison data validation
|
54,308
|
public function initAuth ( ) { if ( $ this -> _verified ) return true ; $ output = $ this -> postRequest ( 'identification/bankid/mobile' , [ 'useEasyLogin' => false , 'generateEasyLoginId' => false , 'userId' => $ this -> _username , ] ) ; if ( $ output -> status != 'USER_SIGN' ) throw new Exception ( 'Unable to use Mobile BankID. Check if the user have enabled Mobile BankID.' , 10 ) ; $ this -> saveSession ( ) ; return true ; }
|
Initiate Mobile BankID authentication
|
54,309
|
public function verify ( ) { if ( $ this -> _verified ) return true ; $ output = $ this -> getRequest ( 'identification/bankid/mobile/verify' ) ; if ( empty ( $ output -> status ) ) throw new Exception ( 'Mobile BankID cannot be verified. Maybe a session timeout.' , 11 ) ; $ this -> _verified = ( $ output -> status == 'COMPLETE' ) ; $ this -> saveSession ( ) ; return $ this -> _verified ; }
|
Check Mobile BankID verification
|
54,310
|
public function zone ( array & $ submitted , array $ options = array ( ) ) { $ this -> options = $ options ; $ this -> submitted = & $ submitted ; $ this -> validateZone ( ) ; $ this -> validateBool ( 'status' ) ; $ this -> validateTitle ( ) ; $ this -> unsetSubmitted ( 'update' ) ; return $ this -> getResult ( ) ; }
|
Performs full zone data validation
|
54,311
|
protected function validateZone ( ) { $ id = $ this -> getUpdatingId ( ) ; if ( $ id === false ) { return null ; } $ data = $ this -> zone -> get ( $ id ) ; if ( empty ( $ data ) ) { $ this -> setErrorUnavailable ( 'update' , $ this -> translation -> text ( 'Zone' ) ) ; return false ; } $ this -> setUpdating ( $ data ) ; return true ; }
|
Validates a zone to be updated
|
54,312
|
public function listProduct ( ) { $ this -> actionListProduct ( ) ; $ this -> setTitleListProduct ( ) ; $ this -> setBreadcrumbListProduct ( ) ; $ this -> setFilterListProduct ( ) ; $ this -> setPagerListProduct ( ) ; $ this -> setData ( 'products' , $ this -> getListProduct ( ) ) ; $ this -> setData ( 'currencies' , $ this -> currency -> getList ( array ( 'enabled' => true ) ) ) ; $ this -> outputListProduct ( ) ; }
|
Displays the product overview page
|
54,313
|
protected function actionListProduct ( ) { list ( $ selected , $ action , $ value ) = $ this -> getPostedAction ( ) ; $ deleted = $ updated = 0 ; foreach ( $ selected as $ id ) { if ( $ action === 'status' && $ this -> access ( 'product_edit' ) ) { $ updated += ( int ) $ this -> product -> update ( $ id , array ( 'status' => $ value ) ) ; } if ( $ action === 'delete' && $ this -> access ( 'product_delete' ) ) { $ deleted += ( int ) $ this -> product -> delete ( $ id ) ; } } if ( $ updated > 0 ) { $ message = $ this -> text ( 'Updated %num item(s)' , array ( '%num' => $ updated ) ) ; $ this -> setMessage ( $ message , 'success' ) ; } if ( $ deleted > 0 ) { $ message = $ this -> text ( 'Deleted %num item(s)' , array ( '%num' => $ deleted ) ) ; $ this -> setMessage ( $ message , 'success' ) ; } }
|
Applies an action to the selected products
|
54,314
|
protected function prepareListProduct ( array & $ list ) { foreach ( $ list as & $ item ) { $ this -> setItemPriceFormatted ( $ item , $ this -> price ) ; $ this -> setItemUrlEntity ( $ item , $ this -> store , 'product' ) ; } }
|
Prepare an array of products
|
54,315
|
public function editProduct ( $ product_id = null ) { $ this -> setProduct ( $ product_id ) ; $ this -> setTitleEditProduct ( ) ; $ this -> setBreadcrumbEditProduct ( ) ; $ this -> setData ( 'product' , $ this -> data_product ) ; $ this -> setData ( 'size_units' , $ this -> convertor -> getUnitNames ( 'size' ) ) ; $ this -> setData ( 'weight_units' , $ this -> convertor -> getUnitNames ( 'weight' ) ) ; $ this -> setData ( 'default_currency' , $ this -> currency -> getDefault ( ) ) ; $ this -> setData ( 'subtract_default' , $ this -> config -> get ( 'product_subtract' , 0 ) ) ; $ this -> setData ( 'classes' , $ this -> product_class -> getList ( array ( 'status' => 1 ) ) ) ; $ this -> setData ( 'languages' , $ this -> language -> getList ( array ( 'enabled' => true ) ) ) ; $ this -> submitEditProduct ( ) ; $ this -> setDataFieldsEditProduct ( ) ; $ this -> setDataAuthorEditProduct ( ) ; $ this -> setDataRelatedEditProduct ( ) ; $ this -> setDataCategoriesEditProduct ( ) ; $ this -> setDataImagesEditProduct ( ) ; $ this -> setJsEditProduct ( ) ; $ this -> outputEditProduct ( ) ; }
|
Displays the product edit form
|
54,316
|
protected function getListCategoryProduct ( $ store_id ) { $ types = $ this -> category_group -> getTypes ( ) ; $ categories = array ( ) ; foreach ( array_keys ( $ types ) as $ type ) { $ op = array ( 'type' => $ type , 'store_id' => $ store_id ) ; $ data = $ this -> getCategoryOptionsByStore ( $ this -> category , $ this -> category_group , $ op ) ; $ categories [ $ type ] = reset ( $ data ) ; } return $ categories ; }
|
Returns an array of categories keyed by a type
|
54,317
|
protected function setSkuCombinationProduct ( array & $ product ) { if ( ! empty ( $ product [ 'combination' ] ) ) { foreach ( $ product [ 'combination' ] as & $ combination ) { $ combination [ 'path' ] = $ combination [ 'thumb' ] = '' ; if ( ! empty ( $ product [ 'images' ] [ $ combination [ 'file_id' ] ] ) ) { $ combination [ 'path' ] = $ product [ 'images' ] [ $ combination [ 'file_id' ] ] [ 'path' ] ; $ this -> setItemThumb ( $ combination , $ this -> image ) ; } $ combination [ 'price' ] = $ this -> price -> decimal ( $ combination [ 'price' ] , $ product [ 'currency' ] ) ; } } }
|
Sets product SKU combinations data
|
54,318
|
protected function submitEditProduct ( ) { if ( $ this -> isPosted ( 'delete' ) ) { $ this -> deleteProduct ( ) ; } else if ( $ this -> isPosted ( 'save' ) && $ this -> validateEditProduct ( ) ) { $ this -> deleteImagesProduct ( ) ; if ( isset ( $ this -> data_product [ 'product_id' ] ) ) { $ this -> updateProduct ( ) ; } else { $ this -> addProduct ( ) ; } } }
|
Handles a submitted product
|
54,319
|
protected function deleteImagesProduct ( ) { $ this -> controlAccess ( 'product_edit' ) ; $ file_ids = $ this -> getPosted ( 'delete_images' , array ( ) , true , 'array' ) ; return $ this -> image -> delete ( $ file_ids ) ; }
|
Delete product images
|
54,320
|
protected function validateEditProduct ( ) { $ this -> setSubmitted ( 'product' , null , false ) ; $ this -> setSubmittedBool ( 'status' ) ; $ this -> setSubmittedBool ( 'subtract' ) ; $ this -> setSubmitted ( 'form' , true ) ; $ this -> setSubmitted ( 'update' , $ this -> data_product ) ; if ( isset ( $ this -> data_product [ 'product_id' ] ) ) { $ this -> setSubmitted ( 'user_id' , $ this -> data_product [ 'user_id' ] ) ; $ this -> setSubmitted ( 'created' , $ this -> data_product [ 'created' ] ) ; $ this -> setSubmitted ( 'modified' , $ this -> data_product [ 'modified' ] ) ; $ this -> setSubmitted ( 'currency' , $ this -> data_product [ 'currency' ] ) ; $ this -> setSubmitted ( 'product_id' , $ this -> data_product [ 'product_id' ] ) ; } else { $ this -> setSubmitted ( 'user_id' , $ this -> uid ) ; $ this -> setSubmitted ( 'currency' , $ this -> currency -> getDefault ( ) ) ; } $ this -> validateComponent ( 'product' ) ; return ! $ this -> hasErrors ( ) ; }
|
Validates an array of submitted product data
|
54,321
|
protected function addProduct ( ) { $ this -> controlAccess ( 'product_add' ) ; if ( $ this -> product -> add ( $ this -> getSubmitted ( ) ) ) { $ this -> redirect ( 'admin/content/product' , $ this -> text ( 'Product has been added' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Product has not been added' ) , 'warning' ) ; }
|
Adds a new product
|
54,322
|
protected function setDataAuthorEditProduct ( ) { $ user_id = $ this -> getData ( 'product.user_id' ) ; if ( ! empty ( $ user_id ) ) { $ user = $ this -> user -> get ( $ user_id ) ; $ this -> setData ( 'product.author' , $ user [ 'email' ] ) ; } }
|
Sets the product author data
|
54,323
|
protected function setDataRelatedEditProduct ( ) { $ product_ids = $ this -> getData ( 'product.related' ) ; $ products = array ( ) ; if ( ! empty ( $ product_ids ) ) { $ products = ( array ) $ this -> product -> getList ( array ( 'product_id' => $ product_ids ) ) ; } $ options = array ( 'entity' => 'product' , 'entity_id' => $ product_ids , 'template_item' => 'backend|content/product/suggestion' ) ; foreach ( $ products as & $ product ) { $ this -> setItemThumb ( $ product , $ this -> image , $ options ) ; $ this -> setItemPriceFormatted ( $ product , $ this -> price ) ; $ this -> setItemRendered ( $ product , array ( 'item' => $ product ) , $ options ) ; } $ widget = array ( 'multiple' => true , 'name' => 'product[related]' , 'products' => $ products , 'error' => $ this -> error ( 'related' ) ) ; $ this -> setData ( 'product_picker' , $ this -> getWidgetProductPicker ( $ widget ) ) ; }
|
Sets related products
|
54,324
|
protected function setTitleEditProduct ( ) { if ( isset ( $ this -> data_product [ 'product_id' ] ) ) { $ title = $ this -> text ( 'Edit %name' , array ( '%name' => $ this -> data_product [ 'title' ] ) ) ; } else { $ title = $ this -> text ( 'Add product' ) ; } $ this -> setTitle ( $ title ) ; }
|
Sets titles on the product edit form
|
54,325
|
protected function setBreadcrumbEditProduct ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ breadcrumbs [ ] = array ( 'text' => $ this -> text ( 'Products' ) , 'url' => $ this -> url ( 'admin/content/product' ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
|
Sets breadcrumbs on the product edit page
|
54,326
|
public function product ( array & $ submitted , array $ options = array ( ) ) { $ this -> options = $ options ; $ this -> submitted = & $ submitted ; $ this -> validateProduct ( ) ; $ this -> validateSubtractProduct ( ) ; $ this -> validateBool ( 'status' ) ; $ this -> validateCurrencyProduct ( ) ; $ this -> validateCategoryProduct ( ) ; $ this -> validateUnitProduct ( ) ; $ this -> validatePriceProduct ( ) ; $ this -> validateStockProduct ( ) ; $ this -> validateTitle ( ) ; $ this -> validateDescription ( ) ; $ this -> validateMetaTitle ( ) ; $ this -> validateMetaDescription ( ) ; $ this -> validateTranslation ( ) ; $ this -> validateImages ( ) ; $ this -> validateStoreId ( false ) ; $ this -> validateUserId ( false ) ; $ this -> validateDimensionProduct ( ) ; $ this -> validateRelatedProduct ( ) ; $ this -> validateClassProduct ( ) ; $ this -> validateSkuProduct ( ) ; $ this -> validateAttributeProduct ( ) ; $ this -> validateCombinationProduct ( ) ; $ this -> validateAlias ( ) ; $ this -> validateUploadImages ( 'product' ) ; $ this -> unsetSubmitted ( 'update' ) ; return $ this -> getResult ( ) ; }
|
Performs full product data validation
|
54,327
|
protected function validateProduct ( ) { $ id = $ this -> getUpdatingId ( ) ; if ( $ id === false ) { return null ; } $ data = $ this -> product -> get ( $ id ) ; if ( empty ( $ data ) ) { $ this -> setErrorUnavailable ( 'update' , $ this -> translation -> text ( 'Product' ) ) ; return false ; } $ this -> setUpdating ( $ data ) ; return true ; }
|
Validates a product data
|
54,328
|
protected function validateSubtractProduct ( ) { $ field = 'subtract' ; $ value = $ this -> getSubmitted ( $ field ) ; if ( isset ( $ value ) ) { $ this -> setSubmitted ( $ field , filter_var ( $ value , FILTER_VALIDATE_BOOLEAN ) ) ; } return true ; }
|
Validates Subtract bool value
|
54,329
|
protected function validateCategoryProduct ( ) { $ fields = array ( 'category_id' => $ this -> translation -> text ( 'Category' ) , 'brand_category_id' => $ this -> translation -> text ( 'Brand' ) , ) ; $ errors = 0 ; foreach ( $ fields as $ field => $ label ) { $ value = $ this -> getSubmitted ( $ field ) ; if ( ! isset ( $ value ) ) { continue ; } if ( ! is_numeric ( $ value ) ) { $ errors ++ ; $ this -> setErrorNumeric ( $ field , $ label ) ; continue ; } if ( empty ( $ value ) ) { continue ; } $ category = $ this -> category -> get ( $ value ) ; if ( empty ( $ category [ 'category_id' ] ) ) { $ errors ++ ; $ this -> setErrorUnavailable ( $ field , $ label ) ; } } return empty ( $ errors ) ; }
|
Validates product categories
|
54,330
|
protected function validateUnitProduct ( ) { $ allowed = array ( 'size_unit' => $ this -> convertor -> getUnitNames ( 'size' ) , 'weight_unit' => $ this -> convertor -> getUnitNames ( 'weight' ) ) ; $ fields = array ( 'size_unit' => $ this -> translation -> text ( 'Size unit' ) , 'weight_unit' => $ this -> translation -> text ( 'Weight unit' ) ) ; $ errors = 0 ; foreach ( $ fields as $ field => $ label ) { $ value = $ this -> getSubmitted ( $ field ) ; if ( isset ( $ value ) && ! isset ( $ allowed [ $ field ] [ $ value ] ) ) { $ errors ++ ; $ this -> setErrorUnavailable ( $ field , $ label ) ; } } return empty ( $ errors ) ; }
|
Validates measurement units
|
54,331
|
protected function validateDimensionProduct ( ) { $ fields = array ( 'width' => $ this -> translation -> text ( 'Width' ) , 'height' => $ this -> translation -> text ( 'Height' ) , 'length' => $ this -> translation -> text ( 'Length' ) , 'weight' => $ this -> translation -> text ( 'Weight' ) ) ; $ errors = 0 ; foreach ( $ fields as $ field => $ label ) { $ value = $ this -> getSubmitted ( $ field ) ; if ( ! isset ( $ value ) ) { continue ; } if ( ! is_numeric ( $ value ) ) { $ errors ++ ; $ this -> setErrorNumeric ( $ field , $ label ) ; } if ( strlen ( $ value ) > 10 ) { $ errors ++ ; $ this -> setErrorLengthRange ( $ field , $ label , 0 , 10 ) ; } } return empty ( $ errors ) ; }
|
Validates product dimensions
|
54,332
|
protected function validateRelatedProduct ( ) { $ field = 'related' ; if ( $ this -> isExcluded ( $ field ) || $ this -> isError ( 'store_id' ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( empty ( $ value ) ) { $ this -> setSubmitted ( $ field , array ( ) ) ; return null ; } $ store_id = $ this -> getSubmitted ( 'store_id' ) ; $ product_ids = array ( ) ; foreach ( array_unique ( $ value ) as $ product_id ) { $ product = $ this -> product -> get ( $ product_id ) ; if ( empty ( $ product [ 'store_id' ] ) ) { $ this -> setError ( $ field , $ this -> translation -> text ( 'Some of related products are invalid' ) ) ; return false ; } if ( $ product [ 'store_id' ] != $ store_id ) { $ this -> setError ( $ field , $ this -> translation -> text ( 'All related product must belong to the same store' ) ) ; return false ; } $ product_ids [ $ product [ 'product_id' ] ] = $ product [ 'product_id' ] ; } $ updating = $ this -> getUpdating ( ) ; if ( isset ( $ updating [ 'product_id' ] ) ) { unset ( $ product_ids [ $ updating [ 'product_id' ] ] ) ; } $ this -> setSubmitted ( 'related' , $ product_ids ) ; return true ; }
|
Validates related products
|
54,333
|
protected function validateSkuProduct ( ) { $ field = 'sku' ; if ( $ this -> isExcluded ( $ field ) || $ this -> isError ( ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; $ label = $ this -> translation -> text ( 'SKU' ) ; if ( $ this -> isUpdating ( ) && empty ( $ value ) ) { $ data = $ this -> getSubmitted ( ) ; $ value = $ this -> product -> generateSku ( $ data ) ; $ this -> setSubmitted ( 'sku' , $ value ) ; } if ( isset ( $ value ) && mb_strlen ( $ value ) > 255 ) { $ this -> setErrorLengthRange ( $ field , $ label , 0 , 255 ) ; return false ; } if ( ! empty ( $ value ) ) { $ this -> processed_skus [ $ value ] = true ; } $ updating = $ this -> getUpdating ( ) ; if ( isset ( $ updating [ 'sku' ] ) && $ updating [ 'sku' ] === $ value ) { return true ; } $ product_id = null ; if ( isset ( $ updating [ 'product_id' ] ) ) { $ product_id = $ updating [ 'product_id' ] ; } $ store_id = $ this -> getSubmitted ( 'store_id' ) ; if ( isset ( $ updating [ 'store_id' ] ) ) { $ store_id = $ updating [ 'store_id' ] ; } $ existing = $ this -> sku -> get ( array ( 'sku' => $ value , 'store_id' => $ store_id ) ) ; if ( isset ( $ product_id ) && isset ( $ existing [ 'product_id' ] ) && $ existing [ 'product_id' ] == $ product_id ) { return true ; } if ( ! empty ( $ existing ) ) { $ this -> setErrorExists ( $ field , $ label ) ; return false ; } return true ; }
|
Validates a product SKU
|
54,334
|
protected function validateClassProduct ( ) { $ field = 'product_class_id' ; $ value = $ this -> getSubmitted ( $ field ) ; if ( empty ( $ value ) ) { return null ; } $ label = $ this -> translation -> text ( 'Product class' ) ; if ( ! is_numeric ( $ value ) ) { $ this -> setErrorNumeric ( $ field , $ label ) ; return false ; } $ product_class = $ this -> product_class -> get ( $ value ) ; if ( empty ( $ product_class ) ) { $ this -> setErrorUnavailable ( $ field , $ label ) ; return false ; } $ fields = $ this -> product_class -> getFields ( $ value ) ; $ this -> setSubmitted ( 'product_fields' , $ fields ) ; return true ; }
|
Validates a product class
|
54,335
|
protected function validateAttributeProduct ( ) { $ fields = $ this -> getSubmitted ( 'product_fields.attribute' ) ; if ( empty ( $ fields ) ) { return null ; } $ attributes = $ this -> getSubmitted ( 'field.attribute' ) ; $ errors = 0 ; foreach ( $ fields as $ field_id => $ field ) { if ( ! empty ( $ field [ 'required' ] ) && empty ( $ attributes [ $ field_id ] ) ) { $ this -> setErrorRequired ( "attribute.$field_id" , $ field [ 'title' ] ) ; $ errors ++ ; } } return empty ( $ errors ) ; }
|
Validates an array of product attributes
|
54,336
|
protected function validateCombinationProduct ( ) { $ combinations = $ this -> getSubmitted ( 'combination' ) ; if ( empty ( $ combinations ) ) { return null ; } $ index = 1 ; foreach ( $ combinations as & $ combination ) { $ combination [ 'status' ] = ! empty ( $ combination [ 'status' ] ) ; $ this -> validateCombinationOptionsProduct ( $ index , $ combination ) ; if ( $ this -> isError ( "combination.$index" ) ) { continue ; } if ( empty ( $ combination [ 'fields' ] ) ) { unset ( $ combinations [ $ index ] ) ; continue ; } $ combination_id = $ this -> sku -> getCombinationId ( $ combination [ 'fields' ] ) ; if ( isset ( $ this -> processed_combinations [ $ combination_id ] ) ) { $ error = $ this -> translation -> text ( 'Combination already exists' ) ; $ this -> setError ( "combination.$index.exists" , $ error ) ; } $ this -> validateCombinationSkuProduct ( $ index , $ combination ) ; $ this -> validateCombinationPriceProduct ( $ index , $ combination ) ; $ this -> validateCombinationStockProduct ( $ index , $ combination ) ; foreach ( $ combination [ 'fields' ] as $ field_value_id ) { if ( ! isset ( $ this -> stock_amount [ $ field_value_id ] ) ) { $ this -> stock_amount [ $ field_value_id ] = ( int ) $ combination [ 'stock' ] ; } } $ this -> processed_combinations [ $ combination_id ] = true ; $ index ++ ; } if ( $ this -> isError ( ) ) { return false ; } $ this -> setSubmitted ( 'combination' , $ combinations ) ; $ this -> setSubmitted ( 'stock' , array_sum ( $ this -> stock_amount ) ) ; return true ; }
|
Validates an array of product combinations
|
54,337
|
protected function validateCombinationOptionsProduct ( $ index , & $ combination ) { $ options = $ this -> getSubmitted ( 'product_fields.option' ) ; if ( empty ( $ options ) ) { return null ; } $ errors = 0 ; foreach ( $ options as $ field_id => $ field ) { if ( ! empty ( $ field [ 'required' ] ) && ! isset ( $ combination [ 'fields' ] [ $ field_id ] ) ) { $ this -> setErrorRequired ( "combination.$index.fields.$field_id" , $ field [ 'title' ] ) ; $ errors ++ ; } } return empty ( $ errors ) ; }
|
Validates option combination fields
|
54,338
|
protected function validateCombinationSkuProduct ( $ index , & $ combination ) { if ( ! isset ( $ combination [ 'sku' ] ) ) { return null ; } if ( $ combination [ 'sku' ] === '' ) { return true ; } $ updating = $ this -> getUpdating ( ) ; $ product_id = null ; if ( isset ( $ updating [ 'product_id' ] ) ) { $ product_id = $ updating [ 'product_id' ] ; } if ( mb_strlen ( $ combination [ 'sku' ] ) > 255 ) { $ this -> setErrorLengthRange ( "combination.$index.sku" , $ this -> translation -> text ( 'SKU' ) , 0 , 255 ) ; return false ; } if ( isset ( $ this -> processed_skus [ $ combination [ 'sku' ] ] ) ) { $ error = $ this -> translation -> text ( 'SKU must be unique per store' ) ; $ this -> setError ( "combination.$index.sku" , $ error ) ; return false ; } $ store_id = $ this -> getSubmitted ( 'store_id' ) ; $ existing = $ this -> sku -> get ( array ( 'sku' => $ combination [ 'sku' ] , 'store_id' => $ store_id ) ) ; if ( isset ( $ product_id ) && isset ( $ existing [ 'product_id' ] ) && $ existing [ 'product_id' ] == $ product_id ) { $ this -> processed_skus [ $ combination [ 'sku' ] ] = true ; return true ; } if ( ! empty ( $ existing ) ) { $ error = $ this -> translation -> text ( 'SKU must be unique per store' ) ; $ this -> setError ( "combination.$index.sku" , $ error ) ; return false ; } $ this -> processed_skus [ $ combination [ 'sku' ] ] = true ; return true ; }
|
Validates option combination SKUs
|
54,339
|
protected function validateCombinationPriceProduct ( $ index , & $ combination ) { $ price = $ this -> getSubmitted ( 'price' ) ; if ( empty ( $ combination [ 'price' ] ) ) { $ combination [ 'price' ] = $ price ; } if ( ! is_numeric ( $ combination [ 'price' ] ) || strlen ( $ combination [ 'price' ] ) > 10 ) { $ error = $ this -> translation -> text ( 'Only numeric values and no longer than @num characters' , array ( '@num' => 10 ) ) ; $ this -> setError ( "combination.$index.price" , $ error ) ; } return ! isset ( $ error ) ; }
|
Validates combination stock price
|
54,340
|
protected function validateCombinationStockProduct ( $ index , & $ combination ) { if ( empty ( $ combination [ 'stock' ] ) ) { return null ; } if ( ! is_numeric ( $ combination [ 'stock' ] ) || strlen ( $ combination [ 'stock' ] ) > 10 ) { $ error = $ this -> translation -> text ( 'Only numeric values and no longer than @num characters' , array ( '@num' => 10 ) ) ; $ this -> setError ( "combination.$index.stock" , $ error ) ; } return ! isset ( $ error ) ; }
|
Validates combination stock level
|
54,341
|
public function getList ( array $ options = array ( ) ) { $ result = null ; $ this -> hook -> attach ( 'sku.list.before' , $ options , $ result , $ this ) ; if ( isset ( $ result ) ) { return $ result ; } $ sql = 'SELECT ps.*, p.title, p.currency' ; if ( ! empty ( $ options [ 'count' ] ) ) { $ sql = 'SELECT COUNT(ps.product_sku_id)' ; } $ sql .= ' FROM product_sku ps LEFT JOIN product p ON(ps.product_id = p.product_id)' ; $ conditions = array ( ) ; if ( isset ( $ options [ 'product_sku_id' ] ) ) { $ sql .= ' WHERE ps.product_sku_id = ?' ; $ conditions [ ] = $ options [ 'product_sku_id' ] ; } else { $ sql .= ' WHERE ps.product_sku_id IS NOT NULL' ; } if ( isset ( $ options [ 'sku' ] ) ) { $ sql .= ' AND ps.sku=?' ; $ conditions [ ] = $ options [ 'sku' ] ; } if ( isset ( $ options [ 'store_id' ] ) ) { $ sql .= ' AND p.store_id=?' ; $ conditions [ ] = $ options [ 'store_id' ] ; } if ( isset ( $ options [ 'title_sku' ] ) ) { $ sql .= ' AND (p.title LIKE ? OR ps.sku LIKE ?)' ; $ conditions [ ] = "%{$options['title_sku']}%" ; $ conditions [ ] = "%{$options['title_sku']}%" ; } if ( isset ( $ options [ 'product_id' ] ) ) { $ sql .= ' AND ps.product_id=?' ; $ conditions [ ] = $ options [ 'product_id' ] ; } if ( isset ( $ options [ 'combination_id' ] ) ) { $ sql .= ' AND ps.combination_id=?' ; $ conditions [ ] = $ options [ 'combination_id' ] ; } if ( isset ( $ options [ 'status' ] ) ) { $ sql .= ' AND ps.status=?' ; $ conditions [ ] = ( int ) $ options [ 'status' ] ; } $ sql .= " ORDER BY ps.sku ASC" ; if ( ! empty ( $ options [ 'limit' ] ) ) { $ sql .= ' LIMIT ' . implode ( ',' , array_map ( 'intval' , $ options [ 'limit' ] ) ) ; } if ( empty ( $ options [ 'count' ] ) ) { $ list = $ this -> db -> fetchAll ( $ sql , $ conditions , array ( 'index' => 'product_sku_id' ) ) ; $ result = $ this -> prepareList ( $ list ) ; } else { $ result = ( int ) $ this -> db -> fetchColumn ( $ sql , $ conditions ) ; } $ this -> hook -> attach ( 'sku.list.after' , $ options , $ result , $ this ) ; return $ result ; }
|
Returns an array of SKUs or counts them
|
54,342
|
public function delete ( $ product_id , array $ options = array ( ) ) { $ result = null ; $ this -> hook -> attach ( 'sku.delete.before' , $ product_id , $ options , $ result , $ this ) ; if ( isset ( $ result ) ) { return ( bool ) $ result ; } $ sql = 'DELETE FROM product_sku WHERE product_id=?' ; if ( ! empty ( $ options [ 'combinations' ] ) ) { $ sql .= ' AND LENGTH(combination_id) > 0' ; } if ( ! empty ( $ options [ 'base' ] ) ) { $ sql .= ' AND LENGTH(combination_id) = 0' ; } $ result = ( bool ) $ this -> db -> run ( $ sql , array ( $ product_id ) ) -> rowCount ( ) ; $ this -> hook -> attach ( 'sku.delete.after' , $ product_id , $ options , $ result , $ this ) ; return ( bool ) $ result ; }
|
Deletes a product SKU
|
54,343
|
public function generate ( $ pattern , array $ options = array ( ) ) { $ options += array ( 'store_id' => null , 'placeholders' => array ( ) ) ; $ result = null ; $ this -> hook -> attach ( 'sku.generate.before' , $ pattern , $ options , $ result ) ; if ( isset ( $ result ) ) { return ( string ) $ result ; } $ sku = $ pattern ; if ( ! empty ( $ options [ 'placeholders' ] ) ) { $ sku = gplcart_string_replace ( $ pattern , $ options [ 'placeholders' ] , $ options ) ; } $ result = $ this -> getUnique ( mb_strimwidth ( $ sku , 0 , 200 , '' ) , $ options [ 'store_id' ] ) ; $ this -> hook -> attach ( 'sku.generate.after' , $ pattern , $ options , $ result ) ; return $ result ; }
|
Generates a SKU
|
54,344
|
public function getUnique ( $ sku , $ store_id ) { $ existing = $ this -> get ( array ( 'sku' => $ sku , 'store_id' => $ store_id ) ) ; if ( empty ( $ existing ) ) { return $ sku ; } $ counter = 1 ; do { $ modified = $ sku . '-' . $ counter ; $ counter ++ ; } while ( $ this -> get ( array ( 'sku' => $ modified , 'store_id' => $ store_id ) ) ) ; return $ modified ; }
|
Returns a unique SKU for the given store ID
|
54,345
|
public function getFieldValues ( $ combination_id ) { $ field_value_ids = explode ( '_' , substr ( $ combination_id , strpos ( $ combination_id , '-' ) + 1 ) ) ; sort ( $ field_value_ids ) ; return $ field_value_ids ; }
|
Returns an array of field value IDs from a combination ID
|
54,346
|
public function getCombinationId ( array $ field_value_ids , $ product_id = null ) { sort ( $ field_value_ids ) ; $ combination_id = implode ( '_' , $ field_value_ids ) ; return empty ( $ product_id ) ? $ combination_id : "$product_id-$combination_id" ; }
|
Creates a field combination id from an array of field value ids
|
54,347
|
protected function prepareList ( array $ list ) { foreach ( $ list as & $ item ) { $ item [ 'fields' ] = $ this -> getFieldValues ( $ item [ 'combination_id' ] ) ; } return $ list ; }
|
Prepare an array of product SKU items
|
54,348
|
protected function getRelatedFieldValues ( array $ product , array $ ids ) { $ related = array ( ) ; foreach ( $ product [ 'combination' ] as $ combination ) { if ( array_intersect ( $ ids , $ combination [ 'fields' ] ) ) { $ related += $ combination [ 'fields' ] ; } } return $ related ; }
|
Returns an array of related fields value IDs
|
54,349
|
protected function init ( ) { parent :: init ( ) ; $ this -> text = 'Submit' ; $ this -> attributes [ 'type' ] = 'submit' ; $ this -> attributes [ 'id' ] = ! $ this -> name ? $ this -> attributes [ 'id' ] . 'submit' : $ this -> attributes [ 'id' ] ; }
|
Initialize field settings
|
54,350
|
public function accountOrder ( $ user_id , $ order_id ) { $ this -> setUserAccountOrder ( $ user_id ) ; $ this -> setOrderAccountOrder ( $ order_id ) ; $ this -> setTitleAccountOrder ( ) ; $ this -> setBreadcrumbAccountOrder ( ) ; $ this -> setData ( 'user' , $ this -> data_user ) ; $ this -> setDataPanelSummaryAccountOrder ( ) ; $ this -> setDataPanelComponentsAccountOrder ( ) ; $ this -> setDataPanelPaymentAddressAccountOrder ( ) ; $ this -> setDataPanelShippingAddressAccountOrder ( ) ; $ this -> outputAccountOrder ( ) ; }
|
Page callback Displays the order overview page
|
54,351
|
protected function setBreadcrumbAccountOrder ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( '/' ) , 'text' => $ this -> text ( 'Shop' ) ) ; $ breadcrumbs [ ] = array ( 'text' => $ this -> text ( 'Orders' ) , 'url' => $ this -> url ( "account/{$this->data_user['user_id']}" ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
|
Sets breadcrumbs on the order overview page
|
54,352
|
protected function setOrderAccountOrder ( $ order_id ) { $ this -> data_order = $ this -> order -> get ( $ order_id ) ; if ( empty ( $ this -> data_order ) ) { $ this -> outputHttpStatus ( 404 ) ; } $ this -> prepareOrderAccountOrder ( $ this -> data_order ) ; }
|
Sets an order data
|
54,353
|
protected function prepareOrderComponentsAccountOrder ( array & $ order ) { $ this -> setItemOrderCartComponent ( $ order , $ this -> price ) ; $ this -> setItemOrderPriceRuleComponent ( $ order , $ this -> price , $ this -> price_rule ) ; $ this -> setItemOrderPaymentComponent ( $ order , $ this -> price , $ this -> payment , $ this -> order ) ; $ this -> setItemOrderShippingComponent ( $ order , $ this -> price , $ this -> shipping , $ this -> order ) ; ksort ( $ order [ 'data' ] [ 'components' ] ) ; }
|
Prepare order components
|
54,354
|
protected function setDataPanelComponentsAccountOrder ( ) { $ order = $ this -> data_order ; $ this -> prepareOrderComponentsAccountOrder ( $ order ) ; $ data = array ( 'order' => $ order , 'components' => $ order [ 'data' ] [ 'components' ] ) ; $ this -> setData ( 'components' , $ this -> render ( 'account/order/components' , $ data ) ) ; }
|
Sets the order components panel on the order overview page
|
54,355
|
public function viewHelp ( $ hash ) { $ this -> setFileHelp ( $ hash ) ; $ this -> setTitleViewHelp ( ) ; $ this -> setBreadcrumbViewHelp ( ) ; $ this -> setData ( 'help' , $ this -> renderHelp ( ) ) ; $ this -> outputViewHelp ( ) ; }
|
View a help item
|
54,356
|
protected function setTitleViewHelp ( ) { $ meta = $ this -> help -> getMeta ( $ this -> data_file ) ; $ this -> setTitle ( $ meta [ 'title' ] ) ; }
|
Sets titles on the view help page
|
54,357
|
protected function setBreadcrumbViewHelp ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin/help' ) , 'text' => $ this -> text ( 'Help' ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
|
Sets breadcrumbs on the view help page
|
54,358
|
protected function setFileHelp ( $ hash ) { $ this -> data_file = gplcart_path_absolute ( gplcart_string_decode ( $ hash ) ) ; if ( ! is_file ( $ this -> data_file ) ) { $ this -> outputHttpStatus ( 404 ) ; } }
|
Sets help file path
|
54,359
|
public function listHelp ( ) { $ this -> setTitleListHelp ( ) ; $ this -> setBreadcrumbListHelp ( ) ; $ this -> setData ( 'items' , $ this -> getListHelp ( ) ) ; $ this -> outputListHelp ( ) ; }
|
Displays the help list page
|
54,360
|
protected function setBreadcrumbListHelp ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
|
Sets breadcrumbs on the help list page
|
54,361
|
public function isMet ( array $ trigger , array $ data ) { $ result = null ; $ this -> hook -> attach ( 'condition.met.before' , $ trigger , $ data , $ result , $ this ) ; if ( isset ( $ result ) ) { return ( bool ) $ result ; } if ( empty ( $ trigger [ 'data' ] [ 'conditions' ] ) ) { return false ; } $ result = true ; $ this -> processed = array ( ) ; foreach ( $ trigger [ 'data' ] [ 'conditions' ] as $ condition ) { if ( $ this -> callHandler ( $ condition , $ data ) !== true ) { $ result = false ; break ; } $ this -> processed [ ] = $ condition [ 'id' ] ; } $ this -> hook -> attach ( 'condition.met.after' , $ trigger , $ data , $ result , $ this ) ; return ( bool ) $ result ; }
|
Whether all conditions are met
|
54,362
|
protected function callHandler ( array $ condition , array $ data ) { try { $ handlers = $ this -> getHandlers ( ) ; return Handler :: call ( $ handlers , $ condition [ 'id' ] , 'process' , array ( $ condition , $ data , $ this ) ) ; } catch ( Exception $ ex ) { return false ; } }
|
Call a condition handler
|
54,363
|
public function getOperators ( ) { return array ( "<" => $ this -> translation -> text ( 'Less than' ) , ">" => $ this -> translation -> text ( 'Greater than' ) , "=" => $ this -> translation -> text ( 'Equal (is in list)' ) , "<=" => $ this -> translation -> text ( 'Less than or equal to' ) , ">=" => $ this -> translation -> text ( 'Greater than or equal to' ) , "!=" => $ this -> translation -> text ( 'Not equal (is not in list)' ) ) ; }
|
Returns an array of condition operators
|
54,364
|
public function fieldValue ( array & $ submitted , array $ options = array ( ) ) { $ this -> options = $ options ; $ this -> submitted = & $ submitted ; $ this -> validateFieldValue ( ) ; $ this -> validateTitle ( ) ; $ this -> validateWeight ( ) ; $ this -> validateTranslation ( ) ; $ this -> validateFieldFieldValue ( ) ; $ this -> validateColorFieldValue ( ) ; $ this -> validateUploadImages ( 'field_value' ) ; $ this -> unsetSubmitted ( 'update' ) ; $ this -> unsetSubmitted ( 'field' ) ; return $ this -> getResult ( ) ; }
|
Performs full field value data validation
|
54,365
|
protected function validateFieldValue ( ) { $ id = $ this -> getUpdatingId ( ) ; if ( $ id === false ) { return null ; } $ data = $ this -> field_value -> get ( $ id ) ; if ( empty ( $ data ) ) { $ this -> setErrorUnavailable ( 'update' , $ this -> translation -> text ( 'Field value' ) ) ; return false ; } $ this -> setUpdating ( $ data ) ; return true ; }
|
Validates a field value to be updated
|
54,366
|
protected function validateColorFieldValue ( ) { $ field = 'color' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( ! isset ( $ value ) || $ value === '' ) { return null ; } if ( preg_match ( '/#([a-fA-F0-9]{3}){1,2}\b/' , $ value ) !== 1 ) { $ this -> setErrorInvalid ( $ field , $ this -> translation -> text ( 'Color' ) ) ; return false ; } if ( $ value === '#000000' ) { $ this -> setSubmitted ( $ field , '' ) ; } return true ; }
|
Validates a color code
|
54,367
|
public function getNextWeight ( $ type , $ pos ) { $ step = 20 ; $ count = $ this -> count ( $ type , $ pos ) ; return $ count * $ step + $ step ; }
|
Returns a weight for the next asset
|
54,368
|
public function getMaxWeight ( $ type , $ pos ) { if ( empty ( $ this -> assets [ $ type ] [ $ pos ] ) ) { return null ; } $ weights = array ( ) ; foreach ( $ this -> assets [ $ type ] [ $ pos ] as $ asset ) { $ weights [ ] = $ asset [ 'weight' ] ; } return max ( $ weights ) ; }
|
Returns the max weight of added assets
|
54,369
|
public function count ( $ type , $ pos ) { return empty ( $ this -> assets [ $ type ] [ $ pos ] ) ? 0 : count ( $ this -> assets [ $ type ] [ $ pos ] ) ; }
|
Returns a weight of the last added asset
|
54,370
|
public function get ( $ type , $ position ) { if ( empty ( $ this -> assets [ $ type ] [ $ position ] ) ) { return array ( ) ; } return $ this -> assets [ $ type ] [ $ position ] ; }
|
Returns an array of asset items
|
54,371
|
public function set ( array $ data ) { $ build = $ this -> build ( $ data ) ; if ( empty ( $ build [ 'asset' ] ) ) { return false ; } if ( ! empty ( $ build [ 'merge' ] ) && is_array ( $ build [ 'asset' ] ) ) { if ( isset ( $ this -> assets [ $ build [ 'type' ] ] [ $ build [ 'position' ] ] [ $ build [ 'merge' ] ] ) ) { $ existing = $ this -> assets [ $ build [ 'type' ] ] [ $ build [ 'position' ] ] [ $ build [ 'merge' ] ] [ 'asset' ] ; $ this -> assets [ $ build [ 'type' ] ] [ $ build [ 'position' ] ] [ $ build [ 'merge' ] ] [ 'asset' ] = array_merge ( $ existing , $ build [ 'asset' ] ) ; } } if ( isset ( $ this -> assets [ $ build [ 'type' ] ] [ $ build [ 'position' ] ] [ $ build [ 'key' ] ] ) ) { return false ; } $ this -> assets [ $ build [ 'type' ] ] [ $ build [ 'position' ] ] [ $ build [ 'key' ] ] = $ build ; return $ this -> assets [ $ build [ 'type' ] ] ; }
|
Sets an asset
|
54,372
|
public function build ( array $ data ) { if ( is_array ( $ data [ 'asset' ] ) ) { $ type = 'js' ; } else if ( strpos ( $ data [ 'asset' ] , 'http' ) === 0 ) { $ type = 'external' ; } else { $ type = pathinfo ( $ data [ 'asset' ] , PATHINFO_EXTENSION ) ; } $ data += array ( 'file' => '' , 'key' => null , 'merge' => '' , 'version' => '' , 'type' => $ type , 'text' => false , 'condition' => '' , 'position' => 'top' ) ; if ( ! isset ( $ data [ 'weight' ] ) ) { $ data [ 'weight' ] = $ this -> getNextWeight ( $ data [ 'type' ] , $ data [ 'position' ] ) ; } if ( ! in_array ( $ data [ 'type' ] , array ( 'css' , 'js' ) ) ) { $ data [ 'text' ] = true ; } if ( ( $ type !== 'external' && $ type != $ data [ 'type' ] ) || is_array ( $ data [ 'asset' ] ) ) { $ data [ 'text' ] = true ; } if ( $ data [ 'text' ] ) { if ( ! isset ( $ data [ 'key' ] ) ) { $ data [ 'key' ] = 'text.' . md5 ( json_encode ( $ data [ 'asset' ] ) ) ; } return $ data ; } if ( gplcart_path_is_absolute ( $ data [ 'asset' ] ) ) { $ data [ 'file' ] = $ data [ 'asset' ] ; $ data [ 'asset' ] = gplcart_path_relative ( $ data [ 'asset' ] ) ; } else if ( $ type !== 'external' ) { $ data [ 'file' ] = gplcart_path_absolute ( $ data [ 'asset' ] ) ; } if ( ! empty ( $ data [ 'file' ] ) ) { if ( ! file_exists ( $ data [ 'file' ] ) ) { return array ( ) ; } $ data [ 'version' ] = filemtime ( $ data [ 'file' ] ) ; } $ data [ 'key' ] = $ data [ 'asset' ] = str_replace ( '\\' , '/' , $ data [ 'asset' ] ) ; return $ data ; }
|
Builds asset data
|
54,373
|
public function listModule ( ) { $ this -> actionListModule ( ) ; $ this -> setTitleListModule ( ) ; $ this -> setBreadcrumbListModule ( ) ; $ this -> setFilterListModule ( ) ; $ this -> setPagerListModule ( ) ; $ this -> setData ( 'types' , $ this -> getTypesModule ( ) ) ; $ this -> setData ( 'modules' , ( array ) $ this -> getListModule ( ) ) ; $ this -> setData ( 'available_modules' , $ this -> module -> getList ( ) ) ; $ this -> outputListModule ( ) ; }
|
Displays the module admin overview page
|
54,374
|
protected function actionListModule ( ) { $ this -> controlToken ( 'action' ) ; $ action = $ this -> getQuery ( 'action' ) ; $ module_id = $ this -> getQuery ( 'module_id' ) ; if ( ! empty ( $ action ) && ! empty ( $ module_id ) ) { $ this -> setModule ( $ module_id ) ; $ result = $ this -> startActionModule ( $ action ) ; $ this -> finishActionModule ( $ result ) ; } }
|
Applies an action to a module
|
54,375
|
protected function setModule ( $ module_id ) { $ this -> data_module = $ this -> module -> get ( $ module_id ) ; if ( empty ( $ this -> data_module ) ) { $ this -> outputHttpStatus ( 403 ) ; } }
|
Set a module data
|
54,376
|
protected function finishActionModule ( $ result ) { if ( $ result === true ) { $ this -> redirect ( '' , $ this -> text ( 'Module has been updated' ) , 'success' ) ; } $ message = $ result ? $ result : $ this -> text ( 'Operation unavailable' ) ; $ this -> redirect ( '' , $ message , 'danger' ) ; }
|
Finishes module action
|
54,377
|
protected function startActionModule ( $ action ) { $ this -> controlAccess ( "module_$action" ) ; switch ( $ action ) { case 'enable' : return $ this -> module_model -> enable ( $ this -> data_module [ 'id' ] ) ; case 'disable' : return $ this -> module_model -> disable ( $ this -> data_module [ 'id' ] ) ; case 'install' : return $ this -> module_model -> install ( $ this -> data_module [ 'id' ] ) ; case 'uninstall' : return $ this -> module_model -> uninstall ( $ this -> data_module [ 'id' ] ) ; } $ this -> outputHttpStatus ( 403 ) ; return null ; }
|
Performs an action against a module
|
54,378
|
protected function prepareListModule ( array & $ list ) { foreach ( $ list as & $ item ) { $ item [ 'has_dependencies' ] = ! empty ( $ item [ 'requires' ] ) || ! empty ( $ item [ 'required_by' ] ) ; } }
|
Prepare an array of modules
|
54,379
|
protected function checkDependenciesListModule ( array & $ list ) { $ this -> validateDependencies ( $ list ) ; $ list = $ this -> graph -> build ( $ list ) ; }
|
Validates module dependencies
|
54,380
|
protected function getTypesModule ( ) { $ types = array ( ) ; foreach ( $ this -> module -> getList ( ) as $ module ) { $ types [ $ module [ 'type' ] ] = $ this -> text ( ucfirst ( $ module [ 'type' ] ) ) ; } return $ types ; }
|
Returns an array of module types
|
54,381
|
public function run ( ) { $ result = null ; $ this -> hook -> attach ( 'cron.run.before' , $ result , $ this ) ; if ( isset ( $ result ) ) { return ( bool ) $ result ; } ini_set ( 'max_execution_time' , 0 ) ; register_shutdown_function ( array ( $ this , 'shutdownHandler' ) ) ; $ this -> logger -> log ( 'cron' , 'Cron has started' , 'info' ) ; try { $ result = $ this -> process ( ) ; } catch ( Exception $ ex ) { $ this -> logger -> log ( 'cron' , $ ex -> getMessage ( ) , 'danger' , false ) ; $ result = false ; } $ this -> hook -> attach ( 'cron.run.after' , $ result , $ this ) ; $ this -> config -> set ( 'cron_last_run' , GC_TIME ) ; return ( bool ) $ result ; }
|
Run cron tasks
|
54,382
|
public function process ( ) { $ this -> report -> deleteExpired ( ) ; $ this -> history -> deleteExpired ( ) ; foreach ( gplcart_file_scan_recursive ( GC_DIR_PRIVATE_TEMP ) as $ file ) { if ( strpos ( basename ( $ file ) , '.' ) !== 0 ) { gplcart_file_delete_recursive ( $ file ) ; } } $ result = $ this -> report -> checkFilesystem ( ) ; if ( $ result !== true ) { foreach ( ( array ) $ result as $ message ) { $ this -> logger -> log ( 'system_status' , array ( 'message' => $ message ) , 'warning' ) ; } } return true ; }
|
Processes all defined tasks
|
54,383
|
protected function outputCommandListHelp ( ) { $ routes = $ this -> route -> getList ( ) ; ksort ( $ routes ) ; $ rows = array ( array ( $ this -> text ( 'Command' ) , $ this -> text ( 'Alias' ) , $ this -> text ( 'Description' ) ) ) ; foreach ( $ routes as $ command => $ info ) { $ rows [ ] = array ( $ command , empty ( $ info [ 'alias' ] ) ? '' : $ info [ 'alias' ] , empty ( $ info [ 'description' ] ) ? '' : $ info [ 'description' ] ) ; } $ this -> table ( $ rows ) ; $ this -> output ( ) ; }
|
Output a list of all available CLI commands
|
54,384
|
protected function outputCommandHelp ( ) { $ command = $ this -> getParam ( 0 ) ; if ( ! empty ( $ command ) ) { $ this -> outputHelp ( $ command ) ; $ this -> output ( ) ; } }
|
Displays help message for a command
|
54,385
|
public function to ( $ unit , $ decimals = null , $ round = true ) { if ( ! isset ( $ this -> value ) ) { throw new InvalidArgumentException ( 'From value not set' ) ; } if ( is_array ( $ unit ) ) { return $ this -> toMany ( $ unit , $ decimals , $ round ) ; } $ key = strtolower ( $ unit ) ; if ( empty ( $ this -> units [ $ key ] [ 'base' ] ) ) { throw new OutOfBoundsException ( 'Unit does not exist' ) ; } if ( ! isset ( $ this -> base_unit ) ) { $ this -> base_unit = $ this -> units [ $ key ] [ 'base' ] ; } if ( $ this -> units [ $ key ] [ 'base' ] != $ this -> base_unit ) { throw new InvalidArgumentException ( 'Cannot convert between units of different types' ) ; } if ( is_callable ( $ this -> units [ $ key ] [ 'conversion' ] ) ) { $ result = $ this -> units [ $ unit ] [ 'conversion' ] ( $ this -> value , true ) ; } else { $ result = $ this -> value / $ this -> units [ $ key ] [ 'conversion' ] ; } if ( ! isset ( $ decimals ) ) { return $ result ; } if ( $ round ) { return round ( $ result , $ decimals ) ; } $ shifter = $ decimals ? pow ( 10 , $ decimals ) : 1 ; return floor ( $ result * $ shifter ) / $ shifter ; }
|
Convert from value to new unit
|
54,386
|
public function toAll ( $ decimals = null , $ round = true ) { if ( ! isset ( $ this -> value ) ) { throw new InvalidArgumentException ( 'From value not set' ) ; } if ( empty ( $ this -> base_unit ) ) { throw new InvalidArgumentException ( 'No from unit set' ) ; } $ units = array ( ) ; foreach ( $ this -> units as $ key => $ data ) { if ( $ data [ 'base' ] == $ this -> base_unit ) { array_push ( $ units , $ key ) ; } } return $ this -> toMany ( $ units , $ decimals , $ round ) ; }
|
Convert from value to all compatible units
|
54,387
|
public function getConversions ( $ unit ) { if ( ! isset ( $ this -> units [ $ unit ] [ 'base' ] ) ) { throw new OutOfBoundsException ( 'Unit is not set' ) ; } $ units = array ( ) ; foreach ( $ this -> units as $ key => $ value ) { if ( isset ( $ value [ 'base' ] ) && $ value [ 'base' ] === $ this -> units [ $ unit ] [ 'base' ] ) { array_push ( $ units , $ key ) ; } } return $ units ; }
|
List all available conversion units for given unit
|
54,388
|
public function getUnits ( $ type = null ) { if ( ! isset ( $ type ) ) { return $ this -> units ; } $ filtered = array ( ) ; foreach ( $ this -> units as $ key => $ value ) { if ( isset ( $ value [ 'type' ] ) && $ value [ 'type' ] === $ type ) { $ filtered [ $ key ] = $ value ; } } return $ filtered ; }
|
Returns an array of units
|
54,389
|
public function getUnitNames ( $ type = null ) { $ names = array ( ) ; foreach ( $ this -> getUnits ( $ type ) as $ key => $ value ) { $ names [ $ key ] = $ value [ 'name' ] ; } return $ names ; }
|
Returns an array of unit names
|
54,390
|
public function convert ( $ value , $ from , $ to , $ decimals = 2 ) { return ( float ) $ this -> from ( $ value , $ from ) -> to ( $ to , $ decimals , ! empty ( $ decimals ) ) ; }
|
Shortcut method to convert units
|
54,391
|
protected function toBase ( $ value , array $ unit ) { if ( is_callable ( $ unit [ 'conversion' ] ) ) { return $ unit [ 'conversion' ] ( $ value , false ) ; } return $ value * $ unit [ 'conversion' ] ; }
|
Convert from value to its base unit
|
54,392
|
protected function toMany ( array $ units , $ decimals = null , $ round = true ) { $ results = array ( ) ; foreach ( $ units as $ key ) { $ results [ $ key ] = $ this -> to ( $ key , $ decimals , $ round ) ; } return $ results ; }
|
Iterate through multiple unit conversions
|
54,393
|
public function userRole ( array & $ submitted , array $ options = array ( ) ) { $ this -> options = $ options ; $ this -> submitted = & $ submitted ; $ this -> validateUserRole ( ) ; $ this -> validatePermissionsUserRole ( ) ; $ this -> validateRedirectUserRole ( ) ; $ this -> validateBool ( 'status' ) ; $ this -> validateName ( ) ; $ this -> unsetSubmitted ( 'update' ) ; return $ this -> getResult ( ) ; }
|
Performs full user role data validation
|
54,394
|
protected function validateUserRole ( ) { $ id = $ this -> getUpdatingId ( ) ; if ( $ id === false ) { return null ; } $ data = $ this -> role -> get ( $ id ) ; if ( empty ( $ data ) ) { $ this -> setErrorUnavailable ( 'update' , $ this -> translation -> text ( 'Role' ) ) ; return false ; } $ this -> setUpdating ( $ data ) ; return true ; }
|
Validates a user role to be updated
|
54,395
|
protected function validatePermissionsUserRole ( ) { $ field = 'permissions' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( $ this -> isUpdating ( ) && ! isset ( $ value ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } if ( empty ( $ value ) ) { $ this -> setSubmitted ( $ field , array ( ) ) ; return null ; } if ( ! is_array ( $ value ) ) { $ this -> setErrorInvalid ( $ field , $ this -> translation -> text ( 'Permissions' ) ) ; return false ; } $ permissions = $ this -> role -> getPermissions ( ) ; $ invalid = array_diff ( $ value , array_keys ( $ permissions ) ) ; if ( ! empty ( $ invalid ) ) { $ this -> setErrorUnavailable ( $ field , implode ( ',' , $ invalid ) ) ; return false ; } return true ; }
|
Validates permissions data
|
54,396
|
protected function validateRedirectUserRole ( ) { $ value = $ this -> getSubmitted ( 'redirect' ) ; if ( isset ( $ value ) && mb_strlen ( $ value ) > 255 ) { $ this -> setErrorLengthRange ( 'redirect' , $ this -> translation -> text ( 'Redirect' ) , 0 , 255 ) ; return false ; } return true ; }
|
Validates a redirect path
|
54,397
|
protected function compare ( $ a , $ b , $ operator ) { settype ( $ a , 'array' ) ; settype ( $ b , 'array' ) ; if ( in_array ( $ operator , array ( '>=' , '<=' , '>' , '<' ) ) ) { $ a = reset ( $ a ) ; $ b = reset ( $ b ) ; } switch ( $ operator ) { case '>=' : return $ a >= $ b ; case '<=' : return $ a <= $ b ; case '>' : return $ a > $ b ; case '<' : return $ a < $ b ; case '=' : return count ( array_intersect ( $ a , $ b ) ) > 0 ; case '!=' : return count ( array_intersect ( $ a , $ b ) ) == 0 ; } return false ; }
|
Compare two values using an operator
|
54,398
|
public function listPriceRule ( ) { $ this -> actionListPriceRule ( ) ; $ this -> setTitleListPriceRule ( ) ; $ this -> setBreadcrumbListPriceRule ( ) ; $ this -> setFilterListPriceRule ( ) ; $ this -> setPagerListPriceRule ( ) ; $ this -> setData ( 'stores' , $ this -> store -> getList ( ) ) ; $ this -> setData ( 'price_rules' , $ this -> getListPriceRule ( ) ) ; $ this -> outputListPriceRule ( ) ; }
|
Displays the price rule overview page
|
54,399
|
protected function actionListPriceRule ( ) { list ( $ selected , $ action , $ value ) = $ this -> getPostedAction ( ) ; $ deleted = $ updated = 0 ; foreach ( $ selected as $ rule_id ) { if ( $ action === 'status' && $ this -> access ( 'price_rule_edit' ) ) { $ updated += ( int ) $ this -> price_rule -> update ( $ rule_id , array ( 'status' => $ value ) ) ; } if ( $ action === 'delete' && $ this -> access ( 'price_rule_delete' ) ) { $ deleted += ( int ) $ this -> price_rule -> delete ( $ rule_id ) ; } } if ( $ updated > 0 ) { $ message = $ this -> text ( 'Updated %num item(s)' , array ( '%num' => $ updated ) ) ; $ this -> setMessage ( $ message , 'success' ) ; } if ( $ deleted > 0 ) { $ message = $ this -> text ( 'Deleted %num item(s)' , array ( '%num' => $ deleted ) ) ; $ this -> setMessage ( $ message , 'success' ) ; } }
|
Applies an action to the selected price rules
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.