Пример #1
0
 public function testNoMatch()
 {
     $stubFacade = $this->generateFacadeStub();
     $coupon = new FreeProduct($stubFacade);
     $date = new \DateTime();
     $coupon->set($stubFacade, 'TEST', 'TEST Coupon', 'This is a test coupon title', 'This is a test coupon description', array('percentage' => 10.0, 'products' => [10, 20], 'offered_product_id' => $this->freeProduct->getId(), 'offered_category_id' => 1), true, true, true, true, 254, $date->setTimestamp(strtotime("today + 3 months")), new ObjectCollection(), new ObjectCollection(), false);
     $this->generateNoMatchingCart($stubFacade);
     $this->assertEquals(0.0, $coupon->exec());
 }
Пример #2
0
 public function loadTaxRule(TaxRule $taxRule, Country $country, Product $product)
 {
     $this->product = null;
     $this->country = null;
     $this->taxRulesCollection = null;
     if ($taxRule->getId() === null) {
         throw new TaxEngineException('TaxRule id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_TAX_RULE);
     }
     if ($country->getId() === null) {
         throw new TaxEngineException('Country id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_COUNTRY);
     }
     if ($product->getId() === null) {
         throw new TaxEngineException('Product id is empty in Calculator::load', TaxEngineException::UNDEFINED_PRODUCT);
     }
     $this->country = $country;
     $this->product = $product;
     $this->taxRulesCollection = $this->taxRuleQuery->getTaxCalculatorCollection($taxRule, $country);
     return $this;
 }
Пример #3
0
 /**
  * Filter the query by a related \Thelia\Model\Product object
  *
  * @param \Thelia\Model\Product|ObjectCollection $product The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildProductVersionQuery The current query, for fluid interface
  */
 public function filterByProduct($product, $comparison = null)
 {
     if ($product instanceof \Thelia\Model\Product) {
         return $this->addUsingAlias(ProductVersionTableMap::ID, $product->getId(), $comparison);
     } elseif ($product instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(ProductVersionTableMap::ID, $product->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByProduct() only accepts arguments of type \\Thelia\\Model\\Product or Collection');
     }
 }
Пример #4
0
 /**
  * Declares an association between this object and a ChildProduct object.
  *
  * @param                  ChildProduct $v
  * @return                 \Thelia\Model\ProductImage The current object (for fluent API support)
  * @throws PropelException
  */
 public function setProduct(ChildProduct $v = null)
 {
     if ($v === null) {
         $this->setProductId(NULL);
     } else {
         $this->setProductId($v->getId());
     }
     $this->aProduct = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildProduct object, it will not be re-added.
     if ($v !== null) {
         $v->addProductImage($this);
     }
     return $this;
 }
Пример #5
0
 /**
  * @param  LoopResultRow         $loopResultRow the current result row
  * @param  \Thelia\Model\Product $product
  * @param $default_category_id
  * @return mixed
  */
 private function associateValues($loopResultRow, $product, $default_category_id)
 {
     $display_initial_price = $product->getVirtualColumn('display_initial_price');
     if (is_null($display_initial_price)) {
         $display_initial_price = 1;
     }
     $loopResultRow->set("ID", $product->getId())->set("REF", $product->getRef())->set("IS_TRANSLATED", $product->getVirtualColumn('IS_TRANSLATED'))->set("LOCALE", $this->locale)->set("TITLE", $product->getVirtualColumn('i18n_TITLE'))->set("CHAPO", $product->getVirtualColumn('i18n_CHAPO'))->set("DESCRIPTION", $product->getVirtualColumn('i18n_DESCRIPTION'))->set("POSTSCRIPTUM", $product->getVirtualColumn('i18n_POSTSCRIPTUM'))->set("URL", $product->getUrl($this->locale))->set("META_TITLE", $product->getVirtualColumn('i18n_META_TITLE'))->set("META_DESCRIPTION", $product->getVirtualColumn('i18n_META_DESCRIPTION'))->set("META_KEYWORDS", $product->getVirtualColumn('i18n_META_KEYWORDS'))->set("POSITION", $product->getPosition())->set("VIRTUAL", $product->getVirtual() ? "1" : "0")->set("VISIBLE", $product->getVisible() ? "1" : "0")->set("TEMPLATE", $product->getTemplateId())->set("DEFAULT_CATEGORY", $default_category_id)->set("TAX_RULE_ID", $product->getTaxRuleId())->set("BRAND_ID", $product->getBrandId() ?: 0)->set("SHOW_ORIGINAL_PRICE", $display_initial_price);
     if ($this->getBackend_context() || $this->getWithPrevNextInfo()) {
         $visible = $this->getWithPrevNextVisible();
         // Find previous and next category
         $previousSearch = ProductQuery::create()->joinProductCategory()->where('ProductCategory.category_id = ?', $default_category_id)->filterByPosition($product->getPosition(), Criteria::LESS_THAN)->orderByPosition(Criteria::DESC);
         if ($visible !== Type\BooleanOrBothType::ANY) {
             $previousSearch->filterByVisible($visible ? 1 : 0);
         }
         $previous = $previousSearch->findOne();
         $nextSearch = ProductQuery::create()->joinProductCategory()->where('ProductCategory.category_id = ?', $default_category_id)->filterByPosition($product->getPosition(), Criteria::GREATER_THAN)->orderByPosition(Criteria::ASC);
         if ($visible !== Type\BooleanOrBothType::ANY) {
             $nextSearch->filterByVisible($visible ? 1 : 0);
         }
         $next = $nextSearch->findOne();
         $loopResultRow->set("HAS_PREVIOUS", $previous != null ? 1 : 0)->set("HAS_NEXT", $next != null ? 1 : 0)->set("PREVIOUS", $previous != null ? $previous->getId() : -1)->set("NEXT", $next != null ? $next->getId() : -1);
     }
     return $loopResultRow;
 }
Пример #6
0
 /**
  * @param  Product $object
  * @return mixed
  */
 protected function getObjectId($object)
 {
     return $object->getId();
 }
Пример #7
0
 /**
  * @depends testSetProductTemplate
  */
 public function testDelete(ProductModel $product)
 {
     $event = new ProductDeleteEvent($product->getId());
     $event->setDispatcher($this->getDispatcher());
     $action = new Product();
     $action->delete($event);
     $deletedProduct = $event->getProduct();
     $this->assertInstanceOf('Thelia\\Model\\Product', $deletedProduct, 'deleted product must be an instance of Thelia\\Model\\Product');
     $this->assertTrue($deletedProduct->isDeleted());
 }
Пример #8
0
 /**
  * Exclude object from result
  *
  * @param   ChildProduct $product Object to remove from the list of results
  *
  * @return ChildProductQuery The current query, for fluid interface
  */
 public function prune($product = null)
 {
     if ($product) {
         $this->addUsingAlias(ProductTableMap::ID, $product->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Пример #9
0
 /**
  * @param LoopResultRow $loopResultRow
  * @param ProductModel $product
  * @param int $defaultCategoryId
  */
 private function findNextPrev(LoopResultRow $loopResultRow, ProductModel $product, $defaultCategoryId)
 {
     if ($this->getWithPrevNextInfo()) {
         $currentPosition = ProductCategoryQuery::create()->filterByCategoryId($defaultCategoryId)->filterByProductId($product->getId())->findOne()->getPosition();
         // Find previous and next product
         $previousQuery = ProductCategoryQuery::create()->filterByCategoryId($defaultCategoryId)->filterByPosition($currentPosition, Criteria::LESS_THAN);
         $nextQuery = ProductCategoryQuery::create()->filterByCategoryId($defaultCategoryId)->filterByPosition($currentPosition, Criteria::GREATER_THAN);
         if (!$this->getBackendContext()) {
             $previousQuery->useProductQuery()->filterByVisible(true)->endUse();
             $previousQuery->useProductQuery()->filterByVisible(true)->endUse();
         }
         $previous = $previousQuery->orderByPosition(Criteria::DESC)->findOne();
         $next = $nextQuery->orderByPosition(Criteria::ASC)->findOne();
         $loopResultRow->set("HAS_PREVIOUS", $previous != null ? 1 : 0)->set("HAS_NEXT", $next != null ? 1 : 0)->set("PREVIOUS", $previous != null ? $previous->getProductId() : -1)->set("NEXT", $next != null ? $next->getProductId() : -1);
     }
 }
Пример #10
0
 /**
  * Set the cart item id which contains the free product related to a given product
  *
  * @param Product  $product    the product in the cart which triggered the discount
  * @param bool|int $cartItemId the cart item ID which contains the free product, or just true if the free product is not yet added.
  */
 protected function setRelatedCartItem($product, $cartItemId)
 {
     $cartItemIdList = $this->facade->getRequest()->getSession()->get($this->getSessionVarName(), array());
     if (!is_array($cartItemIdList)) {
         $cartItemIdList = array();
     }
     $cartItemIdList[$product->getId()] = $cartItemId;
     $this->facade->getRequest()->getSession()->set($this->getSessionVarName(), $cartItemIdList);
 }
 public static function deleteProduct(Product $product)
 {
     /************************************
      * Get name of index and handler to work with OSS API
      ************************************/
     $index = OpensearchserverConfigQuery::read('index_name');
     $oss_api = OpenSearchServerSearchHelper::getHandler();
     //delete every versions of this product (all locales)
     $request = new \OpenSearchServer\Document\Delete();
     $request->index($index)->field('id')->value($product->getId());
     $response = $oss_api->submit($request);
     return $response->isSuccess();
 }