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; } }
/** * 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; }
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; }
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; }
public static function getExtraOrderData($id, $isCart = true) { if ($isCart) { $data = MetaDataQuery::getVal(self::METADATA_KEY_ORDER, self::METADATA_CART_KEY, $id, []); } else { $data = MetaDataQuery::getVal(self::METADATA_KEY_ORDER, MetaData::ORDER_KEY, $id, []); } return $data; }
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)); }
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)); } } }