예제 #1
0
	/**
	 * Test cart preview total product count when the same product is used multiple times
	 */
	public function testCartPreviewCount_DuplicateProducts()
	{
		$cart_srl = 774;
		$cart = new Cart($cart_srl);

		// Make sure we start with 4 products
		$this->assertEquals(4, count($cart->getProducts()));

		// Add one new product to cart (of the same type as one that already is in the cart)
		$product_repository = new ProductRepository();
		$product = $product_repository->getProduct(133);
		$cart->addProduct($product, 1);

		// Make sure new product was added to cart
		$cart = new Cart($cart_srl);
		$this->assertEquals(5, $cart->count(TRUE));

		$cart_preview = new CartPreview($cart, 2);

		$cart_preview_products = $cart_preview->getProducts();
		$this->assertEquals(2, count($cart_preview_products));

		$cart_products_count = $cart_preview->getCartProductsCount();
		$this->assertEquals(5, $cart_products_count);
	}
예제 #2
0
 /**
  * check and update stocks
  * @return array
  */
 public function checkAndUpdateStocks()
 {
     $products = $this->order->getProducts();
     $productRepo = new ProductRepository();
     /** @var $orderProduct OrderProduct */
     $productsEmptyStocks = array();
     foreach ($products as $orderProduct) {
         /** @var $product SimpleProduct */
         $product = $productRepo->getProduct($orderProduct->product_srl, false);
         if ($orderProduct->quantity == $product->qty) {
             $productsEmptyStocks[] = $product;
         }
         $product->substractFromStock($orderProduct->quantity);
     }
     return $productsEmptyStocks;
 }
예제 #3
0
 /**
  * Path to the product image thumbnail
  *
  * @param int    $width
  * @param int    $height
  * @param string $thumbnail_type
  * @return mixed|string
  */
 function getThumbnailPath($width = 80, $height = 0, $thumbnail_type = '')
 {
     if ($this->product) {
         if ($this->product->parent_product_srl) {
             $productRepo = new ProductRepository();
             $parent_product = $productRepo->getProduct($this->product->parent_product_srl);
             return $parent_product->getPrimaryImage()->getThumbnailPath($width, $height, $thumbnail_type);
         } else {
             return $this->product->getPrimaryImage()->getThumbnailPath($width, $height, $thumbnail_type);
         }
     } else {
         return '';
     }
 }
예제 #4
0
 public function testCount()
 {
     $cRepo = new CartRepository();
     $pRepo = new ProductRepository();
     $cart = $cRepo->getCart(NULL, 14);
     $cart->emptyCart();
     $cart->addProduct($pRepo->getProduct(130));
     $cart->addProduct($pRepo->getProduct(132));
     $this->assertEquals(2, $cart->count());
 }
예제 #5
0
 /**
  * cart add product
  * @return Object
  */
 public function procShopToolCartAddProduct()
 {
     $cartRepository = new CartRepository();
     if ($product_srl = Context::get('product_srl')) {
         $productsRepo = new ProductRepository();
         if ($product = $productsRepo->getProduct($product_srl))
         {
             if (!($product instanceof SimpleProduct)) {
                 return new Object(-1, 'msg_invalid_request');
             }
             $logged_info = Context::get('logged_info');
             $cart = $cartRepository->getCart($this->module_info->module_srl, NULL, $logged_info->member_srl, session_id(), TRUE);
             $quantity = (is_numeric(Context::get('quantity')) && Context::get('quantity') > 0 ? Context::get('quantity') : 1);
             try {
                 $cart->addProduct($product, $quantity);
             }
             catch (Exception $e) {
                 return new Object(-1, $e->getMessage());
             }
         }
         else return new Object(-1, 'msg_invalid_request');
     }
     else return new Object(-1, 'msg_invalid_request');
     $shop = $this->model->getShop($this->module_srl);
     $this->setRedirectUrlIfNoReferer(getSiteUrl($shop->domain));
 }
예제 #6
0
	/**
	 * Frontend shop product page
	 */
	public function dispShopProduct()
	{
        /** @var $product Product */
        if ($product = Context::get('product')) {
            //came from from routing
            if (!($product instanceof Product) || !$product->isPersisted()) throw new ShopException('Wrong product');
        }
		else {
            if (!$product_srl = Context::get('product_srl')) throw new ShopException('Could not identify product');
            $product_repository = new ProductRepository();
            $product = $product_repository->getProduct($product_srl);
            if (!$product instanceof Product) throw new ShopException('Product does not exist');
            Context::set('product', $product);
        }

        //add product document if it does not exist  (link to comments)
        if(!isset($product->document_srl)){
            $documentController = getController('document');
            $document = new stdClass();
            $document->title = $product->product_srl;
            $document->commentStatus = 'ALLOW';
            $document->module_srl = $product->module_srl;
            $output = $documentController->insertDocument($document);
            $product->document_srl = $output->variables['document_srl'];
            unset($product->images);
            $product->repo->updateProduct($product);
        }
        $documentModel = getModel('document');
        $product->document = $documentModel->getDocument($product->document_srl);
        $product->comment_list = $_comment_list = $product->document->getComments();
        if (is_array($_comment_list)) {
            foreach ($product->comment_list as $comment){
                $comment->variables['relativeDate'] = $this->model->zdateRelative($comment->getRegdateTime());
            }
        }

		// Setup Javscript datasource for linked dropdowns
		$datasourceJS = $this->getAssociatedProductsAttributesAsJavascriptArray(array($product));
		Context::set('datasourceJS', $datasourceJS);

		// Setup attributes names for display
		if(count($product->attributes))
		{
			$attribute_repository = new AttributeRepository();
			$attributes = $attribute_repository->getAttributes(array_keys($product->attributes));
			Context::set('attributes', $attributes);
		}

		// Categories left tree
		// Retrieve existing categories
		$category_repository = new CategoryRepository();
		$tree = $category_repository->getNavigationCategoriesTree($this->module_srl);

		// Prepare tree for display
		$tree_config = new HtmlCategoryTreeConfig();
		$tree_config->linkCategoryName = TRUE;
		$tree_config->linkGetUrlParams = array('vid', $this->mid, 'act', 'dispShop');
		$tree_config->selected = $product->categories;
		$HTML_tree = $tree->toHTML($tree_config);
		Context::set('HTML_tree', $HTML_tree);

        $this->loadShopCategoryTree();

		$this->setTemplateFile('product.html');
	}
예제 #7
0
	/**
	 * Test inserting product attributes
	 *
	 * Each category has associated a set of attributes
	 * (e.g. All books have the Author attribute, All T-Shirts have Color)
	 * Based on the category a product is in, it can have values for these attributes.
	 *
	 * This test checks that if Color is provided for a product in the Books
	 * category it will not be added.
	 *
	 *
	 * @author Corina Udrescu (dev@xpressengine.org)
	 */
	public function testInsertProductAttributeSkipsAttributesNotInScope()
	{
		$repository = new ProductRepository();
		$product = $repository->getProduct(1);

		$product->attributes[self::ATTRIBUTE_AUTHOR] = "J. K. Rowling";
		$product->attributes[self::ATTRIBUTE_PUBLISH_YEAR] = 2003;
		$product->attributes[self::ATTRIBUTE_COLOR] = "Blue";

		$repository->updateProduct($product);

		$new_product = $repository->getProduct(1);

		$this->assertEquals(2, count($new_product->attributes));

		$this->assertFalse(array_key_exists(self::ATTRIBUTE_COLOR, $new_product->attributes));
		$this->assertEquals("J. K. Rowling", $new_product->attributes[self::ATTRIBUTE_AUTHOR]);
		$this->assertEquals(2003, $new_product->attributes[self::ATTRIBUTE_PUBLISH_YEAR]);
	}
예제 #8
0
 public function productStillAvailable($product, $checkIfInStock = true)
 {
     if ($product instanceof SimpleProduct) {
         if (!$product->isPersisted()) {
             throw new ShopException('Product not persisted');
         }
     } elseif (is_numeric($product)) {
         $pRepo = new ProductRepository();
         $product = $pRepo->getProduct($product);
     } else {
         throw new ShopException('Invalid input');
     }
     return $product && $product->isAvailable($checkIfInStock);
 }