Esempio n. 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());
         }
     }
 }
    /**
     * @param $optionValueId
     * @return DescriptionCollection
     */
    public function getOptionValueDescriptions($optionValueId)
    {
        $query = $this->getDb()->query(<<<SQL
            SELECT *
            FROM `option_value_description` AS od
            WHERE od.option_value_id = :optionValueId
SQL
, [':optionValueId' => $optionValueId]);
        $result = new DescriptionCollection();
        foreach ($query->rows as $row) {
            $result->addDescription(new Description($row['language_id'], $row['name']));
        }
        return $result;
    }
Esempio n. 3
0
 /**
  * @param int $languageId
  * @param string $name
  */
 public function addDescription($languageId, $name)
 {
     $this->descriptions->addDescription(new Description($languageId, $name));
 }
    /**
     * @param int $productId
     * @return DescriptionCollection
     */
    public function getDescription($productId)
    {
        $cacheKey = "product.description." . $productId;
        $result = $this->getCache()->get($cacheKey);
        if (is_null($result)) {
            $query = $this->getDb()->query(<<<SQL
                SELECT *
                FROM product_description
                WHERE product_id = :productId
SQL
, [':productId' => $productId]);
            $result = new DescriptionCollection();
            foreach ($query->rows as $row) {
                $result->addDescription(new Description($row['language_id'], $row['name'], $row['description'], $row['meta_description'], $row['meta_keyword'], $row['seo_title'], $row['seo_h1']));
            }
            $this->getCache()->set($cacheKey, $result);
        }
        return $result;
    }
    /**
     * @param int $manufacturerId
     * @return DescriptionCollection
     */
    public function getDescription($manufacturerId)
    {
        $recordSet = $this->getDb()->query(<<<SQL
            SELECT *
            FROM manufacturer_description
            WHERE manufacturer_id = :manufacturerId
SQL
, [':manufacturerId' => $manufacturerId]);
        $result = new DescriptionCollection();
        $name = $this->getName($manufacturerId);
        foreach ($recordSet->rows as $descriptionEntry) {
            $result->addDescription(new Description($descriptionEntry['language_id'], $name, $descriptionEntry['description'], $descriptionEntry['meta_description'], $descriptionEntry['meta_keyword'], $descriptionEntry['seo_title'], $descriptionEntry['seo_h1']));
        }
        return $result;
    }