Example #1
0
 /**
  * Serialize or remove before saving
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return void
  */
 public function beforeSave($product)
 {
     if ($product->hasIsRecurring()) {
         if ($product->getIsRecurring()) {
             parent::beforeSave($product);
         } else {
             $product->unsRecurringPayment();
         }
     }
 }
Example #2
0
 /**
  * Import product recurring payment information
  * Returns false if it cannot be imported
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return $this|false
  */
 public function importProduct(\Magento\Catalog\Model\Product $product)
 {
     if ($product->getIsRecurring() && is_array($product->getRecurringPayment())) {
         // import recurring payment data
         $this->addData($product->getRecurringPayment());
         // automatically set product name if there is no schedule description
         if (!$this->hasScheduleDescription()) {
             $this->setScheduleDescription($product->getName());
         }
         // collect start datetime from the product options
         $options = $product->getCustomOption(self::PRODUCT_OPTIONS_KEY);
         if ($options) {
             $options = unserialize($options->getValue());
             if (is_array($options)) {
                 if (isset($options['start_datetime'])) {
                     $startDatetime = new \Magento\Framework\Stdlib\DateTime\Date($options['start_datetime'], \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT);
                     $this->setNearestStartDatetime($startDatetime);
                 }
             }
         }
         return $this->_filterValues();
     }
     return false;
 }
Example #3
0
 /**
  * @param \Magento\Catalog\Model\Product\Type\AbstractType $subject
  * @param callable $proceed
  * @param \Magento\Catalog\Model\Product $product
  * @return bool
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundHasOptions(\Magento\Catalog\Model\Product\Type\AbstractType $subject, \Closure $proceed, \Magento\Catalog\Model\Product $product)
 {
     return $product->getIsRecurring() ?: $proceed($product);
 }