/**
  * Create/Edit State
  *
  * @param array $variables
  *
  * @throws HttpException
  */
 public function actionEdit(array $variables = [])
 {
     $this->requireAdmin();
     //getting related product
     if (empty($variables['productId'])) {
         throw new HttpException(400);
     }
     $variables['product'] = craft()->market_product->getById($variables['productId']);
     if (!$variables['product']) {
         throw new HttpException(404, craft::t('Product not found'));
     }
     //getting variant model
     if (empty($variables['variant'])) {
         if (!empty($variables['id'])) {
             $variables['variant'] = craft()->market_variant->getById($variables['id']);
             if (!$variables['variant']) {
                 throw new HttpException(404);
             }
         } else {
             $variables['variant'] = new Market_VariantModel();
         }
     }
     $variables['productType'] = craft()->market_productType->getByHandle($variables['productTypeHandle']);
     $this->prepVariables($variables);
     if (!empty($variables['variant']->id)) {
         $variables['title'] = Craft::t('Variant for {product}', ['product' => $variables['product']]);
     } else {
         $variables['title'] = Craft::t('Create a Variant for {product}', ['product' => $variables['product']]);
     }
     $this->renderTemplate('market/products/variants/_edit', $variables);
 }
 /**
  * Prepare screen to edit a product.
  *
  * @param array $variables
  *
  * @throws HttpException
  */
 public function actionEditProduct(array $variables = [])
 {
     $this->requireAdmin();
     if (!empty($variables['productTypeHandle'])) {
         $variables['productType'] = craft()->market_productType->getByHandle($variables['productTypeHandle']);
     }
     if (empty($variables['productType'])) {
         throw new HttpException(400, craft::t('Wrong product type specified'));
     }
     if (empty($variables['product'])) {
         if (!empty($variables['productId'])) {
             $variables['product'] = craft()->market_product->getById($variables['productId']);
             if (!$variables['product']->id) {
                 throw new HttpException(404);
             }
         } else {
             $variables['product'] = new Market_ProductModel();
             $variables['product']->typeId = $variables['productType']->id;
         }
     }
     if (!empty($variables['product']->id)) {
         $variables['title'] = $variables['product']->title;
     } else {
         $variables['title'] = Craft::t('Create a new Product');
     }
     $variables['continueEditingUrl'] = "market/products/" . $variables['productTypeHandle'] . "/{id}";
     $variables['taxCategories'] = \CHtml::listData(craft()->market_taxCategory->getAll(), 'id', 'name');
     $this->_prepVariables($variables);
     $this->renderTemplate('market/products/_edit', $variables);
 }
 /**
  * @param string $status
  * @return string
  */
 private function getNotificationSubject($status)
 {
     switch ($status) {
         case DraftNotifications_EventCallbackService::STATUS_NEW_DRAFT:
             $message = Craft::t('A new draft has been saved');
             break;
         case DraftNotifications_EventCallbackService::STATUS_EXISTING_DRAFT:
             $message = Craft::t('An existing draft has been saved');
             break;
         case DraftNotifications_EventCallbackService::STATUS_DELETED_DRAFT:
             $message = Craft::t('A draft has been deleted');
             break;
         default:
             $message = craft::t('A draft has been saved');
     }
     return $message;
 }