Add customer tags to customer form. #558

This commit is contained in:
Korina Cordero 2021-05-05 10:33:46 +00:00
parent 601b23afdf
commit 6ac92eba30
4 changed files with 40 additions and 43 deletions

View file

@ -619,7 +619,7 @@ class Customer
public function addCustomerTag(CustomerTag $customer_tag) public function addCustomerTag(CustomerTag $customer_tag)
{ {
$this->customer_tags->add($customer_tag); $this->customer_tags[$customer_tag->getID()] = $customer_tag;
return $this; return $this;
} }
@ -631,11 +631,11 @@ class Customer
public function getCustomerTags() public function getCustomerTags()
{ {
$str_customer_tags = []; $str_cust_tags = [];
foreach ($this->customer_tags as $customer_tag) foreach ($this->customer_tags as $cust_tag)
$str_customer_tags[] = $customer_tag->getID(); $str_cust_tags[] = $cust_tag->getID();
return $str_customer_tags; return $str_cust_tags;
} }
} }

View file

@ -15,7 +15,7 @@ class CustomerTag
{ {
/** /**
* @ORM\Id * @ORM\Id
* @ORM\Column(type="string", length=80, nullable=false) * @ORM\Column(type="string", length=80, nullable=false, unique=true)
* @Assert\NotBlank() * @Assert\NotBlank()
*/ */
protected $id; protected $id;
@ -27,18 +27,6 @@ class CustomerTag
*/ */
protected $name; protected $name;
// flag for car club member
/**
* @ORM\Column(type="boolean")
*/
protected $flag_car_club_member;
// flag for car club promo
/**
* @ORM\Column(type="boolean")
*/
protected $flag_car_club_promo;
// customers // customers
/** /**
* @ORM\ManyToMany(targetEntity="Customer", mappedBy="customer_tags", fetch="EXTRA_LAZY") * @ORM\ManyToMany(targetEntity="Customer", mappedBy="customer_tags", fetch="EXTRA_LAZY")
@ -49,8 +37,6 @@ class CustomerTag
{ {
$this->date_create = new DateTime(); $this->date_create = new DateTime();
$this->customers = new ArrayCollection(); $this->customers = new ArrayCollection();
$this->flag_car_club_member = false;
$this->flag_car_club_promo = false;
} }
public function getID() public function getID()
@ -97,26 +83,4 @@ class CustomerTag
{ {
return $this->customers; return $this->customers;
} }
public function setCarClubMember($flag_car_club_member = true)
{
$this->flag_car_club_member = $flag_car_club_member;
return $this;
}
public function isCarClubMember()
{
return $this->flag_car_club_member;
}
public function setCarClubPromo($flag_car_club_promo = true)
{
$this->flag_car_club_promo = $flag_car_club_promo;
return $this;
}
public function isCarClubPromo()
{
return $this->flag_car_club_promo;
}
} }

View file

@ -22,6 +22,7 @@ use App\Entity\Vehicle;
use App\Entity\Battery; use App\Entity\Battery;
use App\Entity\VehicleManufacturer; use App\Entity\VehicleManufacturer;
use App\Entity\BatteryManufacturer; use App\Entity\BatteryManufacturer;
use App\Entity\CustomerTag;
use DateTime; use DateTime;
@ -151,6 +152,9 @@ class ResqCustomerHandler implements CustomerHandlerInterface
$params['obj'] = new Customer(); $params['obj'] = new Customer();
$params['mode'] = 'create'; $params['mode'] = 'create';
// get customer tags
$params['customer_tags'] = $this->em->getRepository(CustomerTag::class)->findAll();
// get dropdown parameters // get dropdown parameters
$this->fillDropdownParameters($params); $this->fillDropdownParameters($params);
@ -307,6 +311,9 @@ class ResqCustomerHandler implements CustomerHandlerInterface
if (empty($row)) if (empty($row))
throw new NotFoundHttpException('The item does not exist'); throw new NotFoundHttpException('The item does not exist');
// get customer tags
$params['customer_tags'] = $em->getRepository(CustomerTag::class)->findAll();
// get dropdown parameters // get dropdown parameters
$this->fillDropdownParameters($params); $this->fillDropdownParameters($params);
@ -603,13 +610,26 @@ class ResqCustomerHandler implements CustomerHandlerInterface
->setPromoEmail($req->request->get('flag_promo_email', false)) ->setPromoEmail($req->request->get('flag_promo_email', false))
->setDpaConsent($is_dpa_checked) ->setDpaConsent($is_dpa_checked)
->setResearchSms($req->request->get('flag_research_sms', false)) ->setResearchSms($req->request->get('flag_research_sms', false))
->setResearchEmail($req->request->get('flag_research_email', false)); ->setResearchEmail($req->request->get('flag_research_email', false))
->clearCustomerTags();
// phone numbers // phone numbers
$obj->setPhoneMobile($req->request->get('phone_mobile')) $obj->setPhoneMobile($req->request->get('phone_mobile'))
->setPhoneLandline($req->request->get('phone_landline')) ->setPhoneLandline($req->request->get('phone_landline'))
->setPhoneOffice($req->request->get('phone_office')) ->setPhoneOffice($req->request->get('phone_office'))
->setPhoneFax($req->request->get('phone_fax')); ->setPhoneFax($req->request->get('phone_fax'));
// set car club flags
$customer_tags = $req->request->get('customer_tags');
if (!empty($customer_tags))
{
foreach($customer_tags as $customer_tag_id)
{
$customer_tag = $this->em->getRepository(CustomerTag::class)->find($customer_tag_id);
if (!empty($customer_tag))
$obj->addCustomerTag($customer_tag);
}
}
} }
protected function fillDropdownParameters(&$params) protected function fillDropdownParameters(&$params)

View file

@ -160,6 +160,19 @@
</span> </span>
<div class="form-control-feedback hide" data-field="flag_active"></div> <div class="form-control-feedback hide" data-field="flag_active"></div>
</div> </div>
<div class="col-lg-4">
<div class="col-lg-12 form-group-inner">
<div class="m-checkbox-list">
{% for customer_tag in customer_tags %}
<label class="m-checkbox">
<input type="checkbox" name="customer_tags[]" value="{{ customer_tag.getID() }}"{{ customer_tag.getID() in obj.getCustomerTags() ? ' checked' : '' }}>
{{ customer_tag.getName() }}
<span></span>
</label>
{% endfor %}
</div>
</div>
</div>
</div> </div>
</div> </div>