Beispiel #1
0
 protected function initModel()
 {
     if ($this->getRequest()->getMethod() == 'POST') {
         // Cases: submit create and update data
         $descriptions = new DescriptionCollection();
         foreach ($this->getRequest()->getParam('product_description') as $language => $description) {
             $descriptions->addDescription(new Description($language, $description['name'], $description['description'], $description['meta_description'], $description['meta_keyword'], $description['seo_title'], $description['seo_h1']));
         }
         $categories = [];
         foreach ($this->getRequest()->getParam('product_category') as $categoryId) {
             $categories[] = new ProductCategory(new Category($categoryId), $categoryId == $this->getRequest()->getParam('main_category_id'));
         }
         $this->model = new Product(0, $this->getLanguage()->getId(), null, $this->getRequest()->getParam('affiliate_commission'), null, $this->getRequest()->getParam('date_available'), null, $descriptions, new Dimensions($this->getRequest()->getParam('length_class_id'), $this->getRequest()->getParam('height'), $this->getRequest()->getParam('length'), $this->getRequest()->getParam('width')), $this->getRequest()->getParam('image'), $this->getRequest()->getParam('keyword'), $this->getRequest()->getParam('koreanName'), $this->getRequest()->getParam('location'), $this->getRequest()->getParam('manufacturer_id'), $this->getRequest()->getParam('minimum'), $this->getRequest()->getParam('model'), null, $this->getRequest()->getParam('points'), $this->getRequest()->getParam('price'), $this->getRequest()->getParam('quantity'), $this->getRequest()->getParam('shipping'), $this->getRequest()->getParam('sku'), $this->getRequest()->getParam('sort_order'), $this->getRequest()->getParam('status'), $this->getRequest()->getParam('stock_status_id'), $this->getRequest()->getParam('product_store'), $this->getRequest()->getParam('subtract'), new Supplier($this->getRequest()->getParam('supplier_id')), $this->getRequest()->getParam('supplierUrl'), $this->getRequest()->getParam('product_tag'), $this->getRequest()->getParam('upc'), null, null, new Weight($this->getRequest()->getParam('weight_class_id'), $this->getRequest()->getParam('weight')), $this->getRequest()->getParam('product_attribute'), $this->getRequest()->getParam('product_discount'), $this->getRequest()->getParam('product_special'), $this->getRequest()->getParam('product_download'), $categories, $this->getRequest()->getParam('product_related'), $this->getRequest()->getParam('product_layout'), $this->getRequest()->getParam('product_reward'), $this->getRequest()->getParam('image_description'));
         $productOptions = new ProductOptionCollection();
         foreach ($this->getRequest()->getParam('product_option') as $productOptionParam) {
             $productOption = new ProductOption($productOptionParam['product_option_id'], $this->model, OptionDAO::getInstance()->getOptionById($productOptionParam['option_id']), null, $productOptionParam['required'], 0, false);
             if ($productOption->getOption()->isSingleValueType()) {
                 $productOption->setValue($productOptionParam['option_value']);
             } else {
                 if ($productOption->getOption()->isMultiValueType()) {
                     foreach ($productOptionParam['product_option_value'] as $productOptionValueParam) {
                         $productOption->getValue()->attach(new ProductOptionValue($productOptionValueParam['product_option_value_id'], $productOption, new OptionValue($productOption->getOption(), $productOptionValueParam['option_value_id']), $productOptionValueParam['quantity'], $productOptionValueParam['subtract'], $productOptionValueParam['price_prefix'] == '+' ? $productOptionValueParam['price'] : -$productOptionValueParam['price'], $productOptionValueParam['points_prefix'] == '+' ? $productOptionValueParam['points'] : -$productOptionValueParam['points'], $productOptionValueParam['weight_prefix'] == '+' ? $productOptionValueParam['weight'] : -$productOptionValueParam['weight'], 0));
                     }
                 }
             }
             $productOptions->attach($productOption);
         }
         $auctions = [];
         foreach ($this->getRequest()->getParam('product_auctions') as $productAuctionParam) {
             $auctions[] = new Auction(null, $this->model, $this->getRequest()->getParam('auction_name', $this->getConfig()->get('auction_name')), $this->getRequest()->getParam('isauction', $this->getConfig()->get('isauction')), $this->getRequest()->getParam('auction_min', $this->getConfig()->get('auction_min')), $this->getRequest()->getParam('auction_max', $this->getConfig()->get('auction_max')), $this->getRequest()->getParam('auction_start', $this->getConfig()->get('auction_start')), $this->getRequest()->getParam('auction_end', $this->getConfig()->get('auction_end')));
         }
         $this->model->setImages($this->getRequest()->getParam('product_image'));
         $this->model->setOptions($productOptions);
         $this->model->setAuctions($auctions);
         if ($this->getRequest()->getParam('product_id')) {
             // Case: submit update changes
             $this->model->setId($this->getRequest()->getParam('product_id'));
         }
         //TODO: Something to do with UrlAlias
     } else {
         if ($this->getRequest()->getParam('product_id')) {
             // Case: update fill the form for editing
             $this->model = ProductDAO::getInstance()->getProduct($this->getRequest()->getParam('product_id'), false, true);
         } else {
             // Case: create open the form for editing
             $this->model = new Product(0, $this->getLanguage()->getId());
         }
     }
 }