diff --git a/app/code/Magento/Customer/Model/Address/AbstractAddress.php b/app/code/Magento/Customer/Model/Address/AbstractAddress.php index 340ee38b8d298..7b32da94ddedb 100644 --- a/app/code/Magento/Customer/Model/Address/AbstractAddress.php +++ b/app/code/Magento/Customer/Model/Address/AbstractAddress.php @@ -393,7 +393,6 @@ public function getRegionId() if (!$regionId) { if (is_numeric($region)) { $this->setData('region_id', $region); - //@TODO method unsRegion() is neither defined in abstract model nor in it's children $this->unsRegion(); } else { $regionModel = $this->_createRegionInstance()->loadByCode( @@ -629,4 +628,13 @@ protected function _createCountryInstance() { return $this->_countryFactory->create(); } + + /** + * Unset Region from address + * @return $this + */ + public function unsRegion() + { + return $this->unsetData("region"); + } } diff --git a/app/code/Magento/Customer/Model/AttributeMetadataConverter.php b/app/code/Magento/Customer/Model/AttributeMetadataConverter.php index 911a0626589e0..6167660854ddd 100644 --- a/app/code/Magento/Customer/Model/AttributeMetadataConverter.php +++ b/app/code/Magento/Customer/Model/AttributeMetadataConverter.php @@ -8,6 +8,7 @@ use Magento\Customer\Api\Data\OptionInterfaceFactory; use Magento\Customer\Api\Data\ValidationRuleInterfaceFactory; use Magento\Customer\Api\Data\AttributeMetadataInterfaceFactory; +use Magento\Eav\Api\Data\AttributeDefaultValueInterface; /** * Converter for AttributeMetadata @@ -93,7 +94,13 @@ public function createMetadataAttribute($attribute) $validationRules[] = $validationRule; } - return $this->attributeMetadataFactory->create()->setAttributeCode($attribute->getAttributeCode()) + $attributeMetaData = $this->attributeMetadataFactory->create(); + + if ($attributeMetaData instanceof AttributeDefaultValueInterface) { + $attributeMetaData->setDefaultValue($attribute->getDefaultValue()); + } + + return $attributeMetaData->setAttributeCode($attribute->getAttributeCode()) ->setFrontendInput($attribute->getFrontendInput()) ->setInputFilter((string)$attribute->getInputFilter()) ->setStoreLabel($attribute->getStoreLabel()) diff --git a/app/code/Magento/Customer/Model/Customer/Attribute/Backend/Password.php b/app/code/Magento/Customer/Model/Customer/Attribute/Backend/Password.php index df55cd1c3f02f..337cefd8b99d4 100644 --- a/app/code/Magento/Customer/Model/Customer/Attribute/Backend/Password.php +++ b/app/code/Magento/Customer/Model/Customer/Attribute/Backend/Password.php @@ -8,6 +8,7 @@ use Magento\Framework\Exception\LocalizedException; /** + * @deprecated * Customer password attribute backend */ class Password extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend @@ -62,6 +63,7 @@ public function beforeSave($object) } /** + * @deprecated * @param \Magento\Framework\DataObject $object * @return bool */ diff --git a/app/code/Magento/Customer/Model/Data/AttributeMetadata.php b/app/code/Magento/Customer/Model/Data/AttributeMetadata.php index 81e5f5dec321a..2313909639540 100644 --- a/app/code/Magento/Customer/Model/Data/AttributeMetadata.php +++ b/app/code/Magento/Customer/Model/Data/AttributeMetadata.php @@ -12,7 +12,8 @@ * Customer attribute metadata class. */ class AttributeMetadata extends \Magento\Framework\Api\AbstractSimpleObject implements - \Magento\Customer\Api\Data\AttributeMetadataInterface + \Magento\Customer\Api\Data\AttributeMetadataInterface, + \Magento\Eav\Api\Data\AttributeDefaultValueInterface { /** * {@inheritdoc} @@ -400,4 +401,20 @@ public function setIsSearchableInGrid($isSearchableInGrid) { return $this->setData(self::IS_SEARCHABLE_IN_GRID, $isSearchableInGrid); } + + /** + * @inheritdoc + */ + public function getDefaultValue() + { + return $this->_get(self::DEFAULT_VALUE); + } + + /** + * @inheritdoc + */ + public function setDefaultValue($defaultValue) + { + return $this->setData(self::DEFAULT_VALUE, $defaultValue); + } } diff --git a/app/code/Magento/Customer/Model/EmailNotification.php b/app/code/Magento/Customer/Model/EmailNotification.php index 4f362ccada6e2..1aed513ef07e2 100644 --- a/app/code/Magento/Customer/Model/EmailNotification.php +++ b/app/code/Magento/Customer/Model/EmailNotification.php @@ -43,6 +43,23 @@ class EmailNotification implements EmailNotificationInterface const XML_PATH_CONFIRM_EMAIL_TEMPLATE = 'customer/create_account/email_confirmation_template'; const XML_PATH_CONFIRMED_EMAIL_TEMPLATE = 'customer/create_account/email_confirmed_template'; + + /** + * self::NEW_ACCOUNT_EMAIL_REGISTERED welcome email, when confirmation is disabled + * and password is set + * self::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD welcome email, when confirmation is disabled + * and password is not set + * self::NEW_ACCOUNT_EMAIL_CONFIRMED welcome email, when confirmation is enabled + * and password is set + * self::NEW_ACCOUNT_EMAIL_CONFIRMATION email with confirmation link + */ + const TEMPLATE_TYPES = [ + self::NEW_ACCOUNT_EMAIL_REGISTERED => self::XML_PATH_REGISTER_EMAIL_TEMPLATE, + self::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD => self::XML_PATH_REGISTER_NO_PASSWORD_EMAIL_TEMPLATE, + self::NEW_ACCOUNT_EMAIL_CONFIRMED => self::XML_PATH_CONFIRMED_EMAIL_TEMPLATE, + self::NEW_ACCOUNT_EMAIL_CONFIRMATION => self::XML_PATH_CONFIRM_EMAIL_TEMPLATE, + ]; + /**#@-*/ /** @@ -339,7 +356,7 @@ public function newAccount( $storeId = 0, $sendemailStoreId = null ) { - $types = $this->getTemplateTypes(); + $types = self::TEMPLATE_TYPES; if (!isset($types[$type])) { throw new LocalizedException(__('Please correct the transactional account email type.')); @@ -361,30 +378,4 @@ public function newAccount( $storeId ); } - - /** - * Get template types - * - * @return array - * @todo: consider eliminating method - */ - private function getTemplateTypes() - { - /** - * self::NEW_ACCOUNT_EMAIL_REGISTERED welcome email, when confirmation is disabled - * and password is set - * self::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD welcome email, when confirmation is disabled - * and password is not set - * self::NEW_ACCOUNT_EMAIL_CONFIRMED welcome email, when confirmation is enabled - * and password is set - * self::NEW_ACCOUNT_EMAIL_CONFIRMATION email with confirmation link - */ - $types = [ - self::NEW_ACCOUNT_EMAIL_REGISTERED => self::XML_PATH_REGISTER_EMAIL_TEMPLATE, - self::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD => self::XML_PATH_REGISTER_NO_PASSWORD_EMAIL_TEMPLATE, - self::NEW_ACCOUNT_EMAIL_CONFIRMED => self::XML_PATH_CONFIRMED_EMAIL_TEMPLATE, - self::NEW_ACCOUNT_EMAIL_CONFIRMATION => self::XML_PATH_CONFIRM_EMAIL_TEMPLATE, - ]; - return $types; - } } diff --git a/app/code/Magento/Customer/Test/Unit/Model/AttributeMetadatConverterTest.php b/app/code/Magento/Customer/Test/Unit/Model/AttributeMetadatConverterTest.php new file mode 100644 index 0000000000000..c7182a516515f --- /dev/null +++ b/app/code/Magento/Customer/Test/Unit/Model/AttributeMetadatConverterTest.php @@ -0,0 +1,194 @@ +optionFactory = $this->getMockBuilder(OptionInterfaceFactory::class) + ->setMethods(['create']) + ->disableOriginalConstructor() + ->getMock(); + $this->validationRuleFactory = $this->getMockBuilder(ValidationRuleInterfaceFactory::class) + ->setMethods(['create']) + ->disableOriginalConstructor() + ->getMock(); + $this->attributeMetadataFactory = $this->getMockBuilder(AttributeMetadataInterfaceFactory::class) + ->setMethods(['create']) + ->disableOriginalConstructor() + ->getMock(); + $this->dataObjectHelper = $this->getMockBuilder(\Magento\Framework\Api\DataObjectHelper::class) + ->disableOriginalConstructor() + ->getMock(); + $this->attribute = $this->getMockBuilder(\Magento\Customer\Model\Attribute::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->model = new AttributeMetadataConverter( + $this->optionFactory, + $this->validationRuleFactory, + $this->attributeMetadataFactory, + $this->dataObjectHelper + ); + } + + /** + * @return array + */ + private function prepareValidateRules() + { + return [ + 'one' => 'numeric', + 'two' => 'alphanumeric' + ]; + } + + /** + * @return array + */ + private function prepareOptions() + { + return [ + [ + 'label' => 'few_values', + 'value' => [ + [1], [2] + ] + ], + [ + 'label' => 'one_value', + 'value' => 1 + ] + ]; + } + + public function testCreateAttributeMetadataTestWithSource() + { + $validatedRules = $this->prepareValidateRules(); + $options = $this->prepareOptions(); + $optionDataObjectForSimpleValue1 = $this->getMockBuilder(\Magento\Customer\Model\Data\Option::class) + ->disableOriginalConstructor() + ->getMock(); + $optionDataObjectForSimpleValue2 = $this->getMockBuilder(\Magento\Customer\Model\Data\Option::class) + ->disableOriginalConstructor() + ->getMock(); + $optionObject1 = $this->getMock(\Magento\Customer\Api\Data\OptionInterface::class); + $optionObject2 = $this->getMock(\Magento\Customer\Api\Data\OptionInterface::class); + $this->optionFactory->expects($this->exactly(4)) + ->method('create') + ->will( + $this->onConsecutiveCalls( + $optionDataObjectForSimpleValue2, + $optionObject1, + $optionObject2, + $optionDataObjectForSimpleValue1 + ) + ); + $source = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\Source\AbstractSource::class) + ->disableOriginalConstructor() + ->getMock(); + $source->expects($this->once()) + ->method('getAllOptions') + ->willReturn($options); + $this->attribute->expects($this->once()) + ->method('usesSource') + ->willReturn(true); + $this->attribute->expects($this->once()) + ->method('getSource') + ->willReturn($source); + $optionDataObjectForSimpleValue1->expects($this->once()) + ->method('setValue') + ->with(1); + $optionDataObjectForSimpleValue2->expects($this->once()) + ->method('setLabel') + ->with('few_values'); + $optionDataObjectForSimpleValue1->expects($this->once()) + ->method('setLabel') + ->with('one_value'); + $this->dataObjectHelper->expects($this->exactly(2)) + ->method('populateWithArray') + ->withConsecutive( + [$optionObject1, ['1'], \Magento\Customer\Api\Data\OptionInterface::class], + [$optionObject2, ['2'], \Magento\Customer\Api\Data\OptionInterface::class] + ); + $validationRule1 = $this->getMock(\Magento\Customer\Api\Data\ValidationRuleInterface::class); + $validationRule2 = $this->getMock(\Magento\Customer\Api\Data\ValidationRuleInterface::class); + $this->validationRuleFactory->expects($this->exactly(2)) + ->method('create') + ->will($this->onConsecutiveCalls($validationRule1, $validationRule2)); + $validationRule1->expects($this->once()) + ->method('setValue') + ->with('numeric'); + $validationRule1->expects($this->once()) + ->method('setName') + ->with('one') + ->willReturnSelf(); + $validationRule2->expects($this->once()) + ->method('setValue') + ->with('alphanumeric'); + $validationRule2->expects($this->once()) + ->method('setName') + ->with('two') + ->willReturnSelf(); + $attributeMetaData = $this->getMockBuilder(\Magento\Customer\Model\Data\AttributeMetadata::class) + ->disableOriginalConstructor() + ->enableProxyingToOriginalMethods() + ->getMock(); + $this->attribute->expects($this->once()) + ->method('getValidateRules') + ->willReturn($validatedRules); + $this->attributeMetadataFactory->expects($this->once()) + ->method('create') + ->willReturn($attributeMetaData); + $frontend = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend::class) + ->disableOriginalConstructor() + ->getMock(); + $this->attribute->expects($this->once()) + ->method('getFrontend') + ->willReturn($frontend); + $optionDataObjectForSimpleValue2->expects($this->once()) + ->method('setOptions') + ->with([$optionObject1, $optionObject2]); + $this->model->createMetadataAttribute($this->attribute); + } +} diff --git a/app/code/Magento/Eav/Api/Data/AttributeDefaultValueInterface.php b/app/code/Magento/Eav/Api/Data/AttributeDefaultValueInterface.php new file mode 100644 index 0000000000000..e4b33833eb775 --- /dev/null +++ b/app/code/Magento/Eav/Api/Data/AttributeDefaultValueInterface.php @@ -0,0 +1,29 @@ +resource = $resource; + } + + /** + * @param int $websiteId + * @return array + */ + public function getStoreByWebsiteId($websiteId) + { + $connection = $this->resource->getConnection(); + $storeTable = $this->resource->getTableName('store'); + $storeSelect = $connection->select()->from($storeTable, ['store_id'])->where( + 'website_id = ?', + $websiteId + ); + $data = $connection->fetchCol($storeSelect); + return $data; + } +} diff --git a/app/code/Magento/Store/Model/StoreManager.php b/app/code/Magento/Store/Model/StoreManager.php index 77532f2188c09..c34f4e1bd2a58 100644 --- a/app/code/Magento/Store/Model/StoreManager.php +++ b/app/code/Magento/Store/Model/StoreManager.php @@ -5,12 +5,16 @@ */ namespace Magento\Store\Model; +use Magento\Framework\App\ObjectManager; use Magento\Store\Api\StoreResolverInterface; +use Magento\Store\Model\ResourceModel\StoreWebsiteRelation; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class StoreManager implements \Magento\Store\Model\StoreManagerInterface +class StoreManager implements + \Magento\Store\Model\StoreManagerInterface, + \Magento\Store\Api\StoreWebsiteRelationInterface { /** * Application run code @@ -286,4 +290,21 @@ protected function isSingleStoreModeEnabled() \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } + + /** + * @deprecated + * @return StoreWebsiteRelation + */ + private function getStoreWebsiteRelation() + { + return ObjectManager::getInstance()->get(StoreWebsiteRelation::class); + } + + /** + * @inheritdoc + */ + public function getStoreByWebsiteId($websiteId) + { + return $this->getStoreWebsiteRelation()->getStoreByWebsiteId($websiteId); + } } diff --git a/app/code/Magento/Store/Test/Unit/Model/ResourceModel/StoreWebsiteRelationTest.php b/app/code/Magento/Store/Test/Unit/Model/ResourceModel/StoreWebsiteRelationTest.php new file mode 100644 index 0000000000000..fbf8f5aa3d85c --- /dev/null +++ b/app/code/Magento/Store/Test/Unit/Model/ResourceModel/StoreWebsiteRelationTest.php @@ -0,0 +1,70 @@ +select = $this->getMockBuilder(Select::class) + ->disableOriginalConstructor() + ->getMock(); + $this->resourceConnection = $this->getMockBuilder(ResourceConnection::class) + ->disableOriginalConstructor() + ->getMock(); + $this->connection = $this->getMock(AdapterInterface::class); + + $this->model = new StoreWebsiteRelation($this->resourceConnection); + } + + public function testGetStoreByWebsiteId() + { + $data = ['ololo']; + $websiteId = 1; + $storeTable = 'store'; + $this->resourceConnection->expects($this->once()) + ->method('getConnection') + ->willReturn($this->connection); + $this->resourceConnection->expects($this->once()) + ->method('getTableName') + ->willReturn($storeTable); + $this->connection->expects($this->once()) + ->method('select') + ->willReturn($this->select); + + $this->select->expects($this->once()) + ->method('from') + ->with($storeTable, ['store_id']) + ->willReturn($this->select); + $this->select->expects($this->once()) + ->method('where') + ->with('website_id = ?', $websiteId) + ->willReturn($this->select); + $this->connection->expects($this->once()) + ->method('fetchCol') + ->willReturn($data); + + $this->assertEquals($data, $this->model->getStoreByWebsiteId($websiteId)); + } +} diff --git a/app/code/Magento/Store/etc/di.xml b/app/code/Magento/Store/etc/di.xml index 3e9192c24d533..57bf057af2724 100644 --- a/app/code/Magento/Store/etc/di.xml +++ b/app/code/Magento/Store/etc/di.xml @@ -12,6 +12,7 @@ + diff --git a/app/code/Magento/Wishlist/Observer/AddToCart.php b/app/code/Magento/Wishlist/Observer/AddToCart.php index 12eca7dc80aad..19e784ef369b9 100644 --- a/app/code/Magento/Wishlist/Observer/AddToCart.php +++ b/app/code/Magento/Wishlist/Observer/AddToCart.php @@ -15,6 +15,7 @@ /** * Class AddToCart + * @deprecated * @package Magento\Wishlist\Observer */ class AddToCart implements ObserverInterface