public function remove() { StoreProductImage::removeImagesForProduct($this); StoreProductOptionGroup::removeOptionGroupsForProduct($this); StoreProductOptionItem::removeOptionItemsForProduct($this); StoreProductFile::removeFilesForProduct($this); StoreProductGroup::removeGroupsForProduct($this); StoreProductLocation::removeLocationsForProduct($this); StoreProductUserGroup::removeUserGroupsForProduct($this); StoreProductVariation::removeVariationsForProduct($this); $em = Database::get()->getEntityManager(); $em->remove($this); $em->flush(); $page = Page::getByID($this->cID); if (is_object($page)) { $page->delete(); } }
public function add($data) { $product = StoreProduct::getByID((int) $data['pID']); if (!$product) { return false; } if ($product->isExclusive()) { self::clear(); } //now, build a nicer "cart item" $cartItem = array(); $cartItem['product'] = array("pID" => (int) $data['pID'], "qty" => (int) $data['quantity']); unset($data['pID']); unset($data['quantity']); //since we removed the ID/qty, we're left with just the attributes $cartItem['productAttributes'] = $data; $removeexistingexclusive = false; foreach (self::getCart() as $k => $cart) { $cartproduct = StoreProduct::getByID((int) $cart['product']['pID']); if ($cartproduct && $cartproduct->isExclusive()) { self::remove($k); $removeexistingexclusive = true; } } $optionItemIds = array(); // search for product options, if found, collect the id foreach ($cartItem['productAttributes'] as $name => $value) { if (substr($name, 0, 3) == 'pog') { $optionItemIds[] = $value; } } if (!empty($optionItemIds)) { // find the variation via the ids of the options $variation = StoreProductVariation::getByOptionItemIDs($optionItemIds); // association the variation with the product if ($variation) { $options = $variation->getOptions(); if (count($options) == count($optionItemIds)) { // check if we've matched to a variation with the correct number of options $product->setVariation($variation); $cartItem['product']['variation'] = $variation->getID(); } else { return false; } } else { return false; // variation not matched } } elseif ($product->hasVariations()) { return false; // if we have a product with variations, but no variation data was submitted, it's a broken add-to-cart form } $cart = self::getCart(); $exists = self::checkForExistingCartItem($cartItem); if ($exists['exists'] === true) { $existingproductcount = $cart[$exists['cartItemKey']]['product']['qty']; //we have a match, update the qty if ($product->allowQuantity()) { $newquantity = $cart[$exists['cartItemKey']]['product']['qty'] + $cartItem['product']['qty']; if (!$product->isUnlimited() && !$product->allowBackOrders() && $product->getProductQty() < max($newquantity, $existingproductcount)) { $newquantity = $product->getProductQty(); } $added = $newquantity - $existingproductcount; } else { $added = 1; $newquantity = 1; } $cart[$exists['cartItemKey']]['product']['qty'] = $newquantity; } else { $newquantity = $cartItem['product']['qty']; if (!$product->isUnlimited() && !$product->allowBackOrders() && $product->getProductQty() < $newquantity) { $newquantity = $product->getProductQty(); } $cartItem['product']['qty'] = $newquantity; if ($product->isExclusive()) { $cart = array($cartItem); } else { $cart[] = $cartItem; } $added = $newquantity; } Session::set('vividstore.cart', $cart); return array('added' => $added, 'exclusive' => $product->isExclusive(), 'removeexistingexclusive' => $removeexistingexclusive); }
?> ><?php echo t("Price: High to Low"); ?> </option> </select> </div> <?php } echo '<div class="product-list clearfix" id="product-list-' . $bID . '">'; $i = 1; foreach ($products as $product) { $optionGroups = $product->getProductOptionGroups(); $optionItems = $product->getProductOptionItems(true); if ($product->hasVariations()) { $variations = StoreProductVariation::getVariationsForProduct($product); $variationLookup = array(); if (!empty($variations)) { foreach ($variations as $variation) { // returned pre-sorted $ids = $variation->getOptionItemIDs(); $variationLookup[implode('_', $ids)] = $variation; } } } //this is done so we can get a type of active class if there's a product list on the product page $class = "product-list-item vivid-store-col-" . $productsPerRow; if (Page::getCurrentPage()->getCollectionID() == $product->getProductPageID()) { $class = $class . " on-product-page"; } ?>
public function save() { $data = $this->post(); if ($data['pID']) { $this->edit($data['pID']); } else { $this->add(); } if ($this->isPost()) { $errors = $this->validate($data); $this->error = null; //clear errors $this->error = $errors; if (!$errors->has()) { //save the product $product = StoreProduct::saveProduct($data); //save product attributes $aks = StoreProductKey::getList(); foreach ($aks as $uak) { $uak->saveAttributeForm($product); } //save images StoreProductImage::addImagesForProduct($data, $product); //save product groups StoreProductGroup::addGroupsForProduct($data, $product); //save product user groups StoreProductUserGroup::addUserGroupsForProduct($data, $product); //save product options StoreProductOption::addProductOptions($data, $product); //save files StoreProductFile::addFilesForProduct($data, $product); //save category locations StoreProductLocation::addLocationsForProduct($data, $product); // save variations StoreProductVariation::addVariations($data, $product); if ($data['pID']) { $this->redirect('/dashboard/store/products/', 'updated'); } else { $this->redirect('/dashboard/store/products/', 'success'); } } //if no errors } //if post }