コード例 #1
0
ファイル: product.php プロジェクト: ralfeus/moomi-daeri.com
 private function getForm()
 {
     if ($this->getConfig()->get('wk_auction_timezone_set')) {
         if (sizeof($this->model->getAuctions())) {
             $this->data['isauction'] = $this->model->getAuctions()[0]->isAuction();
             $this->data['auction_min'] = $this->model->getAuctions()[0]->getMin();
             $this->data['auction_max'] = $this->model->getAuctions()[0]->getMax();
             $this->data['auction_end'] = $this->model->getAuctions()[0]->getEndDate();
             $this->data['auction_start'] = $this->model->getAuctions()[0]->getStartDate();
             $this->data['auction_name'] = $this->model->getAuctions()[0]->getName();
         } else {
             $this->data['isauction'] = 0;
             $this->data['auction_min'] = '';
             $this->data['auction_max'] = '';
             $this->data['auction_end'] = '';
             $this->data['auction_start'] = '';
             $this->data['auction_name'] = '';
         }
     }
     if (isset($this->error['warning'])) {
         $this->data['error_warning'] = $this->error['warning'];
     } else {
         $this->data['error_warning'] = '';
     }
     if (isset($this->error['name'])) {
         $this->data['error_name'] = $this->error['name'];
     } else {
         $this->data['error_name'] = array();
     }
     if (isset($this->error['meta_description'])) {
         $this->data['error_meta_description'] = $this->error['meta_description'];
     } else {
         $this->data['error_meta_description'] = array();
     }
     if (isset($this->error['description'])) {
         $this->data['error_description'] = $this->error['description'];
     } else {
         $this->data['error_description'] = array();
     }
     if (isset($this->error['model'])) {
         $this->data['error_model'] = $this->error['model'];
     } else {
         $this->data['error_model'] = '';
     }
     if (isset($this->error['date_available'])) {
         $this->data['error_date_available'] = $this->error['date_available'];
     } else {
         $this->data['error_date_available'] = '';
     }
     $url = '';
     if (isset($this->request->get['sort'])) {
         $url .= '&sort=' . $this->request->get['sort'];
     }
     if (isset($this->request->get['order'])) {
         $url .= '&order=' . $this->request->get['order'];
     }
     if (isset($this->request->get['page'])) {
         $url .= '&page=' . $this->request->get['page'];
     }
     $this->setBreadcrumbs();
     $this->data['model'] = $this->model;
     if (!$this->model->getId()) {
         $this->data['action'] = $this->getUrl()->link('catalog/product/insert', 'token=' . $this->getSession()->data['token'] . $url, 'SSL');
     } else {
         $this->data['action'] = $this->getUrl()->link('catalog/product/update', 'token=' . $this->getSession()->data['token'] . '&product_id=' . $this->model->getId() . $url, 'SSL');
     }
     $this->data['cancel'] = $this->getUrl()->link('catalog/product', 'token=' . $this->getSession()->data['token'] . $url, 'SSL');
     $this->data['token'] = $this->getSession()->data['token'];
     //		if (isset($this->request->get['product_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
     //			$product_info = ProductDAO::getInstance()->getProduct($this->getRequest()->getParam('product_id'));
     //		}
     $this->data['languages'] = $this->getLoader()->model('localisation/language')->getLanguages();
     //		if (isset($this->request->post['product_description'])) {
     //			$this->data['product_description'] = $this->request->post['product_description'];
     //		} elseif (isset($this->request->get['product_id'])) {
     //			$this->data['product_description'] = ProductDAO::getInstance()->getDescription($this->request->get['product_id']);
     //		} else {
     //			$this->data['product_description'] = new Description($this->getLanguage()->getId(), '');
     //		}
     //		if (isset($this->request->post['model'])) {
     //			$this->data['model'] = $this->request->post['model'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['model'] = $product_info['model'];
     //		} else {
     //			$this->data['model'] = '';
     //		}
     //		if (isset($this->request->post['sku'])) {
     //			$this->data['sku'] = $this->request->post['sku'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['sku'] = $product_info['sku'];
     //		} else {
     //			$this->data['sku'] = '';
     //		}
     //
     //		if (isset($this->request->post['upc'])) {
     //			$this->data['upc'] = $this->request->post['upc'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['upc'] = $product_info['upc'];
     //		} else {
     //			$this->data['upc'] = '';
     //		}
     //
     //		if (isset($this->request->post['location'])) {
     //			$this->data['location'] = $this->request->post['location'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['location'] = $product_info['location'];
     //		} else {
     //			$this->data['location'] = '';
     //		}
     //		if (isset($this->request->post['image_description'])) {
     //			$this->data['image_description'] = $this->request->post['image_description'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['image_description'] = $product_info['image_description'];
     //		} else {
     //			$this->data['image_description'] = '';
     //		}
     //
     //		if (isset($this->request->post['image'])) {
     //			$this->data['image'] = $this->request->post['image'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['image'] = $product_info['image'];
     //		} else {
     //			$this->data['image'] = '';
     //		}
     //		if (!empty($product_info) && $product_info['image'] && file_exists(DIR_IMAGE . $product_info['image'])) {
     //			$this->data['thumb'] = ImageService::getInstance()->resize($product_info['image'], 100, 100);
     //		} else {
     //			$this->data['thumb'] = ImageService::getInstance()->resize('no_image.jpg', 100, 100);
     //		}
     $this->data['stores'] = StoreDAO::getInstance()->getStores();
     //		if (isset($this->request->post['product_store'])) {
     //			$this->data['product_store'] = $this->request->post['product_store'];
     //		} elseif (isset($this->request->get['product_id'])) {
     //			$this->data['product_store'] = ProductDAO::getInstance()->getStores($this->request->get['product_id']);
     //		} else {
     //			$this->data['product_store'] = array(0);
     //		}
     //		if (isset($this->request->post['keyword'])) {
     //			$this->data['keyword'] = $this->request->post['keyword'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['keyword'] = $product_info['keyword'];
     //		} else {
     //			$this->data['keyword'] = '';
     //		}
     //		if (isset($this->request->post['product_tag'])) {
     //			$this->data['product_tag'] = $this->request->post['product_tag'];
     //		} elseif (isset($this->request->get['product_id'])) {
     //			$this->data['product_tag'] = ProductDAO::getInstance()->getProductTags($this->request->get['product_id']);
     //		} else {
     //			$this->data['product_tag'] = array();
     //		}
     $this->data['manufacturers'] = ManufacturerDAO::getInstance()->getManufacturers();
     //		if (isset($this->request->post['manufacturer_id'])) {
     //			$this->data['manufacturer_id'] = $this->request->post['manufacturer_id'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['manufacturer_id'] = $product_info['manufacturer_id'];
     //		} else {
     //			$this->data['manufacturer_id'] = 0;
     //		}
     $this->data['suppliers'] = SupplierDAO::getInstance()->getSuppliers();
     //		if (isset($this->request->post['supplier_id'])) {
     //			$this->data['supplier_id'] = $this->request->post['supplier_id'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['supplier_id'] = $product_info['supplier_id'];
     //		} else {
     //			$this->data['supplier_id'] = 0;
     //		}
     //		if (isset($this->request->post['shipping'])) {
     //			$this->data['shipping'] = $this->request->post['shipping'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['shipping'] = $product_info['shipping'];
     //		} else {
     //			$this->data['shipping'] = 1;
     //		}
     //
     //        if (isset($this->request->post['price'])) {
     //            $this->data['price'] = $this->request->post['price'];
     //        } else if (!empty($product_info)) {
     //            $this->data['price'] = $product_info['price'];
     //        } else {
     //            $this->data['price'] = '';
     //        }
     //		$this->data['tax_classes'] = $this->getLoader()->model('localisation/tax_class')->getTaxClasses();
     //
     //		if (isset($this->request->post['tax_class_id'])) {
     //			$this->data['tax_class_id'] = $this->request->post['tax_class_id'];
     //		} else if (!empty($product_info)) {
     //			$this->data['tax_class_id'] = $product_info['tax_class_id'];
     //		} else {
     //			$this->data['tax_class_id'] = 0;
     //		}
     //		if (isset($this->request->post['date_available'])) {
     //			$this->data['date_available'] = $this->request->post['date_available'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['date_available'] = date('Y-m-d', strtotime($product_info['date_available']));
     //		} else {
     //			$this->data['date_available'] = date('Y-m-d', time() - 86400);
     //		}
     //
     //		if (isset($this->request->post['quantity'])) {
     //			$this->data['quantity'] = $this->request->post['quantity'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['quantity'] = $product_info['quantity'];
     //		} else {
     //			$this->data['quantity'] = '';
     //		}
     //		if (isset($this->request->post['minimum'])) {
     //			$this->data['minimum'] = $this->request->post['minimum'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['minimum'] = $product_info['minimum'];
     //		} else {
     //			$this->data['minimum'] = 1;
     //		}
     //		if (isset($this->request->post['subtract'])) {
     //			$this->data['subtract'] = $this->request->post['subtract'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['subtract'] = $product_info['subtract'];
     //		} else {
     //			$this->data['subtract'] = 0;
     //		}
     //		if (isset($this->request->post['sort_order'])) {
     //			$this->data['sort_order'] = $this->request->post['sort_order'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['sort_order'] = $product_info['sort_order'];
     //		} else {
     //			$this->data['sort_order'] = 1;
     //		}
     $this->data['stock_statuses'] = $this->getLoader()->model('localisation/stock_status')->getStockStatuses();
     //
     //		if (isset($this->request->post['stock_status_id'])) {
     //			$this->data['stock_status_id'] = $this->request->post['stock_status_id'];
     //		} else if (!empty($product_info)) {
     //			$this->data['stock_status_id'] = $product_info['stock_status_id'];
     //		} else {
     //			$this->data['stock_status_id'] = $this->getConfig()->get('config_stock_status_id');
     //		}
     //		if (isset($this->request->post['status'])) {
     //			$this->data['status'] = $this->request->post['status'];
     //		} else if (!empty($product_info)) {
     //			$this->data['status'] = $product_info['status'];
     //		} else {
     //			$this->data['status'] = 1;
     //		}
     //		if (isset($this->request->post['affiliate_commission'])) {
     //			$this->data['affiliate_commission'] = $this->request->post['affiliate_commission'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['affiliate_commission'] = $product_info['affiliate_commission'];
     //		} else {
     //			$this->data['affiliate_commission'] = 0;
     //		}
     //		if (isset($this->request->post['weight'])) {
     //			$this->data['weight'] = $this->request->post['weight'];
     //		} else if (!empty($product_info)) {
     //			$this->data['weight'] = $product_info['weight'];
     //		} else {
     //			$this->data['weight'] = '';
     //		}
     $this->data['weight_classes'] = MeasureUnitDAO::getInstance()->getWeightClasses();
     //
     //		if (isset($this->request->post['weight_class_id'])) {
     //			$this->data['weight_class_id'] = $this->request->post['weight_class_id'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['weight_class_id'] = $product_info['weight_class_id'];
     //		} else {
     //			$this->data['weight_class_id'] = $this->getConfig()->get('config_weight_class_id');
     //		}
     //		if (isset($this->request->post['length'])) {
     //			$this->data['length'] = $this->request->post['length'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['length'] = $product_info['length'];
     //		} else {
     //			$this->data['length'] = '';
     //		}
     //
     //		if (isset($this->request->post['width'])) {
     //			$this->data['width'] = $this->request->post['width'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['width'] = $product_info['width'];
     //		} else {
     //			$this->data['width'] = '';
     //		}
     //
     //		if (isset($this->request->post['height'])) {
     //			$this->data['height'] = $this->request->post['height'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['height'] = $product_info['height'];
     //		} else {
     //			$this->data['height'] = '';
     //		}
     //		$this->getLoader()->model('localisation/length_class');
     $this->data['length_classes'] = MeasureUnitDAO::getInstance()->getLengthClasses();
     //		if (isset($this->request->post['length_class_id'])) {
     //			$this->data['length_class_id'] = $this->request->post['length_class_id'];
     //		} elseif (!empty($product_info)) {
     //			$this->data['length_class_id'] = $product_info['length_class_id'];
     //		} else {
     //			$this->data['length_class_id'] = $this->getConfig()->get('config_length_class_id');
     //		}
     //		if (isset($this->request->post['product_attribute'])) {
     //			$this->data['product_attributes'] = $this->request->post['product_attribute'];
     //		} elseif (isset($this->request->get['product_id'])) {
     //			$this->data['product_attributes'] = ProductDAO::getInstance()->getProductAttributes($this->request->get['product_id']);
     //		} else {
     //			$this->data['product_attributes'] = array();
     //		}
     //		$this->data['product_options'] = array();
     //		if (isset($this->request->post['product_option'])) {
     //			$product_options = $this->request->post['product_option'];
     //            $product_options = new ProductOptionCollection();
     //            foreach ($this->getRequest()->getParam('product_option') as $productOptionParam) {
     //                $productOption = new ProductOption(
     //                    $productOptionParam['product_option_id'],
     //                    Produ
     //                )
     //            }
     //		} elseif (isset($this->request->get['product_id'])) {
     //			$product_options = ProductDAO::getInstance()->getProductOptions($this->request->get['product_id']);
     //		} else {
     //			$product_options = [];
     //		}
     //
     //
     //		foreach ($product_options as $product_option) {
     //			if ($product_option->getType() == 'select' || $product_option->getType() == 'radio' || $product_option->getType() == 'checkbox' || $product_option->getType() == 'image') {
     //				$product_option_value_data = array();
     //
     //				foreach ($product_option->getValue() as $product_option_value) {
     //					$product_option_value_data[] = array(
     //						'product_option_value_id' => $product_option_value->getId(),
     //						'option_value_id'         => $product_option_value->getOptionValue()->getId(),
     //						'quantity'                => $product_option_value->getQuantity(),
     //						'subtract'                => $product_option_value->getSubtract(),
     //						'price'                   => $product_option_value->getPrice(),
     //						'price_prefix'            => $product_option_value->getPrice() > 0 ? '+' : '-',
     //						'points'                  => $product_option_value->getPoints(),
     //						'points_prefix'           => $product_option_value->getPoints() > 0 ? '+' : '-',
     //						'weight'                  => $product_option_value->getWeight(),
     //						'weight_prefix'           => $product_option_value->getWeight() > 0 ? '+' : '-'
     //					);
     //				}
     //
     //				$this->data['product_options'][] = array(
     //					'product_option_id'    => $product_option->getId(),
     //					'option_id'            => $product_option->getOption()->getId(),
     //					'name'                 => $product_option->getOption()->getName(),
     //					'type'                 => $product_option->getType(),
     //					'product_option_value' => $product_option_value_data,
     //					'required'             => $product_option->isRequired()
     //				);
     //			} else {
     //				$this->data['product_options'][] = array(
     //					'product_option_id' => $product_option->getId(),
     //					'option_id'         => $product_option->getOption()->getId(),
     //					'name'              => $product_option->getOption()->getName(),
     //					'type'              => $product_option->getType(),
     //					'option_value'      => $product_option->getValue(),
     //					'required'          => $product_option->isRequired()
     //				);
     //			}
     //		}
     $this->data['create_option_block'] = $this->getOptionForm();
     $this->data['customer_groups'] = $this->getLoader()->model('sale/customer_group')->getCustomerGroups();
     //		if (isset($this->request->post['product_discount'])) {
     //			$this->data['product_discounts'] = $this->request->post['product_discount'];
     //		} elseif (isset($this->request->get['product_id'])) {
     //			$this->data['product_discounts'] = ProductDAO::getInstance()->getProductDiscounts($this->request->get['product_id']);
     //		} else {
     //			$this->data['product_discounts'] = array();
     //		}
     //		if (isset($this->request->post['product_special'])) {
     //			$this->data['product_specials'] = $this->request->post['product_special'];
     //		} elseif (isset($this->request->get['product_id'])) {
     //			$this->data['product_specials'] = ProductDAO::getInstance()->getProductSpecials($this->request->get['product_id']);
     //		} else {
     //			$this->data['product_specials'] = array();
     //		}
     //		if (isset($this->request->post['product_image'])) {
     //			$product_images = $this->request->post['product_image'];
     //		} elseif (isset($this->request->get['product_id'])) {
     //			$product_images = ProductDAO::getInstance()->getProductImages($this->request->get['product_id']);
     //		} else {
     //			$product_images = array();
     //		}
     $this->data['product_images'] = array();
     foreach ($this->model->getImages() as $productImage) {
         if (file_exists(DIR_IMAGE . $productImage->getImagePath())) {
             $image = $productImage->getImagePath();
         } else {
             $image = 'no_image.jpg';
         }
         $this->data['product_images'][] = array('image' => $image, 'thumb' => ImageService::getInstance()->resize($image, 100, 100), 'sort_order' => $productImage->getSortOrder());
     }
     $this->data['no_image'] = ImageService::getInstance()->resize('no_image.jpg', 100, 100);
     $this->data['downloads'] = $this->getLoader()->model('catalog/download')->getDownloads();
     //		if (isset($this->request->post['product_download'])) {
     //			$this->data['product_download'] = $this->request->post['product_download'];
     //		} elseif (isset($this->request->get['product_id'])) {
     //			$this->data['product_download'] = ProductDAO::getInstance()->getProductDownloads($this->request->get['product_id']);
     //		} else {
     //			$this->data['product_download'] = array();
     //		}
     $categories = CategoryDAO::getInstance()->getAllCategories();
     $this->data['categories'] = $this->getAllCategories($categories);
     //		if (isset($this->request->post['main_category_id'])) {
     //			$this->data['main_category_id'] = $this->request->post['main_category_id'];
     //		} elseif (isset($product_info)) {
     //			$this->data['main_category_id'] = $this->model_catalog_product->getProductMainCategoryId($this->request->get['product_id']);
     //		} else {
     //			$this->data['main_category_id'] = 0;
     //		}
     //		if (isset($this->request->post['product_category'])) {
     //			$this->data['product_category'] = $this->request->post['product_category'];
     //		} elseif (isset($this->request->get['product_id'])) {
     //			$this->data['product_category'] = $this->model_catalog_product->getProductCategories($this->request->get['product_id']);
     //		} else {
     //			$this->data['product_category'] = array();
     //		}
     $this->data['categoriesParent'] = $this->getCategoriesParent(0, array_map(function (ProductCategory $item) {
         return $item->getCategory()->getId();
     }, $this->model->getCategories()));
     //		$this->data['scripts'] = '$("#navigation ul").treeview({persist: "location",	collapsed: true, unique: true	});';
     //		if (isset($this->request->post['product_related'])) {
     //			$products = $this->request->post['product_related'];
     //		} elseif (isset($this->request->get['product_id'])) {
     //			$products = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);
     //		} else {
     //			$products = array();
     //		}
     //
     //		$this->data['product_related'] = array();
     //
     //		foreach ($products as $product_id) {
     //			$related_info = $this->model_catalog_product->getProduct($product_id);
     //
     //			if ($related_info) {
     //				$this->data['product_related'][] = array(
     //					'product_id' => $related_info['product_id'],
     //					'name'       => $related_info['name']
     //				);
     //			}
     //		}
     //		if (isset($this->request->post['points'])) {
     //			$this->data['points'] = $this->request->post['points'];
     //		} else if (!empty($product_info)) {
     //			$this->data['points'] = $product_info['points'];
     //		} else {
     //			$this->data['points'] = '';
     //		}
     //		if (isset($this->request->post['koreanName'])) {
     //			$this->data['koreanName'] = $this->request->post['koreanName'];
     //		} else if (!empty($product_info)) {
     //			$this->data['koreanName'] = $product_info['korean_name'];
     //		} else {
     //			$this->data['koreanName'] = '';
     //		}
     //		if (isset($this->request->post['supplierUrl'])) {
     //			$this->data['supplierUrl'] = $this->request->post['supplierUrl'];
     //		} else if (!empty($product_info)) {
     //			$this->data['supplierUrl'] = $product_info['supplier_url'];
     //		} else {
     //			$this->data['supplierUrl'] = '';
     //		}
     //		if (isset($this->request->post['product_reward'])) {
     //			$this->data['product_reward'] = $this->request->post['product_reward'];
     //		} elseif (isset($this->request->get['product_id'])) {
     //			$this->data['product_reward'] = $this->model_catalog_product->getProductRewards($this->request->get['product_id']);
     //		} else {
     //			$this->data['product_reward'] = array();
     //		}
     //		if (isset($this->request->post['product_layout'])) {
     //			$this->data['product_layout'] = $this->request->post['product_layout'];
     //		} elseif (isset($this->request->get['product_id'])) {
     //			$this->data['product_layout'] = $this->model_catalog_product->getProductLayouts($this->request->get['product_id']);
     //		} else {
     //			$this->data['product_layout'] = array();
     //		}
     $this->data['layouts'] = $this->getLoader()->model('design/layout')->getLayouts();
     $this->children = array('common/header', 'common/footer');
     $this->getResponse()->setOutput($this->render('catalog/productForm.tpl.php'));
 }
コード例 #2
0
 /**
  * @param Product $product
  * @param ProductOption $productOption
  * @param bool $productOptionsExisted
  */
 private function saveOptionValues($product, $productOption, $productOptionsExisted)
 {
     foreach ($productOption->getValue() as $productOptionValue) {
         $productOptionValueParams = [':productOptionValueId' => $productOptionValue->getId(), ':productOptionId' => $productOption->getId(), ':productId' => $product->getId(), ':optionId' => $productOption->getOption()->getId(), ':optionValueId' => $productOptionValue->getOptionValue()->getId(), ':quantity' => $productOptionValue->getQuantity(), ':subtract' => $productOptionValue->getSubtract(), ':price' => abs($productOptionValue->getPrice()), ':pricePrefix' => $productOptionValue->getPrice() < 0 ? '-' : '+', ':points' => abs($productOptionValue->getPoints()), ':pointsPrefix' => $productOptionValue->getPoints() < 0 ? '-' : '+', ':weight' => abs($productOptionValue->getWeight()), ':weightPrefix' => $productOptionValue->getWeight() < 0 ? '-' : '+'];
         if ($productOptionsExisted) {
             $this->getDb()->query("\n                    INSERT INTO product_option_value\n                    SET\n                        product_option_value_id = :productOptionValueId,\n                        product_option_id = :productOptionId,\n                        product_id = :productId,\n                        option_id = :optionId,\n                        option_value_id = :optionValueId,\n                        quantity = :quantity,\n                        subtract = :subtract,\n                        price = :price,\n                        price_prefix = :pricePrefix,\n                        points = :points,\n                        points_prefix = :pointsPrefix,\n                        weight = :weight,\n                        weight_prefix = :weightPrefix\n                ", $productOptionValueParams);
         } else {
             unset($productOptionValueParams[':productOptionValueId']);
             $this->getDb()->query("\n                    INSERT INTO product_option_value\n                    SET\n                        product_option_id = :productOptionId,\n                        product_id = :productId,\n                        option_id = :optionId,\n                        option_value_id = :optionValueId,\n                        quantity = :quantity,\n                        subtract = :subtract,\n                        price = :price,\n                        price_prefix = :pricePrefix,\n                        points = :points,\n                        points_prefix = :pointsPrefix,\n                        weight = :weight,\n                        weight_prefix = :weightPrefix\n                ", $productOptionValueParams);
         }
     }
 }