protected function getTestFeaturedProduct() { $fProduct = new XLite\Module\CDev\FeaturedProducts\Model\FeaturedProduct(); $fProduct->setProduct($this->getProduct()); $fProduct->setCategory($this->getCategory()); $fProduct->setOrderBy(5); \XLite\Core\Database::getEM()->persist($fProduct); \XLite\Core\Database::getEM()->flush(); $this->assertNotNull($fProduct, 'getTestFeaturedProduct() returned null, object expected'); $this->featuredProduct = $fProduct; return $fProduct; }
protected function getTestFeaturedProduct() { $fProduct = new XLite\Module\CDev\FeaturedProducts\Model\FeaturedProduct(); $fProduct->setProduct($this->getProduct()); $fProduct->setCategory($this->getCategory()); $fProduct->setOrderBy(5); \XLite\Core\Database::getEM()->persist($fProduct); \XLite\Core\Database::getEM()->flush(); $this->fp = $fProduct; return $fProduct; }
/** * doActionAddFeaturedProducts * * @return void */ protected function doActionAddFeaturedProducts() { if (isset(\XLite\Core\Request::getInstance()->product_ids)) { $pids = array_keys(\XLite\Core\Request::getInstance()->product_ids); $products = \XLite\Core\Database::getRepo('\\XLite\\Model\\Product')->findByIds($pids); if (!$this->categoryId) { $this->categoryId = \XLite\Core\Database::getRepo('\\XLite\\Model\\Category')->getRootCategoryId(); } $category = \XLite\Core\Database::getRepo('\\XLite\\Model\\Category')->find($this->categoryId); // Retreive existing featured products list of that category $this->category_id = $this->categoryId; $existingLinksIds = array(); $existingLinks = $this->getFeaturedProductsList(); if ($existingLinks) { foreach ($existingLinks as $k => $v) { $existingLinksIds[] = $v->getProduct()->getProductId(); } } if ($products) { foreach ($products as $product) { if (in_array($product->getProductId(), $existingLinksIds)) { \XLite\Core\TopMessage::addWarning('The product SKU#"' . $product->getSku() . '" is already set as featured for the category'); } else { $fp = new \XLite\Module\CDev\FeaturedProducts\Model\FeaturedProduct(); $fp->setProduct($product); if ($category) { $fp->setCategory($category); } \XLite\Core\Database::getEM()->persist($fp); } } } \XLite\Core\Database::getEM()->flush(); } }
/** * doActionAddFeaturedProducts * * @return void */ protected function doActionAdd() { if (isset(\XLite\Core\Request::getInstance()->select)) { $pids = \XLite\Core\Request::getInstance()->select; $products = \XLite\Core\Database::getRepo('\\XLite\\Model\\Product')->findByIds($pids); $this->id = \XLite\Core\Request::getInstance()->id ?: $this->getRootCategoryId(); $category = \XLite\Core\Database::getRepo('\\XLite\\Model\\Category')->find($this->id); $existingLinksIds = array(); $existingLinks = $this->getFeaturedProductsList(); if ($existingLinks) { foreach ($existingLinks as $k => $v) { $existingLinksIds[] = $v->getProduct()->getProductId(); } } if ($products) { foreach ($products as $product) { if (in_array($product->getProductId(), $existingLinksIds)) { \XLite\Core\TopMessage::addWarning('The product SKU#"X" is already set as featured for the category', array('SKU' => $product->getSku())); } else { $fp = new \XLite\Module\CDev\FeaturedProducts\Model\FeaturedProduct(); $fp->setProduct($product); if ($category) { $fp->setCategory($category); } \XLite\Core\Database::getEM()->persist($fp); } } } \XLite\Core\Database::getEM()->flush(); } $this->setReturnURL($this->buildURL('featured_products', '', \XLite\Core\Request::getInstance()->id ? array('id' => $this->id) : array())); }