예제 #1
0
 /**
  * Prepare form.
  *
  * @return $this
  */
 protected function _prepareForm()
 {
     $bannerAttributes = $this->_banner->getStoreAttributes();
     $bannerAttributesInStores = ['store_id' => ''];
     foreach ($bannerAttributes as $bannerAttribute) {
         $bannerAttributesInStores[$bannerAttribute . '_in_store'] = '';
     }
     $dataObj = $this->_objectFactory->create(['data' => $bannerAttributesInStores]);
     $model = $this->_coreRegistry->registry('banner');
     if ($sliderId = $this->getRequest()->getParam('current_slider_id')) {
         $model->setSliderId($sliderId);
     }
     $dataObj->addData($model->getData());
     $storeViewId = $this->getRequest()->getParam('store');
     $attributesInStore = $this->_valueCollectionFactory->create()->addFieldToFilter('banner_id', $model->getId())->addFieldToFilter('store_id', $storeViewId)->getColumnValues('attribute_code');
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     $form->setHtmlIdPrefix($this->_banner->getFormFieldHtmlIdPrefix());
     $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Banner Information')]);
     if ($model->getId()) {
         $fieldset->addField('banner_id', 'hidden', ['name' => 'banner_id']);
     }
     $elements = [];
     $elements['name'] = $fieldset->addField('name', 'text', ['name' => 'name', 'label' => __('Name'), 'title' => __('Name'), 'required' => true]);
     $elements['status'] = $fieldset->addField('status', 'select', ['label' => __('Status'), 'title' => __('Banner Status'), 'name' => 'status', 'options' => Status::getAvailableStatuses()]);
     $slider = $this->_sliderFactory->create()->load($sliderId);
     if ($slider->getId()) {
         $elements['slider_id'] = $fieldset->addField('slider_id', 'select', ['label' => __('Slider'), 'name' => 'slider_id', 'values' => [['value' => $slider->getId(), 'label' => $slider->getTitle()]]]);
     } else {
         $elements['slider_id'] = $fieldset->addField('slider_id', 'select', ['label' => __('Slider'), 'name' => 'slider_id', 'values' => $model->getAvailableSlides()]);
     }
     $elements['image_alt'] = $fieldset->addField('image_alt', 'text', ['title' => __('Alt Text'), 'label' => __('Alt Text'), 'name' => 'image_alt', 'note' => 'Used for SEO']);
     $elements['click_url'] = $fieldset->addField('click_url', 'text', ['title' => __('URL'), 'label' => __('URL'), 'name' => 'click_url']);
     $elements['image'] = $fieldset->addField('image', 'image', ['title' => __('Banner Image'), 'label' => __('Banner Image'), 'name' => 'image', 'note' => 'Allow image type: jpg, jpeg, gif, png']);
     $dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
     $timeFormat = $this->_localeDate->getTimeFormat(\IntlDateFormatter::SHORT);
     if ($dataObj->hasData('start_time')) {
         $datetime = new \DateTime($dataObj->getData('start_time'));
         $dataObj->setData('start_time', $datetime->setTimezone(new \DateTimeZone($this->_localeDate->getConfigTimezone())));
     }
     if ($dataObj->hasData('end_time')) {
         $datetime = new \DateTime($dataObj->getData('end_time'));
         $dataObj->setData('end_time', $datetime->setTimezone(new \DateTimeZone($this->_localeDate->getConfigTimezone())));
     }
     $style = 'color: #000;background-color: #fff; font-weight: bold; font-size: 13px;';
     $elements['start_time'] = $fieldset->addField('start_time', 'date', ['name' => 'start_time', 'label' => __('Starting time'), 'title' => __('Starting time'), 'required' => true, 'readonly' => true, 'style' => $style, 'class' => 'required-entry', 'date_format' => $dateFormat, 'time_format' => $timeFormat, 'note' => $this->_localeDate->getDateTimeFormat(\IntlDateFormatter::SHORT)]);
     $elements['end_time'] = $fieldset->addField('end_time', 'date', ['name' => 'end_time', 'label' => __('Ending time'), 'title' => __('Ending time'), 'required' => true, 'readonly' => true, 'style' => $style, 'class' => 'required-entry', 'date_format' => $dateFormat, 'time_format' => $timeFormat, 'note' => $this->_localeDate->getDateTimeFormat(\IntlDateFormatter::SHORT)]);
     $elements['target'] = $fieldset->addField('target', 'select', ['label' => __('Target'), 'name' => 'target', 'values' => [['value' => \Magestore\Bannerslider\Model\Banner::BANNER_TARGET_SELF, 'label' => __('New Window with Browser Navigation')], ['value' => \Magestore\Bannerslider\Model\Banner::BANNER_TARGET_PARENT, 'label' => __('Parent Window with Browser Navigation')], ['value' => \Magestore\Bannerslider\Model\Banner::BANNER_TARGET_BLANK, 'label' => __('New Window without Browser Navigation')]]]);
     foreach ($attributesInStore as $attribute) {
         if (isset($elements[$attribute])) {
             $elements[$attribute]->setStoreViewId($storeViewId);
         }
     }
     $form->addValues($dataObj->getData());
     $this->setForm($form);
     return parent::_prepareForm();
 }
예제 #2
0
 /**
  * @covers \Magento\Customer\Controller\Adminhtml\Index\Index::execute
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteWithNewCustomerAndException()
 {
     $subscription = 'false';
     $postValue = ['customer' => ['coolness' => false, 'disable_auto_group_change' => 'false'], 'subscription' => $subscription];
     $filteredData = ['coolness' => false, 'disable_auto_group_change' => 'false'];
     /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $formMock */
     $attributeMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface')->disableOriginalConstructor()->getMock();
     $attributeMock->expects($this->once())->method('getAttributeCode')->willReturn('coolness');
     $attributeMock->expects($this->once())->method('getFrontendInput')->willReturn('int');
     $attributes = [$attributeMock];
     $this->requestMock->expects($this->exactly(2))->method('getPostValue')->willReturn($postValue);
     $this->requestMock->expects($this->exactly(2))->method('getPost')->willReturnMap([['customer', null, $postValue['customer']], ['address', null, null]]);
     /** @var \Magento\Customer\Model\Metadata\Form|\PHPUnit_Framework_MockObject_MockObject $formMock */
     $formMock = $this->getMockBuilder('Magento\\Customer\\Model\\Metadata\\Form')->disableOriginalConstructor()->getMock();
     $this->formFactoryMock->expects($this->once())->method('create')->with(\Magento\Customer\Api\CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, 'adminhtml_customer', [], false, \Magento\Customer\Model\Metadata\Form::DONT_IGNORE_INVISIBLE)->willReturn($formMock);
     $formMock->expects($this->once())->method('extractData')->with($this->requestMock, 'customer')->willReturn($filteredData);
     /** @var \Magento\Framework\DataObject|\PHPUnit_Framework_MockObject_MockObject $objectMock */
     $objectMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock();
     $this->objectFactoryMock->expects($this->once())->method('create')->with(['data' => $postValue])->willReturn($objectMock);
     $objectMock->expects($this->once())->method('getData')->with('customer')->willReturn($postValue['customer']);
     $formMock->expects($this->once())->method('getAttributes')->willReturn($attributes);
     /** @var \Magento\Customer\Api\Data\CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customerMock */
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $this->customerDataFactoryMock->expects($this->once())->method('create')->willReturn($customerMock);
     $exception = new \Exception(__('Exception'));
     $this->managementMock->expects($this->once())->method('createAccount')->with($customerMock, null, '')->willThrowException($exception);
     $customerMock->expects($this->never())->method('getId');
     $this->authorizationMock->expects($this->never())->method('isAllowed');
     $this->subscriberFactoryMock->expects($this->never())->method('create');
     $this->sessionMock->expects($this->never())->method('unsCustomerData');
     $this->registryMock->expects($this->never())->method('register');
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->messageManagerMock->expects($this->once())->method('addException')->with($exception, __('Something went wrong while saving the customer.'));
     $this->sessionMock->expects($this->once())->method('setCustomerData')->with($postValue);
     /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
     $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $this->redirectFactoryMock->expects($this->once())->method('create')->with([])->willReturn($redirectMock);
     $redirectMock->expects($this->once())->method('setPath')->with('customer/*/new', ['_current' => true])->willReturn(true);
     $this->assertEquals($redirectMock, $this->model->execute());
 }
예제 #3
0
 /**
  * Check if rule can be applied for specific address/quote/customer
  *
  * @param \Magento\SalesRule\Model\Rule $rule
  * @param \Magento\Quote\Model\Quote\Address $address
  * @return bool
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function canProcessRule($rule, $address)
 {
     if ($rule->hasIsValidForAddress($address) && !$address->isObjectNew()) {
         return $rule->getIsValidForAddress($address);
     }
     /**
      * check per coupon usage limit
      */
     if ($rule->getCouponType() != \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON) {
         $couponCode = $address->getQuote()->getCouponCode();
         if (strlen($couponCode)) {
             /** @var \Magento\SalesRule\Model\Coupon $coupon */
             $coupon = $this->couponFactory->create();
             $coupon->load($couponCode, 'code');
             if ($coupon->getId()) {
                 // check entire usage limit
                 if ($coupon->getUsageLimit() && $coupon->getTimesUsed() >= $coupon->getUsageLimit()) {
                     $rule->setIsValidForAddress($address, false);
                     return false;
                 }
                 // check per customer usage limit
                 $customerId = $address->getQuote()->getCustomerId();
                 if ($customerId && $coupon->getUsagePerCustomer()) {
                     $couponUsage = $this->objectFactory->create();
                     $this->usageFactory->create()->loadByCustomerCoupon($couponUsage, $customerId, $coupon->getId());
                     if ($couponUsage->getCouponId() && $couponUsage->getTimesUsed() >= $coupon->getUsagePerCustomer()) {
                         $rule->setIsValidForAddress($address, false);
                         return false;
                     }
                 }
             }
         }
     }
     /**
      * check per rule usage limit
      */
     $ruleId = $rule->getId();
     if ($ruleId && $rule->getUsesPerCustomer()) {
         $customerId = $address->getQuote()->getCustomerId();
         /** @var \Magento\SalesRule\Model\Rule\Customer $ruleCustomer */
         $ruleCustomer = $this->customerFactory->create();
         $ruleCustomer->loadByCustomerRule($customerId, $ruleId);
         if ($ruleCustomer->getId()) {
             if ($ruleCustomer->getTimesUsed() >= $rule->getUsesPerCustomer()) {
                 $rule->setIsValidForAddress($address, false);
                 return false;
             }
         }
     }
     $rule->afterLoad();
     /**
      * quote does not meet rule's conditions
      */
     if (!$rule->validate($address)) {
         $rule->setIsValidForAddress($address, false);
         return false;
     }
     /**
      * passed all validations, remember to be valid
      */
     $rule->setIsValidForAddress($address, true);
     return true;
 }