本文整理汇总了PHP中Thelia\Core\HttpFoundation\Request::getProductId方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getProductId方法的具体用法?PHP Request::getProductId怎么用?PHP Request::getProductId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thelia\Core\HttpFoundation\Request
的用法示例。
在下文中一共展示了Request::getProductId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cartFormAfterBuild
/**
* Add fields for attribute values selection in our own way (since the product on has its default PSE, it has
* no attributes as far as Thelia is concerned, but we want it to have all of its template's attributes).
*
* @param TheliaFormEvent $event
*/
public function cartFormAfterBuild(TheliaFormEvent $event)
{
$sessionLocale = null;
$session = $this->request->getSession();
if ($session !== null) {
$sessionLang = $session->getLang();
if ($sessionLang !== null) {
$sessionLocale = $sessionLang->getLocale();
}
}
$product = ProductQuery::create()->findPk($this->request->getProductId());
if ($product === null || $product->getTemplate() === null) {
return;
}
$productAttributes = AttributeQuery::create()->filterByTemplate($product->getTemplate())->find();
/** @var Attribute $productAttribute */
foreach ($productAttributes as $productAttribute) {
$attributeValues = AttributeAvQuery::create()->findByAttributeId($productAttribute->getId());
$choices = [];
/** @var AttributeAv $attributeValue */
foreach ($attributeValues as $attributeValue) {
if ($sessionLocale !== null) {
$attributeValue->setLocale($sessionLocale);
}
$choices[$attributeValue->getId()] = $attributeValue->getTitle();
}
$event->getForm()->getFormBuilder()->add(static::LEGACY_PRODUCT_ATTRIBUTE_FIELD_PREFIX . $productAttribute->getId(), 'choice', ['choices' => $choices, 'required' => true]);
}
}