/** * @return \Pimcore\Model\Object\CoreShopProduct */ public function getGift() { if (!$this->gift instanceof CoreShopProduct) { $this->gift = CoreShopProduct::getByPath($this->gift); } return $this->gift; }
public function previewAction() { $id = $this->getParam("id"); $product = CoreShopProduct::getById($id); $this->disableLayout(); if ($product instanceof $product) { $this->view->product = $product; } else { throw new \Exception(sprintf("Product with id %s not found", $id)); } }
public function addAction() { $product_id = $this->getParam("product", null); $amount = $this->getParam("amount", 1); $product = CoreShopProduct::getById($product_id); $isAllowed = true; $result = Plugin::getEventManager()->trigger('cart.preAdd', $this, array("product" => $product, "cart" => $this->cart, "request" => $this->getRequest()), function ($v) { return is_bool($v); }); if ($result->stopped()) { $isAllowed = $result->last(); } if ($isAllowed) { if ($product instanceof CoreShopProduct && $product->getEnabled() && $product->getAvailableForOrder()) { $item = $this->cart->addItem($product, $amount); Plugin::getEventManager()->trigger('cart.postAdd', $this, array("request" => $this->getRequest(), "product" => $product, "cart" => $this->cart, "cartItem" => $item)); $this->_helper->json(array("success" => true, "cart" => $this->cart->toArray())); } } else { $this->_helper->json(array("success" => false, "message" => 'not allowed')); } $this->_helper->json(array("success" => false, "cart" => $this->cart->toArray())); }
/** * Gets all Differences in the variants * * @param CoreShopProduct $product * @return array */ public static function getDimensions(CoreShopProduct $product) { $variants = $product->getChilds(array(AbstractObject::OBJECT_TYPE_VARIANT)); $fieldDefinition = $product->getClass()->getFieldDefinition("dimensions"); $variantsAndMaster = array_merge(array($product), $variants); $currentInheritedValue = AbstractObject::getGetInheritedValues(); AbstractObject::setGetInheritedValues(false); $overwrittenKeyValues = array(); $overwrittenKeys = array(); if (count($variants) > 0) { foreach ($variants as $variant) { $fieldData = $variant->getDimensions(); $value = $fieldDefinition->getDataForEditmode($fieldData, $variant); //Search for not inherited fields foreach ($value as $singleBrickData) { if (!$singleBrickData) { continue; } if (!array_key_exists($singleBrickData['type'], $overwrittenKeys)) { $overwrittenKeys[$singleBrickData['type']] = array(); } foreach ($singleBrickData['metaData'] as $key => $meta) { if (!$meta['inherited']) { if (!in_array($key, $overwrittenKeys[$singleBrickData['type']])) { $overwrittenKeys[$singleBrickData['type']][] = $key; } } } } } //We now have the keys and reloop the variants to get all the values foreach ($variantsAndMaster as $variant) { $fieldData = $variant->getDimensions(); $value = $fieldDefinition->getDataForEditmode($fieldData, $variant); foreach ($value as $singleBrickData) { if (!$singleBrickData) { continue; } if (array_key_exists($singleBrickData['type'], $overwrittenKeys)) { if (!is_array($overwrittenKeyValues[$singleBrickData['type']])) { $overwrittenKeyValues[$singleBrickData['type']] = array(); } foreach ($overwrittenKeys[$singleBrickData['type']] as $key) { $found = false; foreach ($overwrittenKeyValues[$singleBrickData['type']][$key] as $existingValue) { if ($existingValue['value'] == $singleBrickData['data'][$key]) { $found = true; break; } } if (!$found) { $overwrittenKeyValues[$singleBrickData['type']][$key][] = array("value" => $singleBrickData['data'][$key], "object" => $variant->getId()); } } } } } } AbstractObject::setGetInheritedValues($currentInheritedValue); return $overwrittenKeyValues; }
/** * finds the CartItem for a Product * * @param CoreShopProduct $product * @return bool * @throws \Exception */ public function findItemForProduct(CoreShopProduct $product) { if (!$product instanceof CoreShopProduct) { throw new \Exception("\$product must be instance of CoreShopProduct"); } foreach ($this->getItems() as $item) { if ($item->getProduct()->getId() == $product->getId()) { return $item; } } return false; }