Skip to content

Make "is_required" and "is_visible" properties of telephone, company and fax attributes of addresses configurable #8519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
a9df245
Add {{depend}} to telephone line in default address text template
avstudnitz Feb 11, 2017
bad7819
Add new configuration field for the telephone field
avstudnitz Feb 11, 2017
5b32a01
Fix backend model for config field "show telephone"
avstudnitz Feb 11, 2017
93d23f2
display the telephone field conditionally dependant upon the configur…
pixelhed Feb 11, 2017
1b66bb0
Update validation of customer and quote address for the case of "tele…
avstudnitz Feb 11, 2017
d4bd82b
display the telephone field in the address edit form conditionally
pixelhed Feb 11, 2017
6540ef8
Added system configuration for toggling display of company and fax fi…
pixelhed Feb 11, 2017
94f0265
Update validation of order address for the case of "telephone" not be…
avstudnitz Feb 11, 2017
4c4990e
Add server side validation for fax and company fields, depending on c…
avstudnitz Feb 11, 2017
92f8298
removed unused method
pixelhed Feb 11, 2017
7b1df36
Enabled toggling of frontend fields for company and fax - added suppo…
pixelhed Feb 11, 2017
74facff
Merge branch 'telephone-not-required' of github.com:magento-hackathon…
pixelhed Feb 11, 2017
724a552
Add Integration Tests about register form and widgets
avstudnitz Feb 11, 2017
5814ef4
updated formatting of templates
pixelhed Feb 12, 2017
665867c
added missing EavConfig docblock param
pixelhed Feb 12, 2017
e68f72c
made EavConfig an optional param
pixelhed Feb 12, 2017
ed3ffe6
Merge branch 'telephone-not-required' of github.com:magento-hackathon…
pixelhed Feb 12, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 180 additions & 0 deletions app/code/Magento/Customer/Block/Widget/Company.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Customer\Block\Widget;

use Magento\Customer\Api\AddressMetadataInterface;
use Magento\Customer\Api\CustomerMetadataInterface;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Customer\Helper\Address as AddressHelper;
use Magento\Customer\Model\Options;
use Magento\Framework\View\Element\Template\Context;

/**
* Widget for showing customer company.
*
* @method CustomerInterface getObject()
* @method Name setObject(CustomerInterface $customer)
*
* @SuppressWarnings(PHPMD.DepthOfInheritance)
*/
class Company extends AbstractWidget
{

/**
* the attribute code
*/
const ATTRIBUTE_CODE = 'company';

/**
* @var AddressMetadataInterface
*/
protected $addressMetadata;

/**
* @var Options
*/
protected $options;

/**
* @param Context $context
* @param AddressHelper $addressHelper
* @param CustomerMetadataInterface $customerMetadata
* @param Options $options
* @param AddressMetadataInterface $addressMetadata
* @param array $data
*/
public function __construct(
Context $context,
AddressHelper $addressHelper,
CustomerMetadataInterface $customerMetadata,
Options $options,
AddressMetadataInterface $addressMetadata,
array $data = []
)
{
$this->options = $options;
parent::__construct($context, $addressHelper, $customerMetadata, $data);
$this->addressMetadata = $addressMetadata;
$this->_isScopePrivate = true;
}

/**
* @return void
*/
public function _construct()
{
parent::_construct();

// default template location
$this->setTemplate('widget/company.phtml');
}

/**
* Can show config value
*
* @param string $key
*
* @return bool
*/
protected function _showConfig($key)
{
return (bool)$this->getConfig($key);
}

/**
* Can show prefix
*
* @return bool
*/
public function showCompany()
{
return $this->_isAttributeVisible(self::ATTRIBUTE_CODE);
}

/**
* {@inheritdoc}
*/
protected function _getAttribute($attributeCode)
{
if ($this->getForceUseCustomerAttributes() || $this->getObject() instanceof CustomerInterface) {
return parent::_getAttribute($attributeCode);
}

try {
$attribute = $this->addressMetadata->getAttributeMetadata($attributeCode);
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
return null;
}

if ($this->getForceUseCustomerRequiredAttributes() && $attribute && !$attribute->isRequired()) {
$customerAttribute = parent::_getAttribute($attributeCode);
if ($customerAttribute && $customerAttribute->isRequired()) {
$attribute = $customerAttribute;
}
}

return $attribute;
}

/**
* Retrieve store attribute label
*
* @param string $attributeCode
*
* @return string
*/
public function getStoreLabel($attributeCode)
{
$attribute = $this->_getAttribute($attributeCode);
return $attribute ? __($attribute->getStoreLabel()) : '';
}

/**
* Get string with frontend validation classes for attribute
*
* @param string $attributeCode
*
* @return string
*/
public function getAttributeValidationClass($attributeCode)
{
return $this->_addressHelper->getAttributeValidationClass($attributeCode);
}

/**
* @param string $attributeCode
*
* @return bool
*/
private function _isAttributeVisible($attributeCode)
{
$attributeMetadata = $this->_getAttribute($attributeCode);
return $attributeMetadata ? (bool)$attributeMetadata->isVisible() : false;
}

/**
* Check if company attribute enabled in system
*
* @return bool
*/
public function isEnabled()
{
return $this->_getAttribute(self::ATTRIBUTE_CODE) ? (bool)$this->_getAttribute(self::ATTRIBUTE_CODE)->isVisible(
) : false;
}

/**
* Check if company attribute marked as required
*
* @return bool
*/
public function isRequired()
{
return $this->_getAttribute(self::ATTRIBUTE_CODE) ? (bool)$this->_getAttribute(self::ATTRIBUTE_CODE)
->isRequired() : false;
}
}
180 changes: 180 additions & 0 deletions app/code/Magento/Customer/Block/Widget/Fax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Customer\Block\Widget;

use Magento\Customer\Api\AddressMetadataInterface;
use Magento\Customer\Api\CustomerMetadataInterface;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Customer\Helper\Address as AddressHelper;
use Magento\Customer\Model\Options;
use Magento\Framework\View\Element\Template\Context;

/**
* Widget for showing customer company.
*
* @method CustomerInterface getObject()
* @method Name setObject(CustomerInterface $customer)
*
* @SuppressWarnings(PHPMD.DepthOfInheritance)
*/
class Fax extends AbstractWidget
{

/**
* the attribute code
*/
const ATTRIBUTE_CODE = 'fax';

/**
* @var AddressMetadataInterface
*/
protected $addressMetadata;

/**
* @var Options
*/
protected $options;

/**
* @param Context $context
* @param AddressHelper $addressHelper
* @param CustomerMetadataInterface $customerMetadata
* @param Options $options
* @param AddressMetadataInterface $addressMetadata
* @param array $data
*/
public function __construct(
Context $context,
AddressHelper $addressHelper,
CustomerMetadataInterface $customerMetadata,
Options $options,
AddressMetadataInterface $addressMetadata,
array $data = []
)
{
$this->options = $options;
parent::__construct($context, $addressHelper, $customerMetadata, $data);
$this->addressMetadata = $addressMetadata;
$this->_isScopePrivate = true;
}

/**
* @return void
*/
public function _construct()
{
parent::_construct();

// default template location
$this->setTemplate('widget/fax.phtml');
}

/**
* Can show config value
*
* @param string $key
*
* @return bool
*/
protected function _showConfig($key)
{
return (bool)$this->getConfig($key);
}

/**
* Can show prefix
*
* @return bool
*/
public function showFax()
{
return $this->_isAttributeVisible(self::ATTRIBUTE_CODE);
}

/**
* {@inheritdoc}
*/
protected function _getAttribute($attributeCode)
{
if ($this->getForceUseCustomerAttributes() || $this->getObject() instanceof CustomerInterface) {
return parent::_getAttribute($attributeCode);
}

try {
$attribute = $this->addressMetadata->getAttributeMetadata($attributeCode);
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
return null;
}

if ($this->getForceUseCustomerRequiredAttributes() && $attribute && !$attribute->isRequired()) {
$customerAttribute = parent::_getAttribute($attributeCode);
if ($customerAttribute && $customerAttribute->isRequired()) {
$attribute = $customerAttribute;
}
}

return $attribute;
}

/**
* Retrieve store attribute label
*
* @param string $attributeCode
*
* @return string
*/
public function getStoreLabel($attributeCode)
{
$attribute = $this->_getAttribute($attributeCode);
return $attribute ? __($attribute->getStoreLabel()) : '';
}

/**
* Get string with frontend validation classes for attribute
*
* @param string $attributeCode
*
* @return string
*/
public function getAttributeValidationClass($attributeCode)
{
return $this->_addressHelper->getAttributeValidationClass($attributeCode);
}

/**
* @param string $attributeCode
*
* @return bool
*/
private function _isAttributeVisible($attributeCode)
{
$attributeMetadata = $this->_getAttribute($attributeCode);
return $attributeMetadata ? (bool)$attributeMetadata->isVisible() : false;
}

/**
* Check if company attribute enabled in system
*
* @return bool
*/
public function isEnabled()
{
return $this->_getAttribute(self::ATTRIBUTE_CODE) ? (bool)$this->_getAttribute(self::ATTRIBUTE_CODE)->isVisible(
) : false;
}

/**
* Check if company attribute marked as required
*
* @return bool
*/
public function isRequired()
{
return $this->_getAttribute(self::ATTRIBUTE_CODE) ? (bool)$this->_getAttribute(self::ATTRIBUTE_CODE)
->isRequired() : false;
}
}
Loading