Exemple #1
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);
 }
Exemple #2
0
 /**
  * Determine current product and initialize its recurring payment model
  *
  * @return \Magento\RecurringPayment\Block\Catalog\Product\View\Payment
  */
 protected function _prepareLayout()
 {
     $product = $this->_registry->registry('current_product');
     if ($product) {
         $this->_payment = $this->_paymentFactory->create()->importProduct($product);
     }
     return parent::_prepareLayout();
 }
Exemple #3
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));
 }