Skip to content

Commit

Permalink
46527 integration of price on request with calculatedprice field (#793)
Browse files Browse the repository at this point in the history
* 46527 integration of price on request with calculatedprice field

* 46527 refactor code

* 46527 update unit test

* 46527 update unit test

* 46527 update unit test

* 46527 update unit test

* 46527 update unit test

* 46527 update database change

* 46527 update unit test

* 46527 update unit test

* update unit test

* 46527 update unit test

* Fix unittest after merge

---------

Co-authored-by: Frederic Alpers <88546396+fredericalpers@users.noreply.github.com>
Co-authored-by: andernath <chibineko@gmail.com>
  • Loading branch information
3 people authored Oct 24, 2024
1 parent a5362ea commit 3afcd41
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 16 deletions.
7 changes: 7 additions & 0 deletions plugin/DataView/DataDetailView.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class DataDetailView
'wochmietbto',
'kaufpreis_pro_qm',
'mietpreis_pro_qm',
'calculatedPrice'
];

/**
Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions plugin/DataView/DataListView.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class DataListView
'wochmietbto',
'kaufpreis_pro_qm',
'mietpreis_pro_qm',
'calculatedPrice'
];

/**
Expand Down
29 changes: 18 additions & 11 deletions plugin/DataView/DataViewSimilarEstates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -236,4 +237,10 @@ public function getListFieldsShowPriceOnRequest(): array
{
return $this->_priceFields;
}

/** @param array $priceFields */
public function setListFieldsShowPriceOnRequest(array $priceFields)
{
$this->_priceFields = $priceFields;
}
}
36 changes: 35 additions & 1 deletion plugin/Installer/DatabaseChanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,7 +43,7 @@
class DatabaseChanges implements DatabaseChangesInterface
{
/** @var int */
const MAX_VERSION = 53;
const MAX_VERSION = 54;

/** @var WPOptionWrapperBase */
private $_pWpOption;
Expand Down Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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);
}
}
}
1 change: 1 addition & 0 deletions tests/TestClassDataViewSimilarEstates.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function testGetListFieldsShowPriceOnRequest()
'wochmietbto',
'kaufpreis_pro_qm',
'mietpreis_pro_qm',
'calculatedPrice',
];
$this->assertEquals($expectedPriceFields, $pDataViewSimilarEstates->getListFieldsShowPriceOnRequest());
}
Expand Down
64 changes: 62 additions & 2 deletions tests/TestClassDatabaseChanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -271,7 +272,7 @@ public function testDeleteMessageFieldApplicantSearchForm()
*/
public function testMaxVersion()
{
$this->assertEquals(53, DatabaseChanges::MAX_VERSION);
$this->assertEquals(54, DatabaseChanges::MAX_VERSION);
}


Expand Down Expand Up @@ -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;
}
}
2 changes: 0 additions & 2 deletions tests/TestClassEstateViewFieldModifierTypeTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ public function testApiCustomFields()
'energyClass',
'aussen_courtage',
'kaution',
'preisAufAnfrage',
];

$pEstateViewFieldModifierTypeTitle = new EstateViewFieldModifierTypeTitle(['test1', 'test2']);
Expand Down Expand Up @@ -179,7 +178,6 @@ public function testVisibleCustomFields()
'energyClass',
'aussen_courtage',
'kaution',
'preisAufAnfrage',
];

$pEstateViewFieldModifierTypeTitle = new EstateViewFieldModifierTypeTitle(['test1', 'test2']);
Expand Down

0 comments on commit 3afcd41

Please sign in to comment.