Example #1
0
 /**
  * Execute a command and return a response. Does not render
  * @param IRequest $Request
  * @throws \Exception
  * @return IResponse the execution response
  */
 function execute(IRequest $Request)
 {
     $SessionRequest = $Request;
     if (!$SessionRequest instanceof ISessionRequest) {
         throw new \Exception("Session required");
     }
     $Account = AbstractAccountType::loadFromSession($SessionRequest);
     if (!$Account instanceof MerchantAccount) {
         throw new RequestException("Only merchants may create a new Product");
     }
     $productOptions = array("Choose a Product Type" => null);
     /** @var AbstractProductType[] $ProductTypes */
     $ProductTypes = array();
     $ProductForms = array();
     foreach (Types\AbstractProductType::loadAllProductTypes() as $ProductType) {
         $ProductTypes[$ProductType->getTypeName()] = $ProductType;
         $FieldSet = $ProductType->getConfigFieldSet($Request);
         $FieldSet->setAttribute('disabled', 'disabled');
         $ProductForms[] = $FieldSet;
         //			$FieldSet = $ProductType->getRatesFieldSet($Request);
         //			$FieldSet->setAttribute('disabled', 'disabled');
         //			$ProductForms[] = $FieldSet;
         $productOptions[$ProductType->getTypeDescription()] = $ProductType->getTypeName();
     }
     $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '/assets/product.js'), new HTMLHeaderStyleSheet(__DIR__ . '/assets/product.css'), new HTMLElement('fieldset', 'fieldset-create-product', new HTMLElement('legend', 'legend-product', self::TITLE), new HTMLElement('label', null, "Status<br/>", new HTMLSelectField(self::PARAM_PRODUCT_STATUS, ProductEntry::$StatusOptions, new RequiredValidation())), "<br/><br/>", new HTMLElement('label', null, "Choose a Product Type<br/>", new HTMLSelectField(self::PARAM_PRODUCT_TYPE, $productOptions, new RequiredValidation())), "<br/><br/>", $ProductForms, "<br/><br/>Submit:<br/>", new HTMLButton('submit', 'Submit', 'submit')), "<br/>");
     if (!$Request instanceof IFormRequest) {
         return $Form;
     }
     $status = $Form->validateField($Request, self::PARAM_PRODUCT_STATUS);
     $productType = $Form->validateField($Request, self::PARAM_PRODUCT_TYPE);
     //		$sourceID = $Form->validateField($Request, self::PARAM_PAYMENT_SOURCE_TYPE);
     $ChosenProduct = $ProductTypes[$productType];
     $ChosenProduct->validateConfigRequest($Request, $Form);
     $accountID = 'default';
     if ($Account) {
         $accountID = $Account->getID();
     }
     $id = ProductEntry::create($Request, $ChosenProduct, $accountID, $status);
     return new RedirectResponse(ManageProduct::getRequestURL($id), "Product created successfully. Redirecting...", 5);
 }
Example #2
0
 static function create(IRequest $Request, AbstractProductType $Product, $accountID, $status = 0)
 {
     $id = strtoupper(uniqid(self::ID_PREFIX));
     $Product->setProductID($id);
     $Product->setAccountID($accountID);
     $inserted = self::table()->insert(array(ProductTable::COLUMN_ID => $id, ProductTable::COLUMN_ACCOUNT_ID => $accountID, ProductTable::COLUMN_STATUS => $status, ProductTable::COLUMN_PRODUCT => serialize($Product)))->execute($Request);
     if (!$inserted) {
         throw new \InvalidArgumentException("Could not insert " . __CLASS__);
     }
     $Request->log("New Product Entry Inserted: " . get_class($Product), $Request::VERBOSE);
     return $id;
 }
 /**
  * Map data to the key map
  * @param IKeyMapper $Map the map inst to add data to
  * @internal param \CPath\Request\IRequest $Request
  * @internal param \CPath\Request\IRequest $Request
  * @return void
  */
 function mapKeys(IKeyMapper $Map)
 {
     parent::mapKeys($Map);
     if ($this->created) {
         $Map->map('shipping-full_name', $this->full_name);
         $Map->map('shipping-address', $this->address);
         $Map->map('shipping-address2', $this->address2);
         $Map->map('shipping-city', $this->city);
         $Map->map('shipping-state', $this->state);
         $Map->map('shipping-country', $this->country);
     }
 }