diff --git a/plugin/DataView/DataDetailView.php b/plugin/DataView/DataDetailView.php index 0e00b7e05..979545ae8 100644 --- a/plugin/DataView/DataDetailView.php +++ b/plugin/DataView/DataDetailView.php @@ -242,6 +242,7 @@ class DataDetailView 'wochmietbto', 'kaufpreis_pro_qm', 'mietpreis_pro_qm', + 'calculatedPrice' ]; /** @@ -447,4 +448,10 @@ public function getContactImageTypes(): array /** @param array $contactImageTypes */ public function setContactImageTypes(array $contactImageTypes) { $this->_contactImageTypes = $contactImageTypes; } + + /** @param array $priceFields */ + public function setListFieldsShowPriceOnRequest(array $priceFields) + { + $this->_priceFields = $priceFields; + } } diff --git a/plugin/DataView/DataListView.php b/plugin/DataView/DataListView.php index 56f742ae5..d3b081baf 100644 --- a/plugin/DataView/DataListView.php +++ b/plugin/DataView/DataListView.php @@ -188,6 +188,7 @@ class DataListView 'wochmietbto', 'kaufpreis_pro_qm', 'mietpreis_pro_qm', + 'calculatedPrice' ]; /** diff --git a/plugin/DataView/DataViewSimilarEstates.php b/plugin/DataView/DataViewSimilarEstates.php index d2be77b08..838c2be74 100644 --- a/plugin/DataView/DataViewSimilarEstates.php +++ b/plugin/DataView/DataViewSimilarEstates.php @@ -108,17 +108,18 @@ class DataViewSimilarEstates /** @var string[] */ private $_priceFields = [ - 'kaufpreis', - 'erbpacht', - 'nettokaltmiete', - 'warmmiete', - 'pacht', - 'kaltmiete', - 'miete_pauschal', - 'saisonmiete', - 'wochmietbto', - 'kaufpreis_pro_qm', - 'mietpreis_pro_qm', + 'kaufpreis', + 'erbpacht', + 'nettokaltmiete', + 'warmmiete', + 'pacht', + 'kaltmiete', + 'miete_pauschal', + 'saisonmiete', + 'wochmietbto', + 'kaufpreis_pro_qm', + 'mietpreis_pro_qm', + 'calculatedPrice' ]; /** @param bool $sameEstateKind */ @@ -236,4 +237,10 @@ public function getListFieldsShowPriceOnRequest(): array { return $this->_priceFields; } + + /** @param array $priceFields */ + public function setListFieldsShowPriceOnRequest(array $priceFields) + { + $this->_priceFields = $priceFields; + } } \ No newline at end of file diff --git a/plugin/Installer/DatabaseChanges.php b/plugin/Installer/DatabaseChanges.php index d02a31076..f9ac7795e 100644 --- a/plugin/Installer/DatabaseChanges.php +++ b/plugin/Installer/DatabaseChanges.php @@ -28,6 +28,8 @@ use onOffice\WPlugin\AddressList; use Exception; use onOffice\WPlugin\DataView\DataDetailViewHandler; +use onOffice\WPlugin\DataView\DataViewSimilarEstates; +use onOffice\WPlugin\DataView\DataDetailView; use onOffice\WPlugin\Template\TemplateCall; use onOffice\WPlugin\Types\ImageTypes; use onOffice\WPlugin\DataView\DataSimilarView; @@ -41,7 +43,7 @@ class DatabaseChanges implements DatabaseChangesInterface { /** @var int */ - const MAX_VERSION = 53; + const MAX_VERSION = 54; /** @var WPOptionWrapperBase */ private $_pWpOption; @@ -356,6 +358,12 @@ public function install() $dbversion = 53; } + if ($dbversion == 53) { + $this->updatePriceFieldsOptionForSimilarEstate(); + $this->updatePriceFieldsOptionDetailView(); + $dbversion = 54; + } + $this->_pWpOption->updateOption( 'oo_plugin_db_version', $dbversion, true ); } @@ -1319,4 +1327,30 @@ private function updateContactImageTypesForDetailPage() $this->_pWpOption->updateOption('onoffice-default-view', $pDataDetailViewOptions); } } + + /** + * + */ + public function updatePriceFieldsOptionForSimilarEstate() + { + $pDataSimilarViewOptions = $this->_pWpOption->getOption('onoffice-similar-estates-settings-view'); + if (!empty($pDataSimilarViewOptions)) { + $pDataViewSimilarEstates = new DataViewSimilarEstates(); + $pDataSimilarViewOptions->getDataViewSimilarEstates()->setListFieldsShowPriceOnRequest($pDataViewSimilarEstates->getListFieldsShowPriceOnRequest()); + $this->_pWpOption->updateOption('onoffice-similar-estates-settings-view', $pDataSimilarViewOptions); + } + } + + /** + * + */ + public function updatePriceFieldsOptionDetailView() + { + $pDataDetailViewOptions = $this->_pWpOption->getOption('onoffice-default-view'); + if (!empty($pDataDetailViewOptions)) { + $pDataDataDetailView = new DataDetailView(); + $pDataDetailViewOptions->setListFieldsShowPriceOnRequest($pDataDataDetailView->getListFieldsShowPriceOnRequest()); + $this->_pWpOption->updateOption('onoffice-default-view', $pDataDetailViewOptions); + } + } } diff --git a/tests/TestClassDataViewSimilarEstates.php b/tests/TestClassDataViewSimilarEstates.php index 5c811566a..82af54ec7 100644 --- a/tests/TestClassDataViewSimilarEstates.php +++ b/tests/TestClassDataViewSimilarEstates.php @@ -138,6 +138,7 @@ public function testGetListFieldsShowPriceOnRequest() 'wochmietbto', 'kaufpreis_pro_qm', 'mietpreis_pro_qm', + 'calculatedPrice', ]; $this->assertEquals($expectedPriceFields, $pDataViewSimilarEstates->getListFieldsShowPriceOnRequest()); } diff --git a/tests/TestClassDatabaseChanges.php b/tests/TestClassDatabaseChanges.php index 72948d087..b11e6f768 100644 --- a/tests/TestClassDatabaseChanges.php +++ b/tests/TestClassDatabaseChanges.php @@ -25,6 +25,7 @@ use onOffice\WPlugin\DataView\DataDetailView; use onOffice\WPlugin\DataView\DataDetailViewHandler; +use onOffice\WPlugin\DataView\DataViewSimilarEstates; use onOffice\WPlugin\Installer\DatabaseChanges; use onOffice\WPlugin\Types\ImageTypes; use onOffice\WPlugin\Utility\__String; @@ -118,7 +119,7 @@ public function testInstall(): array $this->assertGreaterThanOrEqual(self::NUM_NEW_TABLES, count($this->_createQueries)); $dbversion = $this->_pDbChanges->getDbVersion(); - $this->assertEquals(53, $dbversion); + $this->assertEquals(54, $dbversion); return $this->_createQueries; } @@ -271,7 +272,7 @@ public function testDeleteMessageFieldApplicantSearchForm() */ public function testMaxVersion() { - $this->assertEquals(53, DatabaseChanges::MAX_VERSION); + $this->assertEquals(54, DatabaseChanges::MAX_VERSION); } @@ -421,4 +422,63 @@ public function testUpdateDefaultPictureTypesForSimilarEstate(): array return $this->_createQueries; } + + /** + * @covers \onOffice\WPlugin\Installer\DatabaseChanges::updatePriceFieldsOptionForSimilarEstate + */ + public function testUpdatePriceFieldsOptionForSimilarEstate() + { + global $wpdb; + $dataViewSimilarEstates = new DataViewSimilarEstates(); + $listFieldsShowPriceOnRequest = $dataViewSimilarEstates->getListFieldsShowPriceOnRequest(); + + $this->_pDbChanges = new DatabaseChanges($this->_pWpOption, $wpdb); + + $dataSimilarViewOptions = new \onOffice\WPlugin\DataView\DataSimilarView(); + $dataSimilarViewOptions->name = "onoffice-similar-estates-settings-view"; + $dataSimilarViewOptions->getDataViewSimilarEstates()->setListFieldsShowPriceOnRequest($listFieldsShowPriceOnRequest); + update_option('onoffice-similar-estates-settings-view', $dataSimilarViewOptions); + + $this->_pDbChanges->deinstall(); + add_option('oo_plugin_db_version', '44'); + add_filter('query', [$this, 'saveCreateQuery'], 1); + $this->_pDbChanges->install(); + remove_filter('query', [$this, 'saveCreateQuery'], 1); + + $pSimilarEstatesOptions = get_option('onoffice-similar-estates-settings-view'); + $pDataViewSimilarEstates = $pSimilarEstatesOptions->getDataViewSimilarEstates(); + + $this->assertEquals($listFieldsShowPriceOnRequest, $pDataViewSimilarEstates->getListFieldsShowPriceOnRequest()); + + return $this->_createQueries; + } + + /** + * @covers \onOffice\WPlugin\Installer\DatabaseChanges::updatePriceFieldsOptionDetailView + */ + public function testUpdatePriceFieldsOptionForDetailView() + { + global $wpdb; + $dataDetailView = new DataDetailView(); + $listFieldsShowPriceOnRequest = $dataDetailView->getListFieldsShowPriceOnRequest(); + + $this->_pDbChanges = new DatabaseChanges($this->_pWpOption, $wpdb); + + $dataDetailViewOptions = new \onOffice\WPlugin\DataView\DataDetailView(); + $dataDetailViewOptions->name = "onoffice-default-view"; + $dataDetailViewOptions->setListFieldsShowPriceOnRequest($listFieldsShowPriceOnRequest); + update_option('onoffice-default-view', $dataDetailViewOptions); + + $this->_pDbChanges->deinstall(); + add_option('oo_plugin_db_version', '44'); + add_filter('query', [$this, 'saveCreateQuery'], 1); + $this->_pDbChanges->install(); + remove_filter('query', [$this, 'saveCreateQuery'], 1); + + $pDetailViewOptions = get_option('onoffice-default-view'); + + $this->assertEquals($listFieldsShowPriceOnRequest, $pDetailViewOptions->getListFieldsShowPriceOnRequest()); + + return $this->_createQueries; + } } diff --git a/tests/TestClassEstateViewFieldModifierTypeTitle.php b/tests/TestClassEstateViewFieldModifierTypeTitle.php index 213b44b6c..6ebdb4df8 100644 --- a/tests/TestClassEstateViewFieldModifierTypeTitle.php +++ b/tests/TestClassEstateViewFieldModifierTypeTitle.php @@ -138,7 +138,6 @@ public function testApiCustomFields() 'energyClass', 'aussen_courtage', 'kaution', - 'preisAufAnfrage', ]; $pEstateViewFieldModifierTypeTitle = new EstateViewFieldModifierTypeTitle(['test1', 'test2']); @@ -179,7 +178,6 @@ public function testVisibleCustomFields() 'energyClass', 'aussen_courtage', 'kaution', - 'preisAufAnfrage', ]; $pEstateViewFieldModifierTypeTitle = new EstateViewFieldModifierTypeTitle(['test1', 'test2']);