/**
  * Generate adapter stub
  *
  * @param int    $cartTotalPrice   Cart total price
  * @param string $checkoutCurrency Checkout currency
  * @param string $i18nOutput       Output from each translation
  *
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
 {
     $stubFacade = $this->getMockBuilder('\\Thelia\\Coupon\\BaseFacade')->disableOriginalConstructor()->getMock();
     $stubFacade->expects($this->any())->method('getCartTotalPrice')->will($this->returnValue($cartTotalPrice));
     $stubFacade->expects($this->any())->method('getCheckoutCurrency')->will($this->returnValue($checkoutCurrency));
     $stubFacade->expects($this->any())->method('getConditionEvaluator')->will($this->returnValue(new ConditionEvaluator()));
     $stubTranslator = $this->getMockBuilder('\\Thelia\\Core\\Translation\\Translator')->disableOriginalConstructor()->getMock();
     $stubTranslator->expects($this->any())->method('trans')->will($this->returnValue($i18nOutput));
     $stubFacade->expects($this->any())->method('getTranslator')->will($this->returnValue($stubTranslator));
     $category1 = new Category();
     $category1->setId(10);
     $category2 = new Category();
     $category2->setId(20);
     $category3 = new Category();
     $category3->setId(30);
     $product1 = new Product();
     $product1->setId(10)->addCategory($category1)->addCategory($category2);
     $product2 = new Product();
     $product2->setId(20)->addCategory($category3);
     $cartItem1Stub = $this->getMockBuilder('\\Thelia\\Model\\CartItem')->disableOriginalConstructor()->getMock();
     $cartItem1Stub->expects($this->any())->method('getProduct')->will($this->returnValue($product1));
     $cartItem1Stub->expects($this->any())->method('getQuantity')->will($this->returnValue(1));
     $cartItem2Stub = $this->getMockBuilder('\\Thelia\\Model\\CartItem')->disableOriginalConstructor()->getMock();
     $cartItem2Stub->expects($this->any())->method('getProduct')->will($this->returnValue($product2));
     $cartItem2Stub->expects($this->any())->method('getQuantity')->will($this->returnValue(2));
     $cartStub = $this->getMockBuilder('\\Thelia\\Model\\Cart')->disableOriginalConstructor()->getMock();
     $cartStub->expects($this->any())->method('getCartItems')->will($this->returnValue([$cartItem1Stub, $cartItem2Stub]));
     $stubFacade->expects($this->any())->method('getCart')->will($this->returnValue($cartStub));
     return $stubFacade;
 }
 protected function checkEan(Product $product, $colorAttributeId, $sizeAttributeId)
 {
     $isCombination = false;
     $defaultPse = $product->getDefaultSaleElements();
     $combinationAttribute = $colorAttributeId . ',' . $sizeAttributeId;
     if (null !== $combinationAttribute) {
         $combination = AttributeAvQuery::create()->useAttributeCombinationQuery()->filterByAttributeId(explode(',', $combinationAttribute), Criteria::IN)->filterByProductSaleElementsId($defaultPse->getId())->endUse()->findOne();
         if (null !== $combination) {
             $isCombination = true;
         }
     }
     if (false === $isCombination) {
         if (null === $defaultPse->getEanCode()) {
             return false;
         }
     } else {
         $productSaleElementss = $product->getProductSaleElementss();
         foreach ($productSaleElementss as $productSaleElements) {
             if (null === $productSaleElements->getEanCode()) {
                 return false;
             }
         }
     }
     return true;
 }
 public function productHasQuantity(Product $product)
 {
     /** @var ProductSaleElements $productSaleElements */
     foreach ($product->getProductSaleElementss() as $productSaleElements) {
         if ($productSaleElements->getQuantity() > 0) {
             return true;
         }
         return false;
     }
 }
 public function generateNoMatchingCart(\PHPUnit_Framework_MockObject_MockObject $stubFacade)
 {
     $product2 = new Product();
     $product2->setId(30);
     $cartItem2Stub = $this->getMockBuilder('\\Thelia\\Model\\CartItem')->disableOriginalConstructor()->getMock();
     $cartItem2Stub->expects($this->any())->method('getProduct')->will($this->returnValue($product2));
     $cartItem2Stub->expects($this->any())->method('getQuantity')->will($this->returnValue(2));
     $cartStub = $this->getMockBuilder('\\Thelia\\Model\\Cart')->disableOriginalConstructor()->getMock();
     $cartStub->expects($this->any())->method('getCartItems')->will($this->returnValue([$cartItem2Stub]));
     $stubFacade->expects($this->any())->method('getCart')->will($this->returnValue($cartStub));
 }
Example #5
0
 /**
  * Create a new product entry
  *
  * @param \Thelia\Core\Event\Product\ProductCreateEvent $event
  */
 public function create(ProductCreateEvent $event)
 {
     $product = new ProductModel();
     $product->setDispatcher($event->getDispatcher())->setRef($event->getRef())->setLocale($event->getLocale())->setTitle($event->getTitle())->setVisible($event->getVisible() ? 1 : 0)->setVirtual($event->getVirtual() ? 1 : 0)->setTaxRule(TaxRuleQuery::create()->findOneByIsDefault(true))->create($event->getDefaultCategory(), $event->getBasePrice(), $event->getCurrencyId(), $event->getTaxRuleId(), $event->getBaseWeight());
     // Set the product template, if one is defined in the category tree
     $parentCatId = $event->getDefaultCategory();
     while ($parentCatId > 0) {
         if (null === ($cat = CategoryQuery::create()->findPk($parentCatId))) {
             break;
         }
         if ($cat->getDefaultTemplateId()) {
             $product->setTemplateId($cat->getDefaultTemplateId())->save();
             break;
         }
         $parentCatId = $cat->getParent();
     }
     $event->setProduct($product);
 }
Example #6
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;
 }
 /**
  * @return mixed an instance of Product, Folder, Content or Category Model
  */
 public function getObject()
 {
     $product = new Product();
     $product->setRef(uniqid());
     return $product;
 }
Example #8
0
 /**
  * @param  Product $object
  * @return mixed
  */
 protected function getObjectId($object)
 {
     return $object->getId();
 }
Example #9
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());
 }
Example #10
0
 /**
  * Create a new product entry
  *
  * @param \Thelia\Core\Event\Product\ProductCreateEvent $event
  */
 public function create(ProductCreateEvent $event)
 {
     $product = new ProductModel();
     $product->setDispatcher($event->getDispatcher())->setRef($event->getRef())->setLocale($event->getLocale())->setTitle($event->getTitle())->setVisible($event->getVisible() ? 1 : 0)->setVirtual($event->getVirtual() ? 1 : 0)->setTaxRule(TaxRuleQuery::create()->findOneByIsDefault(true))->create($event->getDefaultCategory(), $event->getBasePrice(), $event->getCurrencyId(), $event->getTaxRuleId(), $event->getBaseWeight());
     $event->setProduct($product);
 }
Example #11
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;
 }
Example #12
0
 /**
  * Tears down the fixture, for example, closes a network connection.
  * This method is called after a test is executed.
  */
 protected function tearDown()
 {
     $this->freeProduct->getDefaultSaleElements()->setPromo($this->originalPromo)->save();
 }
Example #13
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();
 }
Example #15
0
 /**
  * Filter the query by a related \Thelia\Model\Product object
  *
  * @param \Thelia\Model\Product|ObjectCollection $product  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildTemplateQuery The current query, for fluid interface
  */
 public function filterByProduct($product, $comparison = null)
 {
     if ($product instanceof \Thelia\Model\Product) {
         return $this->addUsingAlias(TemplateTableMap::ID, $product->getTemplateId(), $comparison);
     } elseif ($product instanceof ObjectCollection) {
         return $this->useProductQuery()->filterByPrimaryKeys($product->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByProduct() only accepts arguments of type \\Thelia\\Model\\Product or Collection');
     }
 }
Example #16
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;
 }
Example #17
0
 /**
  * Get the default category id for a product
  *
  * @param \Thelia\Model\Product $product
  * @return null|int
  */
 protected function getDefaultCategoryId($product)
 {
     $defaultCategoryId = null;
     if ((bool) $product->getVirtualColumn('is_default_category')) {
         $defaultCategoryId = $product->getVirtualColumn('default_category_id');
     } else {
         $defaultCategoryId = $product->getDefaultCategoryId();
     }
     return $defaultCategoryId;
 }
Example #18
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');
     }
 }
Example #19
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;
 }