Example #1
0
 /**
  * Returns a new ChildMetaDataQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildMetaDataQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof \Thelia\Model\MetaDataQuery) {
         return $criteria;
     }
     $query = new \Thelia\Model\MetaDataQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Example #2
0
 public function delete(MetaDataDeleteEvent $event)
 {
     $metaData = MetaDataQuery::create()->filterByMetaKey($event->getMetaKey())->filterByElementKey($event->getElementKey())->filterByElementId($event->getElementId())->findOne();
     $event->setMetaData($metaData);
     if (null !== $metaData) {
         $metaData->delete();
     }
 }
Example #3
0
 public function handleOrder(VirtualProductOrderHandleEvent $event)
 {
     $documentId = MetaDataQuery::getVal('virtual', MetaDataModel::PSE_KEY, $event->getPseId());
     if (null !== $documentId) {
         $productDocument = ProductDocumentQuery::create()->findPk($documentId);
         if (null !== $productDocument) {
             $event->setPath($productDocument->getFile());
         }
     }
 }
 /**
  * Retrieve meta data associated to an element
  *
  * params should contain at least key an id attributes. Thus it will return
  * an array of associated data.
  *
  * If meta argument is specified then it will return an unique value.
  *
  * @param array $params
  * @param \Smarty $smarty
  *
  * @throws \InvalidArgumentException
  *
  * @return string|array|null
  */
 public function metaAccess($params, $smarty)
 {
     $meta = $this->getParam($params, 'meta', null);
     $key = $this->getParam($params, 'key', null);
     $id = $this->getParam($params, 'id', null);
     $cacheKey = sprintf('meta_%s_%s_%s', $meta, $key, $id);
     $out = null;
     if (array_key_exists($cacheKey, self::$dataAccessCache)) {
         return self::$dataAccessCache[$cacheKey];
     }
     if ($key !== null && $id !== null) {
         if ($meta === null) {
             $out = MetaDataQuery::getAllVal($key, (int) $id);
         } else {
             $out = MetaDataQuery::getVal($meta, $key, (int) $id);
         }
     } else {
         throw new \InvalidArgumentException("key and id arguments are required in meta access function");
     }
     self::$dataAccessCache[$cacheKey] = $out;
     if (!empty($params['out'])) {
         $smarty->assign($params['out'], $out);
         return $out !== null ? true : false;
     } else {
         if (is_array($out)) {
             throw new \InvalidArgumentException('The argument "out" is required if the meta value is an array');
         }
         return $out;
     }
 }
Example #5
0
 /**
  * Retrieve meta data associated to an element
  *
  * params should contain at least key an id attributes. Thus it will return
  * an array of associated datas.
  *
  * If meta argument is specified then it will return an unique value.
  *
  * @param $params
  * @param $smarty
  *
  * @throws \InvalidArgumentException
  *
  * @return string|array|null
  */
 public function metaAccess($params, $smarty)
 {
     $meta = $this->getParam($params, 'meta', null);
     $key = $this->getParam($params, 'key', null);
     $id = $this->getParam($params, 'id', null);
     $cacheKey = sprintf('meta_%s_%s_%s', $meta, $key, $id);
     $out = null;
     if (array_key_exists($cacheKey, self::$dataAccessCache)) {
         return self::$dataAccessCache[$cacheKey];
     }
     if ($key !== null && $id !== null) {
         if ($meta === null) {
             $out = MetaDataQuery::getAllVal($key, (int) $id);
         } else {
             $out = MetaDataQuery::getVal($meta, $key, (int) $id);
         }
     } else {
         throw new \InvalidArgumentException("key and id attributes are required in meta access function");
     }
     self::$dataAccessCache[$cacheKey] = $out;
     return $out;
 }
Example #6
0
 /**
  * Performs an INSERT on the database, given a MetaData or Criteria object.
  *
  * @param mixed               $criteria Criteria or MetaData object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(MetaDataTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from MetaData object
     }
     if ($criteria->containsKey(MetaDataTableMap::ID) && $criteria->keyContainsValue(MetaDataTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . MetaDataTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = MetaDataQuery::create()->mergeWith($criteria);
     try {
         // use transaction because $criteria could contain info
         // for more than one table (I guess, conceivably)
         $con->beginTransaction();
         $pk = $query->doInsert($con);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
     return $pk;
 }
Example #7
0
 /**
  * @params Product $product
  *
  * @depends testUpdate
  */
 public function testDelete(Product $product)
 {
     $metaData = MetaDataQuery::create()->filterByMetaKey('test')->filterByElementKey(get_class($product))->filterByElementId($product->getId())->findOne();
     $this->assertNotNull($metaData);
     $event = new MetaDataDeleteEvent('test', get_class($product), $product->getId());
     $event->setDispatcher($this->dispatcher);
     $action = new MetaData();
     $action->delete($event);
     $deleted = $event->getMetaData();
     $this->assertInstanceOf('Thelia\\Model\\MetaData', $deleted);
     $this->assertTrue($deleted->isDeleted());
 }
Example #8
0
 Model\BrandI18nQuery::create()->deleteAll();
 Model\ProductImageQuery::create()->deleteAll();
 Model\CategoryImageQuery::create()->deleteAll();
 Model\FolderImageQuery::create()->deleteAll();
 Model\ContentImageQuery::create()->deleteAll();
 Model\BrandImageQuery::create()->deleteAll();
 Model\ProductDocumentQuery::create()->deleteAll();
 Model\CategoryDocumentQuery::create()->deleteAll();
 Model\FolderDocumentQuery::create()->deleteAll();
 Model\ContentDocumentQuery::create()->deleteAll();
 Model\BrandDocumentQuery::create()->deleteAll();
 Model\CouponQuery::create()->deleteAll();
 Model\OrderQuery::create()->deleteAll();
 Model\SaleQuery::create()->deleteAll();
 Model\SaleProductQuery::create()->deleteAll();
 Model\MetaDataQuery::create()->deleteAll();
 $stmt = $con->prepare("SET foreign_key_checks = 1");
 $stmt->execute();
 echo "Creating customers\n";
 //API
 $api = new Thelia\Model\Api();
 $api->setProfileId(null)->setApiKey('79E95BD784CADA0C9A578282E')->setLabel("test")->save();
 //customer
 $customer = new Thelia\Model\Customer();
 $customer->createOrUpdate(1, "thelia", "thelia", "5 rue rochon", "", "", "0102030405", "0601020304", "63000", "clermont-ferrand", 64, "*****@*****.**", "azerty");
 for ($j = 0; $j <= 3; $j++) {
     $address = new Thelia\Model\Address();
     $address->setLabel(getRealText(20))->setTitleId(rand(1, 3))->setFirstname($faker->firstname)->setLastname($faker->lastname)->setAddress1($faker->streetAddress)->setAddress2($faker->streetAddress)->setAddress3($faker->streetAddress)->setCellphone($faker->phoneNumber)->setPhone($faker->phoneNumber)->setZipcode($faker->postcode)->setCity($faker->city)->setCountryId(64)->setCustomer($customer)->save();
 }
 for ($i = 0; $i < 3; $i++) {
     $admin = new Thelia\Model\Admin();
Example #9
0
 protected function getPSEVirtualDocument(ProductSaleElementsModel $pse)
 {
     /**
      * Compute documents with the associated loop
      */
     $documentLoop = new Document($this->container);
     // select only not visible documents
     $documentLoop->initializeArgs(["product" => $pse->getProductId(), "visible" => 0]);
     $documents = $documentLoop->exec($documentPagination);
     $documentId = intval(MetaDataQuery::getVal("virtual", "pse", $pse->getId()));
     $data = [];
     /** @var \Thelia\Core\Template\Element\LoopResultRow $document */
     for ($documents->rewind(); $documents->valid(); $documents->next()) {
         $document = $documents->current();
         $data[] = ["id" => $document->get("ID"), "url" => $document->get("DOCUMENT_URL"), "title" => $document->get("TITLE"), "is_associated" => $documentId === $document->get("ID"), "filename" => $document->model->getFile()];
     }
     return $data;
 }
Example #10
0
 $brand->delete();
 \Thelia\Model\ProductImageQuery::create()->find()->delete();
 \Thelia\Model\CategoryImageQuery::create()->find()->delete();
 \Thelia\Model\FolderImageQuery::create()->find()->delete();
 \Thelia\Model\ContentImageQuery::create()->find()->delete();
 \Thelia\Model\BrandImageQuery::create()->find()->delete();
 \Thelia\Model\ProductDocumentQuery::create()->find()->delete();
 \Thelia\Model\CategoryDocumentQuery::create()->find()->delete();
 \Thelia\Model\FolderDocumentQuery::create()->find()->delete();
 \Thelia\Model\ContentDocumentQuery::create()->find()->delete();
 \Thelia\Model\BrandDocumentQuery::create()->find()->delete();
 \Thelia\Model\CouponQuery::create()->find()->delete();
 \Thelia\Model\OrderQuery::create()->find()->delete();
 \Thelia\Model\SaleQuery::create()->find()->delete();
 \Thelia\Model\SaleProductQuery::create()->find()->delete();
 \Thelia\Model\MetaDataQuery::create()->find()->delete();
 $stmt = $con->prepare("SET foreign_key_checks = 1");
 $stmt->execute();
 echo "Creating customers\n";
 //API
 $api = new Thelia\Model\Api();
 $api->setProfileId(null)->setApiKey('79E95BD784CADA0C9A578282E')->setLabel("test")->save();
 //customer
 $customer = new Thelia\Model\Customer();
 $customer->createOrUpdate(1, "thelia", "thelia", "5 rue rochon", "", "", "0102030405", "0601020304", "63000", "clermont-ferrand", 64, "*****@*****.**", "azerty");
 for ($j = 0; $j <= 3; $j++) {
     $address = new Thelia\Model\Address();
     $address->setLabel(getRealText(20))->setTitleId(rand(1, 3))->setFirstname($faker->firstname)->setLastname($faker->lastname)->setAddress1($faker->streetAddress)->setAddress2($faker->streetAddress)->setAddress3($faker->streetAddress)->setCellphone($faker->phoneNumber)->setPhone($faker->phoneNumber)->setZipcode($faker->postcode)->setCity($faker->city)->setCountryId(64)->setCustomer($customer)->save();
 }
 for ($i = 0; $i < 3; $i++) {
     $admin = new Thelia\Model\Admin();
Example #11
0
 protected function createOrder(EventDispatcherInterface $dispatcher, ModelOrder $sessionOrder, CurrencyModel $currency, LangModel $lang, CartModel $cart, CustomerModel $customer)
 {
     $con = \Propel\Runtime\Propel::getConnection(OrderTableMap::DATABASE_NAME);
     $con->beginTransaction();
     $placedOrder = $sessionOrder->copy();
     $placedOrder->setDispatcher($dispatcher);
     $deliveryAddress = AddressQuery::create()->findPk($sessionOrder->getChoosenDeliveryAddress());
     $taxCountry = $deliveryAddress->getCountry();
     $invoiceAddress = AddressQuery::create()->findPk($sessionOrder->getChoosenInvoiceAddress());
     $cartItems = $cart->getCartItems();
     /* fulfill order */
     $placedOrder->setCustomerId($customer->getId());
     $placedOrder->setCurrencyId($currency->getId());
     $placedOrder->setCurrencyRate($currency->getRate());
     $placedOrder->setLangId($lang->getId());
     /* hard save the delivery and invoice addresses */
     $deliveryOrderAddress = new OrderAddress();
     $deliveryOrderAddress->setCustomerTitleId($deliveryAddress->getTitleId())->setCompany($deliveryAddress->getCompany())->setFirstname($deliveryAddress->getFirstname())->setLastname($deliveryAddress->getLastname())->setAddress1($deliveryAddress->getAddress1())->setAddress2($deliveryAddress->getAddress2())->setAddress3($deliveryAddress->getAddress3())->setZipcode($deliveryAddress->getZipcode())->setCity($deliveryAddress->getCity())->setPhone($deliveryAddress->getPhone())->setCountryId($deliveryAddress->getCountryId())->save($con);
     $invoiceOrderAddress = new OrderAddress();
     $invoiceOrderAddress->setCustomerTitleId($invoiceAddress->getTitleId())->setCompany($invoiceAddress->getCompany())->setFirstname($invoiceAddress->getFirstname())->setLastname($invoiceAddress->getLastname())->setAddress1($invoiceAddress->getAddress1())->setAddress2($invoiceAddress->getAddress2())->setAddress3($invoiceAddress->getAddress3())->setZipcode($invoiceAddress->getZipcode())->setCity($invoiceAddress->getCity())->setPhone($invoiceAddress->getPhone())->setCountryId($invoiceAddress->getCountryId())->save($con);
     $placedOrder->setDeliveryOrderAddressId($deliveryOrderAddress->getId());
     $placedOrder->setInvoiceOrderAddressId($invoiceOrderAddress->getId());
     $placedOrder->setStatusId(OrderStatusQuery::getNotPaidStatus()->getId());
     $placedOrder->setCart($cart);
     /* memorize discount */
     $placedOrder->setDiscount($cart->getDiscount());
     $placedOrder->save($con);
     /* fulfill order_products and decrease stock */
     foreach ($cartItems as $cartItem) {
         $product = $cartItem->getProduct();
         /* get translation */
         $productI18n = I18n::forceI18nRetrieving($lang->getLocale(), 'Product', $product->getId());
         $pse = $cartItem->getProductSaleElements();
         /* check still in stock */
         if ($cartItem->getQuantity() > $pse->getQuantity() && true === ConfigQuery::checkAvailableStock() && 0 === $product->getVirtual()) {
             throw new TheliaProcessException("Not enough stock", TheliaProcessException::CART_ITEM_NOT_ENOUGH_STOCK, $cartItem);
         }
         if (0 === $product->getVirtual()) {
             /* decrease stock for non virtual product */
             $allowNegativeStock = intval(ConfigQuery::read('allow_negative_stock', 0));
             $newStock = $pse->getQuantity() - $cartItem->getQuantity();
             //Forbid negative stock
             if ($newStock < 0 && 0 === $allowNegativeStock) {
                 $newStock = 0;
             }
             $pse->setQuantity($newStock);
             $pse->save($con);
         }
         /* get tax */
         $taxRuleI18n = I18n::forceI18nRetrieving($lang->getLocale(), 'TaxRule', $product->getTaxRuleId());
         $taxDetail = $product->getTaxRule()->getTaxDetail($product, $taxCountry, $cartItem->getPrice(), $cartItem->getPromoPrice(), $lang->getLocale());
         // get the virtual document path
         $virtualDocumentPath = null;
         if ($product->getVirtual() === 1) {
             // try to find the associated document
             if (null !== ($documentId = MetaDataQuery::getVal('virtual', MetaDataModel::PSE_KEY, $pse->getId()))) {
                 $productDocument = ProductDocumentQuery::create()->findPk($documentId);
                 if (null !== $productDocument) {
                     $virtualDocumentPath = $productDocument->getFile();
                 }
             }
         }
         $orderProduct = new OrderProduct();
         $orderProduct->setOrderId($placedOrder->getId())->setProductRef($product->getRef())->setProductSaleElementsRef($pse->getRef())->setProductSaleElementsId($pse->getId())->setTitle($productI18n->getTitle())->setChapo($productI18n->getChapo())->setDescription($productI18n->getDescription())->setPostscriptum($productI18n->getPostscriptum())->setVirtual($product->getVirtual())->setVirtualDocument($virtualDocumentPath)->setQuantity($cartItem->getQuantity())->setPrice($cartItem->getPrice())->setPromoPrice($cartItem->getPromoPrice())->setWasNew($pse->getNewness())->setWasInPromo($cartItem->getPromo())->setWeight($pse->getWeight())->setTaxRuleTitle($taxRuleI18n->getTitle())->setTaxRuleDescription($taxRuleI18n->getDescription())->setEanCode($pse->getEanCode())->setCartIemId($cartItem->getId())->setDispatcher($dispatcher)->save($con);
         /* fulfill order_product_tax */
         foreach ($taxDetail as $tax) {
             $tax->setOrderProductId($orderProduct->getId());
             $tax->save($con);
         }
         /* fulfill order_attribute_combination and decrease stock */
         foreach ($pse->getAttributeCombinations() as $attributeCombination) {
             $attribute = I18n::forceI18nRetrieving($lang->getLocale(), 'Attribute', $attributeCombination->getAttributeId());
             $attributeAv = I18n::forceI18nRetrieving($lang->getLocale(), 'AttributeAv', $attributeCombination->getAttributeAvId());
             $orderAttributeCombination = new OrderProductAttributeCombination();
             $orderAttributeCombination->setOrderProductId($orderProduct->getId())->setAttributeTitle($attribute->getTitle())->setAttributeChapo($attribute->getChapo())->setAttributeDescription($attribute->getDescription())->setAttributePostscriptum($attribute->getPostscriptum())->setAttributeAvTitle($attributeAv->getTitle())->setAttributeAvChapo($attributeAv->getChapo())->setAttributeAvDescription($attributeAv->getDescription())->setAttributeAvPostscriptum($attributeAv->getPostscriptum())->save($con);
         }
     }
     $con->commit();
     return $placedOrder;
 }
Example #12
0
 public static function setExtraOrderData($id, $data, $isCart = true)
 {
     if ($isCart) {
         MetaDataQuery::setVal(self::METADATA_KEY_ORDER, self::METADATA_CART_KEY, $id, $data);
     } else {
         MetaDataQuery::setVal(self::METADATA_KEY_ORDER, MetaData::ORDER_KEY, $id, $data);
     }
 }
Example #13
0
 public function activationAction($ref, $refId)
 {
     if (null !== ($response = $this->checkAuth([], ['comment'], AccessManager::UPDATE))) {
         return $response;
     }
     $message = ["success" => false];
     $status = $this->getRequest()->request->get('status');
     switch ($status) {
         case "0":
         case "1":
             MetaDataQuery::setVal(\Comment\Model\Comment::META_KEY_ACTIVATED, $ref, $refId, $status);
             $message['success'] = true;
             break;
         case "-1":
             $deleted = MetaDataQuery::create()->filterByMetaKey(\Comment\Model\Comment::META_KEY_ACTIVATED)->filterByElementKey($ref)->filterByElementId($refId)->delete();
             if ($deleted === 1) {
                 $message['success'] = true;
             }
             break;
     }
     $message['status'] = MetaDataQuery::getVal(\Comment\Model\Comment::META_KEY_ACTIVATED, $ref, $refId, "-1");
     return $this->jsonResponse(json_encode($message));
 }
Example #14
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see MetaData::setDeleted()
  * @see MetaData::isDeleted()
  */
 public function delete(ConnectionInterface $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getServiceContainer()->getWriteConnection(MetaDataTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildMetaDataQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Example #15
0
 public function getContentDefinition(CommentDefinitionEvent $event)
 {
     $config = $event->getConfig();
     $event->setVerified(true);
     $event->setRating(false);
     // is comment is authorized on this product
     $commentProductActivated = MetaDataQuery::getVal(Comment::META_KEY_ACTIVATED, \Thelia\Model\MetaData::CONTENT_KEY, $event->getRefId());
     // not defined, get the global config
     if ("1" !== $commentProductActivated) {
         if ("0" === $commentProductActivated || false === $config['activated']) {
             throw new InvalidDefinitionException($this->translator->trans("Comment not activated on this element.", ['%ref' => $event->getRef()], CommentModule::MESSAGE_DOMAIN));
         }
     }
 }