/** * Actions to perform after saving a course * * @param object $model \Components\Courses\Models\Course * @param boolean $isNew Is this a newly created entry? * @return void */ public function onOfferingSave($model) { if (!$model->exists()) { return; } $params = new \Hubzero\Config\Registry($model->get('params')); if ($params->get('store_product', 0)) { $course = \Components\Courses\Models\Course::getInstance($model->get('course_id')); $title = $course->get('title') . ' (' . $model->get('title') . ')'; $description = $course->get('blurb'); $price = $params->get('store_price', '30.00'); $duration = $params->get('store_membership_duration', '1 YEAR'); if (!$params->get('store_product_id', 0)) { include_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Course.php'; $product = new StorefrontModelCourse(); $product->setName($title); $product->setDescription($description); $product->setPrice($price); // We don't want products showing up for non-published courses if ($model->get('state') != 1) { $product->setActiveStatus(0); } else { $product->setActiveStatus(1); } // Membership model: membership duration period (must me in MySQL date format: 1 DAY, 2 MONTH, 3 YEAR...) $product->setTimeToLive($duration); // Course alias id $product->setCourseId($course->get('alias')); $product->setOfferingId($model->get('alias')); try { // Returns object with values, pId is the new product ID to link to $info = $product->add(); $params->set('store_product_id', $info->pId); $model->set('params', $params->toString()); $model->store(); } catch (Exception $e) { $this->setError('ERROR: ' . $e->getMessage()); } } else { $warehouse = new StorefrontModelWarehouse(); try { // Get course by pID returned with $course->add() above $product = $warehouse->getCourse($params->get('store_product_id', 0)); $product->setName($title); $product->setDescription($description); $product->setPrice($price); $product->setTimeToLive($duration); if ($model->get('state') != 1) { $product->setActiveStatus(0); } else { $product->setActiveStatus(1); } $product->update(); } catch (Exception $e) { $this->setError('ERROR: ' . $e->getMessage()); } } } }
/** * Get coupon * * @param string coupon code * @return StorefrontModelCoupon Instance of a coupon */ public function getCoupon($code) { // Seems like unused code throw new Exception('Not sure if this is ever used. Warehouse.php'); // Create a StorefrontModelCoupon if ($productType == 'product') { $product = new StorefrontModelProduct(); } elseif ($productType == 'course') { $product = new StorefrontModelCourse(); } // Get all product info $productInfo = $this->getProductInfo($pId, true); $product->setType($productInfo->ptId); $product->setId($productInfo->pId); $product->setName($productInfo->pName); $product->setDescription($productInfo->pDescription); $product->setTagline($productInfo->pTagline); $product->setActiveStatus($productInfo->pActive); // Get collections $collections = $this->_getProductCollections($pId); foreach ($collections as $cId) { $product->addToCollection($cId); } // Get SKUs $skus = $this->getProductSkus($pId); // Add SKUs to product foreach ($skus as $sId) { $sku = $this->getSku($sId, $productType); $product->addSku($sku); } $product->verify(); return $product; }