示例#1
0
 /**
  * Prepare reference info
  *
  * @return void
  */
 protected function _prepareLayout()
 {
     parent::_prepareLayout();
     $this->_shouldRenderInfo = true;
     foreach (array('method_code', 'reference_id', 'schedule_description', 'state') as $key) {
         $this->_addInfo(array('label' => $this->_fields->getFieldLabel($key), 'value' => $this->_recurringPayment->renderData($key)));
     }
 }
示例#2
0
 /**
  * Return recurring payment getaway information for view
  *
  * @return array
  */
 public function getRecurringPaymentGetawayInformation()
 {
     $recurringPayment = $this->_coreRegistry->registry('current_recurring_payment');
     $information = array();
     foreach ($recurringPayment->getData() as $key => $value) {
         $information[$this->_fields->getFieldLabel($key)] = $value;
     }
     return $information;
 }
示例#3
0
 /**
  * Prepare schedule info
  *
  * @return void
  */
 protected function _prepareLayout()
 {
     parent::_prepareLayout();
     $this->_shouldRenderInfo = true;
     foreach (array('start_datetime', 'suspension_threshold') as $key) {
         $this->_addInfo(array('label' => $this->_fields->getFieldLabel($key), 'value' => $this->_recurringPayment->renderData($key)));
     }
     foreach ($this->_recurringPayment->exportScheduleInfo() as $info) {
         $this->_addInfo(array('label' => $info->getTitle(), 'value' => $info->getSchedule()));
     }
 }
示例#4
0
文件: Fees.php 项目: aiesh/magento2
 /**
  * Prepare fees info
  *
  * @return void
  */
 protected function _prepareLayout()
 {
     parent::_prepareLayout();
     $this->_shouldRenderInfo = true;
     $this->_addInfo(array('label' => $this->_fields->getFieldLabel('currency_code'), 'value' => $this->_recurringPayment->getCurrencyCode()));
     $params = array('init_amount', 'trial_billing_amount', 'billing_amount', 'tax_amount', 'shipping_amount');
     foreach ($params as $key) {
         $value = $this->_recurringPayment->getData($key);
         if ($value) {
             $this->_addInfo(array('label' => $this->_fields->getFieldLabel($key), 'value' => $this->_coreHelper->formatCurrency($value, false), 'is_amount' => true));
         }
     }
 }
示例#5
0
 public function testPrepareProductRecurringPaymentOptions()
 {
     $payment = $this->getMock('Magento\\Framework\\Object', array('setStory', 'importBuyRequest', 'importProduct', 'exportStartDatetime', 'exportScheduleInfo', 'getFieldLabel'), array(), '', false);
     $payment->expects($this->once())->method('exportStartDatetime')->will($this->returnValue('date'));
     $payment->expects($this->any())->method('setStore')->will($this->returnValue($payment));
     $payment->expects($this->once())->method('importBuyRequest')->will($this->returnValue($payment));
     $payment->expects($this->once())->method('exportScheduleInfo')->will($this->returnValue(array(new \Magento\Framework\Object(array('title' => 'Title', 'schedule' => 'schedule')))));
     $this->_fieldsBlock->expects($this->once())->method('getFieldLabel')->will($this->returnValue('Field Label'));
     $this->_recurringPaymentFactory->expects($this->once())->method('create')->will($this->returnValue($payment));
     $product = $this->getMock('Magento\\Framework\\Object', array('getIsRecurring', 'addCustomOption'), array(), '', false);
     $product->expects($this->once())->method('getIsRecurring')->will($this->returnValue(true));
     $infoOptions = array(array('label' => 'Field Label', 'value' => 'date'), array('label' => 'Title', 'value' => 'schedule'));
     $product->expects($this->at(2))->method('addCustomOption')->with('additional_options', serialize($infoOptions));
     $this->_event->expects($this->any())->method('getProduct')->will($this->returnValue($product));
     $this->_testModel->prepareProductRecurringPaymentOptions($this->_observer);
 }
示例#6
0
文件: Grid.php 项目: aiesh/magento2
 /**
  * Prepare grid columns
  *
  * @return $this
  */
 protected function _prepareColumns()
 {
     $this->addColumn('reference_id', array('header' => $this->_fields->getFieldLabel('reference_id'), 'index' => 'reference_id', 'html_decorators' => array('nobr'), 'width' => 1));
     if (!$this->_storeManager->isSingleStoreMode()) {
         $this->addColumn('store_id', array('header' => __('Store'), 'index' => 'store_id', 'type' => 'store', 'store_view' => true, 'display_deleted' => true));
     }
     $this->addColumn('state', array('header' => $this->_fields->getFieldLabel('state'), 'index' => 'state', 'type' => 'options', 'options' => $this->recurringStates->toOptionArray(), 'html_decorators' => array('nobr'), 'width' => 1));
     $this->addColumn('created_at', array('header' => $this->_fields->getFieldLabel('created_at'), 'index' => 'created_at', 'type' => 'datetime', 'html_decorators' => array('nobr'), 'width' => 1));
     $this->addColumn('updated_at', array('header' => $this->_fields->getFieldLabel('updated_at'), 'index' => 'updated_at', 'type' => 'datetime', 'html_decorators' => array('nobr'), 'width' => 1));
     $this->addColumn('method_code', array('header' => $this->_fields->getFieldLabel('method_code'), 'index' => 'method_code', 'type' => 'options', 'options' => $this->payments->toOptionArray()));
     $this->addColumn('schedule_description', array('header' => $this->_fields->getFieldLabel('schedule_description'), 'index' => 'schedule_description'));
     return parent::_prepareColumns();
 }
示例#7
0
文件: Grid.php 项目: aiesh/magento2
 /**
  * Prepare grid data
  *
  * @return void
  */
 protected function _prepareLayout()
 {
     parent::_prepareLayout();
     $this->_preparePayments(array('reference_id', 'state', 'created_at', 'updated_at', 'method_code'));
     $pager = $this->getLayout()->createBlock('Magento\\Theme\\Block\\Html\\Pager')->setCollection($this->_payments)->setIsOutputRequired(false);
     $this->setChild('pager', $pager);
     $this->setGridColumns(array(new \Magento\Framework\Object(array('index' => 'reference_id', 'title' => $this->_fields->getFieldLabel('reference_id'), 'is_nobr' => true, 'width' => 1)), new \Magento\Framework\Object(array('index' => 'state', 'title' => $this->_fields->getFieldLabel('state'))), new \Magento\Framework\Object(array('index' => 'created_at', 'title' => $this->_fields->getFieldLabel('created_at'), 'is_nobr' => true, 'width' => 1, 'is_amount' => true)), new \Magento\Framework\Object(array('index' => 'updated_at', 'title' => $this->_fields->getFieldLabel('updated_at'), 'is_nobr' => true, 'width' => 1)), new \Magento\Framework\Object(array('index' => 'method_code', 'title' => $this->_fields->getFieldLabel('method_code'), 'is_nobr' => true, 'width' => 1))));
     $payments = array();
     $store = $this->_storeManager->getStore();
     foreach ($this->_payments as $payment) {
         $payment->setStore($store);
         $payments[] = new \Magento\Framework\Object(array('reference_id' => $payment->getReferenceId(), 'reference_id_link_url' => $this->getUrl('sales/recurringPayment/view/', array('payment' => $payment->getId())), 'state' => $payment->renderData('state'), 'created_at' => $this->formatDate($payment->getData('created_at'), 'medium', true), 'updated_at' => $payment->getData('updated_at') ? $this->formatDate($payment->getData('updated_at'), 'short', true) : '', 'method_code' => $payment->renderData('method_code')));
     }
     if ($payments) {
         $this->setGridElements($payments);
     }
 }
示例#8
0
 /**
  * Collect buy request and set it as custom option
  *
  * Also sets the collected information and schedule as informational static options
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function prepareProductRecurringPaymentOptions($observer)
 {
     $product = $observer->getEvent()->getProduct();
     $buyRequest = $observer->getEvent()->getBuyRequest();
     if (!$product->getIsRecurring()) {
         return;
     }
     /** @var \Magento\RecurringPayment\Model\RecurringPayment $payment */
     $payment = $this->_recurringPaymentFactory->create(array('locale' => $this->_locale));
     $payment->setStore($this->_storeManager->getStore())->importBuyRequest($buyRequest)->importProduct($product);
     if (!$payment) {
         return;
     }
     // add the start datetime as product custom option
     $product->addCustomOption(\Magento\RecurringPayment\Model\RecurringPayment::PRODUCT_OPTIONS_KEY, serialize(array('start_datetime' => $payment->getStartDatetime())));
     // duplicate as 'additional_options' to render with the product statically
     $infoOptions = array(array('label' => $this->_fields->getFieldLabel('start_datetime'), 'value' => $payment->exportStartDatetime()));
     foreach ($payment->exportScheduleInfo() as $info) {
         $infoOptions[] = array('label' => $info->getTitle(), 'value' => $info->getSchedule());
     }
     $product->addCustomOption('additional_options', serialize($infoOptions));
 }
示例#9
0
 /**
  * Check whether the object data is valid
  * Returns true if valid.
  *
  * @return bool
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function isValid()
 {
     $this->_filterValues();
     $this->_errors = array();
     // start date, order ref ID, schedule description
     if (!$this->getStartDatetime()) {
         $this->_errors['start_datetime'][] = __('The start date is undefined.');
     } elseif (!\Zend_Date::isDate($this->getStartDatetime(), \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT)) {
         $this->_errors['start_datetime'][] = __('The start date has an invalid format.');
     }
     if (!$this->getScheduleDescription()) {
         $this->_errors['schedule_description'][] = __('The schedule description must be provided.');
     }
     // period unit and frequency
     if (!$this->getPeriodUnit() || !in_array($this->getPeriodUnit(), array_keys($this->_periodUnits->toOptionArray()), true)) {
         $this->_errors['period_unit'][] = __('The billing period unit is not defined or wrong.');
     }
     if ($this->getPeriodFrequency() && !$this->_validatePeriodFrequency('period_unit', 'period_frequency')) {
         $this->_errors['period_frequency'][] = __('The period frequency is wrong.');
     }
     // trial period unit, trial frequency, trial period max cycles, trial billing amount
     if ($this->getTrialPeriodUnit()) {
         if (!in_array($this->getTrialPeriodUnit(), array_keys($this->_periodUnits->toOptionArray()), true)) {
             $this->_errors['trial_period_unit'][] = __('The trial billing period unit is wrong.');
         }
         if (!$this->getTrialPeriodFrequency() || !$this->_validatePeriodFrequency('trial_period_unit', 'trial_period_frequency')) {
             $this->_errors['trial_period_frequency'][] = __('The trial period frequency is wrong.');
         }
         if (!$this->getTrialPeriodMaxCycles()) {
             $this->_errors['trial_period_max_cycles'][] = __('The trial period max cycles is wrong.');
         }
         if (!$this->getTrialBillingAmount()) {
             $this->_errors['trial_billing_amount'][] = __('The trial billing amount is wrong.');
         }
     }
     // billing and other amounts
     if (!$this->getBillingAmount() || 0 >= $this->getBillingAmount()) {
         $this->_errors['billing_amount'][] = __('We found a wrong or empty billing amount specified.');
     }
     foreach (array('trial_billing_abount', 'shipping_amount', 'tax_amount', 'init_amount') as $key) {
         if ($this->hasData($key) && 0 >= $this->getData($key)) {
             $this->_errors[$key][] = __('The wrong %1 is specified.', $this->_fields->getFieldLabel($key));
         }
     }
     // currency code
     if (!$this->getCurrencyCode()) {
         $this->_errors['currency_code'][] = __('The currency code is undefined.');
     }
     // payment method
     if (!$this->_manager || !$this->getMethodCode()) {
         $this->_errors['method_code'][] = __('The payment method code is undefined.');
     }
     if ($this->_manager) {
         try {
             $this->_manager->validate($this);
         } catch (\Magento\Framework\Model\Exception $e) {
             $this->_errors['payment_method'][] = $e->getMessage();
         }
     }
     return empty($this->_errors);
 }
示例#10
-3
文件: Form.php 项目: aiesh/magento2
 /**
  * Add a field to the form or fieldset
  * Form and fieldset have same abstract
  *
  * @param \Magento\Framework\Data\Form|\Magento\Framework\Data\Form\Element\Fieldset $formOrFieldset
  * @param string $elementName
  * @param array $options
  * @param string $type
  * @return \Magento\Framework\Data\Form\Element\AbstractElement
  */
 protected function _addField($formOrFieldset, $elementName, $options = array(), $type = 'text')
 {
     $options = array_merge($options, array('name' => $elementName, 'label' => $this->_recurringPaymentFields->getFieldLabel($elementName), 'note' => $this->_recurringPaymentFields->getFieldComment($elementName), 'disabled' => $this->_isReadOnly));
     if (in_array($elementName, array('period_unit', 'period_frequency'))) {
         $options['required'] = true;
     }
     return $formOrFieldset->addField($elementName, $type, $options);
 }