Пример #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());
         }
     }
 }
Пример #2
0
 /**
  * @param Product $product
  * @return Product
  */
 public function saveProduct($product)
 {
     $this->getDb()->beginTransaction();
     try {
         if ($product->getId() == 0) {
             $this->getDb()->query("\n                    INSERT INTO product\n                    (model, sku, upc, location, quantity, stock_status_id, image, manufacturer_id, supplier_id, shipping,\n                    price, points, tax_class_id, date_available, weight, weight_class_id, length, width, height, \n                    length_class_id, subtract, minimum, sort_order, status, date_added, date_modified, viewed, user_id,\n                    afc_id, affiliate_commission, korean_name, supplier_url, image_description)\n                    VALUES (\n                        :model, :sku, :upc, :location, :quantity, :stockStatusId, :image, :manufacturerId, :supplierId, \n                        :shipping, :price, :points, 0, :dateAvailable, :weight, :weightClassId, :length, :width, :height, \n                        :lengthClassId, :subtract, :minimum, :sortOrder, :status, NOW(), NOW(), 0, :userId, :afcId, \n                        :affiliateCommission, :koreanName, :supplierUrl, :imageDescription\n                    )\n                    ", [':model' => $product->getModel(), ':sku' => $product->getSku(), ':upc' => $product->getUpc(), ':location' => $product->getLocation(), ':quantity' => $product->getQuantity(), ':stockStatusId' => $product->getStockStatusId(), ':image' => $product->getImagePath(), ':manufacturerId' => $product->getManufacturer()->getId(), ':supplierId' => $product->getSupplier()->getId(), ':shipping' => $product->getShipping(), ':price' => $product->getPrice(), ':points' => $product->getPoints(), ':dateAvailable' => $product->getDateAvailable(), ':weight' => $product->getWeight()->getWeight(), ':weightClassId' => $product->getWeight()->getUnit()->getId(), ':length' => $product->getDimension()->getLength(), ':width' => $product->getDimension()->getWidth(), ':height' => $product->getDimension()->getHeight(), ':lengthClassId' => $product->getDimension()->getUnit()->getId(), ':subtract' => $product->getSubtract(), ':minimum' => $product->getMinimum(), ':sortOrder' => $product->getSortOrder(), ':status' => $product->getStatus(), ':userId' => $product->getUserId(), ':afcId' => $product->getAfcId(), ':affiliateCommission' => $product->getAffiliateCommission(), ':koreanName' => $product->getKoreanName(), ':supplierUrl' => $product->getSupplierUrl(), ':imageDescription' => $product->getImageDescription()]);
             $product->setId($this->getDb()->getLastId());
         } else {
             $this->getDb()->query("\n                    UPDATE product\n                    SET\n                        model = :model,\n                        sku = :sku,\n                        upc = :upc,\n                        location = :location,\n                        minimum = :minimum,\n                        subtract = :subtract,\n                        stock_status_id = :stockStatusId,\n                        date_available = :dateAvailable,\n                        manufacturer_id = :manufacturerId,\n                        supplier_id = :supplierId,\n                        shipping = :shipping,\n                        price = :price,\n                        points = :points,\n                        weight = :weight,\n                        weight_class_id = :weightClassId,\n                        length = :length,\n                        width = :width,\n                        height = :height,\n                        length_class_id = :lengthClassId,\n                        status = :status,\n                        sort_order = :sortOrder,\n                        affiliate_commission = :affiliateCommission,\n                        image = :image,\n                        date_modified = NOW(),\n                        korean_name = :koreanName,\n                        supplier_url = :supplierUrl,\n                        image_description = :imageDescription\n                    WHERE product_id = :productId\n                    ", array(':model' => $product->getModel(), ':sku' => $product->getSku(), ':upc' => $product->getUpc(), ':location' => $product->getLocation(), ':minimum' => $product->getMinimum(), ':subtract' => $product->getSubtract(), ':stockStatusId' => $product->getStockStatusId(), ':dateAvailable' => $product->getDateAvailable(), ':manufacturerId' => $product->getManufacturer()->getId(), ':supplierId' => $product->getSupplier()->getId(), ':shipping' => $product->getShipping(), ':price' => $product->getPrice(), ':points' => $product->getPoints(), ':weight' => $product->getWeight()->getWeight(), ':weightClassId' => $product->getWeight()->getUnit()->getId(), ':length' => $product->getDimension()->getLength(), ':width' => $product->getDimension()->getWidth(), ':height' => $product->getDimension()->getHeight(), ':lengthClassId' => $product->getDimension()->getUnit()->getId(), ':status' => $product->getStatus(), ':sortOrder' => $product->getSortOrder(), ':affiliateCommission' => $product->getAffiliateCommission(), ':image' => $product->getImagePath(), ':productId' => $product->getId(), ':koreanName' => $product->getKoreanName(), ':supplierUrl' => $product->getSupplierUrl(), ':imageDescription' => $product->getImageDescription()));
         }
         $this->saveDescription($product);
         $this->saveStores($product);
         $this->saveAttributes($product);
         $this->saveOptions($product);
         $this->saveDiscounts($product);
         $this->saveSpecials($product);
         $this->saveImages($product);
         $this->saveDownloads($product);
         $this->saveCategories($product);
         $this->saveRelated($product);
         $this->saveRewards($product);
         $this->saveLayouts($product);
         $this->saveTags($product);
         $this->saveUrlAliases($product);
         $this->saveWKAuction($product->getId());
         $this->getCache()->deleteAll('/^product/');
         $this->getDb()->commitTransaction();
     } catch (\Exception $e) {
         $this->getLogger()->write($e->getMessage());
         $this->getLogger()->write($e->getTraceAsString());
         $this->getDb()->rollbackTransaction();
     }
     return $product;
 }