protected function setUp()
 {
     if (CategoryQuery::create()->count() === 0) {
         $category = new Category();
         $category->save();
     }
 }
 /**
  * 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;
 }
Example #3
0
 /**
  * @depends testUpdate
  */
 public function testDelete(CategoryModel $category)
 {
     $event = new CategoryDeleteEvent($category->getId());
     $event->setDispatcher($this->getDispatcher());
     $action = new Category();
     $action->delete($event);
     $deletedCategory = $event->getCategory();
     $this->assertInstanceOf('Thelia\\Model\\Category', $deletedCategory);
     $this->assertTrue($deletedCategory->isDeleted());
 }
 public function generateNoMatchingCart(\PHPUnit_Framework_MockObject_MockObject $stubFacade)
 {
     $category3 = new Category();
     $category3->setId(30);
     $product2 = new Product();
     $product2->addCategory($category3);
     $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
 /**
  * Declares an association between this object and a ChildCategory object.
  *
  * @param                  ChildCategory $v
  * @return                 \Thelia\Model\CategoryVersion The current object (for fluent API support)
  * @throws PropelException
  */
 public function setCategory(ChildCategory $v = null)
 {
     if ($v === null) {
         $this->setId(NULL);
     } else {
         $this->setId($v->getId());
     }
     $this->aCategory = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildCategory object, it will not be re-added.
     if ($v !== null) {
         $v->addCategoryVersion($this);
     }
     return $this;
 }
Example #6
0
 /**
  * Filter the query by a related \Thelia\Model\Category object
  *
  * @param \Thelia\Model\Category|ObjectCollection $category The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildCategoryDocumentQuery The current query, for fluid interface
  */
 public function filterByCategory($category, $comparison = null)
 {
     if ($category instanceof \Thelia\Model\Category) {
         return $this->addUsingAlias(CategoryDocumentTableMap::CATEGORY_ID, $category->getId(), $comparison);
     } elseif ($category instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(CategoryDocumentTableMap::CATEGORY_ID, $category->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByCategory() only accepts arguments of type \\Thelia\\Model\\Category or Collection');
     }
 }
Example #7
0
 /**
  * Exclude object from result
  *
  * @param   ChildCategory $category Object to remove from the list of results
  *
  * @return ChildCategoryQuery The current query, for fluid interface
  */
 public function prune($category = null)
 {
     if ($category) {
         $this->addUsingAlias(CategoryTableMap::ID, $category->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Example #8
0
 public function import($startRecord = 0)
 {
     $count = 0;
     $errors = 0;
     $hdl = $this->t1db->query(sprintf("select * from produit order by rubrique asc limit %d, %d", intval($startRecord), $this->getChunkSize()));
     $image_import = new ProductImageImport($this->dispatcher, $this->t1db);
     $document_import = new ProductDocumentImport($this->dispatcher, $this->t1db);
     while ($hdl && ($produit = $this->t1db->fetch_object($hdl))) {
         $count++;
         // Put contents on the root folder in a special folder
         if ($produit->rubrique == 0) {
             try {
                 $this->cat_corresp->getT2($produit->rubrique);
             } catch (\Exception $ex) {
                 // Create the '0' folder
                 $root = new Category();
                 $root->setParent(0)->setLocale('fr_FR')->setTitle("Rubrique racine Thelia 1")->setLocale('en_US')->setTitle("Thelia 1 root category")->setDescription("")->setChapo("")->setPostscriptum("")->setVisible(true)->save();
                 Tlog::getInstance()->warning("Created pseudo-root category to store products at root level");
                 $this->cat_corresp->addEntry(0, $root->getId());
             }
         }
         $rubrique = $this->cat_corresp->getT2($produit->rubrique);
         if ($rubrique > 0) {
             try {
                 $this->product_corresp->getT2($produit->id);
                 Tlog::getInstance()->warning("Product ID={$produit->id} already imported.");
                 continue;
             } catch (ImportException $ex) {
                 // Okay, the product was not imported.
             }
             try {
                 // Check if the product ref is not already defined, and create a new one if it's the case.
                 $origRef = $destRef = $produit->ref;
                 $refIdx = 1;
                 while (null !== ($dupProd = ProductQuery::create()->findOneByRef($destRef))) {
                     Tlog::getInstance()->warning("Duplicate product reference: '{$destRef}', generating alternate reference.");
                     $destRef = sprintf('%s-%d', $origRef, $refIdx++);
                 }
                 $event = new ProductCreateEvent();
                 $idx = 0;
                 $descs = $this->t1db->query_list("select * from produitdesc where produit = ? order by lang asc", array($produit->id));
                 // Prices should be without axes
                 $produit->prix = round($produit->prix / (1 + $produit->tva / 100), 2);
                 $produit->prix2 = round($produit->prix2 / (1 + $produit->tva / 100), 2);
                 $product_id = 0;
                 foreach ($descs as $objdesc) {
                     $lang = $this->getT2Lang($objdesc->lang);
                     // A title is required to create the rewritten URL
                     if (empty($objdesc->titre)) {
                         $objdesc->titre = sprintf("Untitled-%d-%s", $objdesc->id, $lang->getCode());
                     }
                     if ($idx == 0) {
                         $event->setRef($destRef)->setLocale($lang->getLocale())->setTitle($objdesc->titre)->setDefaultCategory($this->cat_corresp->getT2($produit->rubrique))->setVisible($produit->ligne == 1 ? true : false)->setBasePrice($produit->prix)->setBaseWeight($produit->poids)->setTaxRuleId($this->tax_corresp->getT2(1000 * $produit->tva))->setCurrencyId($this->getT2Currency()->getId());
                         $this->dispatcher->dispatch(TheliaEvents::PRODUCT_CREATE, $event);
                         $product_id = $event->getProduct()->getId();
                         // Set the product template (resets the product default price)
                         // -----------------------------------------------------------
                         try {
                             $pste = new ProductSetTemplateEvent($event->getProduct(), $this->tpl_corresp->getT2($produit->rubrique), $this->getT2Currency()->getId());
                             $this->dispatcher->dispatch(TheliaEvents::PRODUCT_SET_TEMPLATE, $pste);
                         } catch (ImportException $ex) {
                             Tlog::getInstance()->addWarning("No product template was found for product {$product_id}: ", $ex->getMessage());
                         }
                         // Create the default product sale element, and update it
                         // ------------------------------------------------------
                         $create_pse_event = new ProductSaleElementCreateEvent($event->getProduct(), array(), $this->getT2Currency()->getId());
                         $this->dispatcher->dispatch(TheliaEvents::PRODUCT_ADD_PRODUCT_SALE_ELEMENT, $create_pse_event);
                         $update_pse_event = new ProductSaleElementUpdateEvent($event->getProduct(), $create_pse_event->getProductSaleElement()->getId());
                         $update_pse_event->setReference($destRef)->setPrice($produit->prix)->setCurrencyId($this->getT2Currency()->getId())->setWeight($produit->poids)->setQuantity($produit->stock)->setSalePrice($produit->prix2)->setOnsale($produit->promo ? true : false)->setIsnew($produit->nouveaute ? true : false)->setIsdefault(true)->setEanCode('')->setTaxRuleId($this->tax_corresp->getT2(1000 * $produit->tva))->setFromDefaultCurrency(0);
                         $this->dispatcher->dispatch(TheliaEvents::PRODUCT_UPDATE_PRODUCT_SALE_ELEMENT, $update_pse_event);
                         // Update position
                         // ---------------
                         $update_position_event = new UpdatePositionEvent($product_id, UpdatePositionEvent::POSITION_ABSOLUTE, $produit->classement);
                         $this->dispatcher->dispatch(TheliaEvents::PRODUCT_UPDATE_POSITION, $update_position_event);
                         Tlog::getInstance()->info("Created product {$product_id} from {$objdesc->titre} ({$produit->id})");
                         $this->product_corresp->addEntry($produit->id, $product_id);
                         // Import related content
                         // ----------------------
                         $contents = $this->t1db->query_list("select * from contenuassoc where objet=? and type=1 order by classement", array($produit->id));
                         // type: 1 = produit, 0=rubrique
                         foreach ($contents as $content) {
                             try {
                                 $content_event = new ProductAddContentEvent($event->getProduct(), $this->content_corresp->getT2($content->contenu));
                                 $this->dispatcher->dispatch(TheliaEvents::PRODUCT_ADD_CONTENT, $content_event);
                             } catch (\Exception $ex) {
                                 Tlog::getInstance()->addError("Failed to create associated content {$content->contenu} for product {$product_id}: ", $ex->getMessage());
                                 $errors++;
                             }
                         }
                         // Update features (= caracteristiques) values
                         // -------------------------------------------
                         $caracvals = $this->t1db->query_list("select * from caracval where produit=?", array($produit->id));
                         foreach ($caracvals as $caracval) {
                             try {
                                 if (intval($caracval->caracdisp) != 0) {
                                     $feature_value = $this->feat_av_corresp->getT2($caracval->caracdisp);
                                     $is_text = false;
                                 } elseif ($caracval->valeur != '') {
                                     $feature_value = $caracval->valeur;
                                     $is_text = true;
                                 } else {
                                     continue;
                                 }
                                 $feature_value_event = new FeatureProductUpdateEvent($product_id, $this->feat_corresp->getT2($caracval->caracteristique), $feature_value, $is_text);
                                 $this->dispatcher->dispatch(TheliaEvents::PRODUCT_FEATURE_UPDATE_VALUE, $feature_value_event);
                             } catch (\Exception $ex) {
                                 Tlog::getInstance()->addError("Failed to update feature value with caracdisp ID={$caracval->caracdisp} (value='{$caracval->valeur}') for product {$product_id}: ", $ex->getMessage());
                                 $errors++;
                             }
                         }
                         // Update Attributes (= declinaisons) options
                         // ------------------------------------------
                         $rubdecs = $this->t1db->query_list("\n                                                                select\n                                                                    declinaison\n                                                                from\n                                                                    rubdeclinaison rd, declinaison d\n                                                                where\n                                                                    rd.declinaison=d.id\n                                                                and\n                                                                    rd.rubrique=?\n                                                                 order by\n                                                                    d.classement", array($produit->rubrique));
                         foreach ($rubdecs as $rubdec) {
                             $declidisps = $this->t1db->query_list("select id from declidisp where declinaison=?", array($rubdec->declinaison));
                             foreach ($declidisps as $declidisp) {
                                 $disabled = $this->t1db->query_list("select id from exdecprod where declidisp=? and produit=?", array($declidisp->id, $produit->id));
                                 if (count($disabled) > 0) {
                                     continue;
                                 }
                                 $stock = $this->t1db->query_obj("select * from stock where declidisp=?and produit=?", array($declidisp->id, $produit->id));
                                 if ($stock == false) {
                                     continue;
                                 }
                                 try {
                                     $pse_create_event = new ProductSaleElementCreateEvent($event->getProduct(), array($this->attr_av_corresp->getT2($stock->declidisp)), $this->getT2Currency()->getId());
                                     $this->dispatcher->dispatch(TheliaEvents::PRODUCT_ADD_PRODUCT_SALE_ELEMENT, $pse_create_event);
                                     $pse_update_event = new ProductSaleElementUpdateEvent($event->getProduct(), $pse_create_event->getProductSaleElement()->getId());
                                     $pse_update_event->setReference($destRef)->setPrice($produit->prix + $stock->surplus)->setCurrencyId($this->getT2Currency()->getId())->setWeight($produit->poids)->setQuantity($stock->valeur)->setSalePrice($produit->prix2 + $stock->surplus)->setOnsale($produit->promo ? true : false)->setIsnew($produit->nouveaute ? true : false)->setIsdefault(true)->setEanCode('')->setTaxRuleId($this->tax_corresp->getT2(1000 * $produit->tva))->setFromDefaultCurrency(0);
                                     $this->dispatcher->dispatch(TheliaEvents::PRODUCT_UPDATE_PRODUCT_SALE_ELEMENT, $pse_update_event);
                                 } catch (\Exception $ex) {
                                     Tlog::getInstance()->addError("Failed to update product sale element value with declidisp ID={$stock->declidisp} for product {$product_id}: ", $ex->getMessage());
                                     $errors++;
                                 }
                             }
                         }
                         // Import images and documents
                         // ---------------------------
                         $image_import->importMedia($produit->id, $product_id);
                         $document_import->importMedia($produit->id, $product_id);
                     }
                     Tlog::getInstance()->info(sprintf("Updating product ID=%d, data for lang %s.", $product_id, $lang->getCode()));
                     // Update the newly created product
                     $update_event = new ProductUpdateEvent($product_id);
                     $update_event->setRef($destRef)->setLocale($lang->getLocale())->setTitle($objdesc->titre)->setChapo($objdesc->chapo)->setDescription($objdesc->description)->setPostscriptum($objdesc->postscriptum)->setVisible($produit->ligne == 1 ? true : false)->setDefaultCategory($this->cat_corresp->getT2($produit->rubrique));
                     $this->dispatcher->dispatch(TheliaEvents::PRODUCT_UPDATE, $update_event);
                     // Update the rewritten URL, if one was defined
                     $this->updateRewrittenUrl($event->getProduct(), $lang->getLocale(), $objdesc->lang, "produit", "%id_produit={$produit->id}&id_rubrique={$produit->rubrique}%");
                     $idx++;
                 }
             } catch (\Exception $ex) {
                 Tlog::getInstance()->addError("Failed to import product ID={$produit->id}: ", $ex->getMessage());
                 $errors++;
             }
         } else {
             Tlog::getInstance()->addError("Cannot import product ID={$produit->id}, which is at root level (e.g., rubrique parent = 0).");
             $errors++;
         }
     }
     return new ImportChunkResult($count, $errors);
 }
Example #9
0
 /**
  * Create a new category entry
  *
  * @param \Thelia\Core\Event\Category\CategoryCreateEvent $event
  */
 public function create(CategoryCreateEvent $event)
 {
     $category = new CategoryModel();
     $category->setDispatcher($event->getDispatcher())->setLocale($event->getLocale())->setParent($event->getParent())->setVisible($event->getVisible())->setTitle($event->getTitle())->save();
     $event->setCategory($category);
 }
 /**
  * @param Category $object
  * @return int
  */
 protected function getObjectId($object)
 {
     return $object->getId();
 }