I'm trying to customize Real Estate extension for my needs (and to understand how extensions are working and how to make 'em).
There is file application/Espo/Modules/RealEstate/Repositories/RealEstateRequest.php in which function afterSave is using to form name of request.
I want to make something similar for Properties. So I created entity "propertyName" (Varchar) for RealEstateProperty (in Entity manager) and placed it to Layouts.
I also copied those public function afterSave(Entity $entity, array $options) from application/Espo/Modules/RealEstate/Repositories/RealEstateRequest.php
to application/Espo/Modules/RealEstate/Repositories/RealEstateProperty.php and edited it, so it's now looks like:
So, if I creating new Property, I enter name to propertyName field (for example Qwerty)
What I want to get in list view later - something like "Qwerty P 000003"
What I get with it - only "Qwerty" and pack of errors in log:
What I'm doing wrong and what I'm missing?
(versions: EspoCRM 4.0.0 and Real Estate 1.0.2)
There is file application/Espo/Modules/RealEstate/Repositories/RealEstateRequest.php in which function afterSave is using to form name of request.
PHP Code:
public function afterSave(Entity $entity, array $options)
{
$result = parent::afterSave($entity, $options);
$this->handleAfterSaveContacts($entity, $options);
if ($entity->isNew() && !$entity->get('name')) {
$e = $this->get($entity->id);
$name = strval($e->get('number'));
$name = str_pad($name, 6, '0', STR_PAD_LEFT);
$name = 'R ' . $name;
$e->set('name', $name);
$this->save($e);
$entity->set('name', $name);
$entity->set('number', $e->get('number'));
}
return $result;
}
I also copied those public function afterSave(Entity $entity, array $options) from application/Espo/Modules/RealEstate/Repositories/RealEstateRequest.php
to application/Espo/Modules/RealEstate/Repositories/RealEstateProperty.php and edited it, so it's now looks like:
PHP Code:
<?php
namespace Espo\Modules\RealEstate\Repositories;
class RealEstateProperty extends \Espo\Core\Templates\Repositories\Base
{
public function beforeSave(Entity $entity, array $options)
{
$propertyType = $entity->get('type');
switch ($propertyType) {
case 'Apartment':
$entity->set('floorCount', null);
break;
case 'Separate House':
$entity->set('floor', null);
break;
case 'Office':
$entity->set('bedroomCount', null);
$entity->set('bathroomCount', null);
$entity->set('floorCount', null);
case 'Warehouse':
case 'Retail':
case 'Farm':
$entity->set('floor', null);
$entity->set('bedroomCount', null);
$entity->set('bathroomCount', null);
$entity->set('floorCount', null);
break;
}
return parent::beforeSave($entity, $options);
}
public function afterSave(Entity $entity, array $options)
{
$result = parent::afterSave($entity, $options);
$this->handleAfterSaveContacts($entity, $options);
if ($entity->isNew() && !$entity->get('propertyName')) {
$e = $this->get($entity->id);
$propertyName = strval($e->get('number'));
$propertyName = str_pad($propertyName, 6, '0', STR_PAD_LEFT);
$propertyName = 'P ' . $propertyName;
$e->set('propertyName', $propertyName);
$this->save($e);
$entity->set('propertyName', $propertyName);
$entity->set('number', $e->get('number'));
}
return $result;
}
}
What I want to get in list view later - something like "Qwerty P 000003"
What I get with it - only "Qwerty" and pack of errors in log:
Code:
[2016-03-02 09:38:06] Espo.ERROR: E_RECOVERABLE_ERROR: Argument 1 passed to Espo\Modules\RealEstate\Repositories\RealEstateProperty::beforeSave() must be an instance of Espo\Modules\RealEstate\Repositories\Entity, instance of Espo\Modules\RealEstate\Entities\RealEstateProperty given, called in /var/www/espocrm/application/Espo/ORM/Repositories/RDB.php on line 141 and defined {"file":"/var/www/espocrm/application/Espo/Modules/RealEstate/Repositories/RealEstateProperty.php","line":7} [] [2016-03-02 09:38:06] Espo.ERROR: E_RECOVERABLE_ERROR: Argument 1 passed to Espo\Modules\RealEstate\Repositories\RealEstateProperty::afterSave() must be an instance of Espo\Modules\RealEstate\Repositories\Entity, instance of Espo\Modules\RealEstate\Entities\RealEstateProperty given, called in /var/www/espocrm/application/Espo/ORM/Repositories/RDB.php on line 149 and defined {"file":"/var/www/espocrm/application/Espo/Modules/RealEstate/Repositories/RealEstateProperty.php","line":35} []
(versions: EspoCRM 4.0.0 and Real Estate 1.0.2)
Comment