예제 #1
0
 public function generate(IsotopeProduct $objProduct, array $arrOptions = array())
 {
     $objPrice = $objProduct->getPrice();
     if (null === $objPrice) {
         return '';
     }
     return $objPrice->generate($objProduct->getRelated('type')->showPriceTiers());
 }
예제 #2
0
 public function generate(IsotopeProduct $objProduct, array $arrOptions = array())
 {
     $arrData = deserialize($objProduct->{$this->field_name});
     if (is_array($arrData) && $arrData['unit'] > 0 && $arrData['value'] != '') {
         $objBasePrice = \Isotope\Model\BasePrice::findByPk((int) $arrData['unit']);
         if (null !== $objBasePrice && null !== $objProduct->getPrice()) {
             return sprintf($objBasePrice->getLabel(), Isotope::formatPriceWithCurrency($objProduct->getPrice()->getAmount() / $arrData['value'] * $objBasePrice->amount), $arrData['value']);
         }
     }
     return '';
 }
예제 #3
0
 /**
  * Create a gallery for product, falls back to standard gallery if none is defined
  *
  * @param IsotopeProduct $objProduct
  * @param string         $strAttribute
  * @param array          $arrConfig
  *
  * @return static
  */
 public static function createForProductAttribute(IsotopeProduct $objProduct, $strAttribute, $arrConfig)
 {
     $objGallery = static::findByPk((int) $arrConfig['gallery']);
     if (null === $objGallery) {
         $objGallery = new \Isotope\Model\Gallery\Standard();
     }
     $objGallery->setName($objProduct->getFormId() . '_' . $strAttribute);
     $objGallery->setFiles(static::mergeMediaData(deserialize($objProduct->{$strAttribute}, true), deserialize($objProduct->{$strAttribute . '_fallback'}, true)));
     $objGallery->product_id = $objProduct->pid ? $objProduct->pid : $objProduct->id;
     $objGallery->href = $objProduct->generateUrl($arrConfig['jumpTo']);
     return $objGallery;
 }
예제 #4
0
파일: Frontend.php 프로젝트: bytehead/core
 /**
  * Callback for add_to_cart button
  *
  * @param IsotopeProduct $objProduct
  * @param array          $arrConfig
  */
 public function addToCart(IsotopeProduct $objProduct, array $arrConfig = array())
 {
     $objModule = $arrConfig['module'];
     $intQuantity = $objModule->iso_use_quantity && intval(\Input::post('quantity_requested')) > 0 ? intval(\Input::post('quantity_requested')) : 1;
     // Do not add parent of variant product to the cart
     if ($objProduct->hasVariants() && !$objProduct->isVariant()) {
         return;
     }
     if (Isotope::getCart()->addProduct($objProduct, $intQuantity, $arrConfig) !== false) {
         Message::addConfirmation($GLOBALS['TL_LANG']['MSC']['addedToCart']);
         if (!$objModule->iso_addProductJumpTo) {
             $this->reload();
         }
         \Controller::redirect(\Haste\Util\Url::addQueryString('continue=' . base64_encode(\Environment::get('request')), $objModule->iso_addProductJumpTo));
     }
 }
예제 #5
0
 public function generate(IsotopeProduct $objProduct, array $arrOptions = array())
 {
     $objPrice = $objProduct->getPrice();
     if (null === $objPrice || !$objPrice->hasTiers()) {
         return '';
     }
     $arrTiers = array();
     foreach ($objPrice->current()->getTiers() as $min => $price) {
         $arrTiers[] = array('min' => $min, 'price' => $price, 'tax_class' => $objPrice->tax_class);
     }
     $order = $arrOptions['order'];
     if ($order != '' && in_array($order, array_keys($arrTiers[0]))) {
         usort($arrTiers, function ($a, $b) use($order) {
             return strcmp($a[$order], $b[$order]);
         });
     }
     return $this->generateTable($arrTiers, $objProduct);
 }
예제 #6
0
 /**
  * Find prices for a given product and collection
  *
  * @param IsotopeProduct|Standard                    $objProduct
  * @param IsotopeProductCollection|ProductCollection $objCollection
  * @param array                                      $arrOptions
  *
  * @return IsotopePrice
  */
 public static function findByProductAndCollection(IsotopeProduct $objProduct, IsotopeProductCollection $objCollection, array $arrOptions = array())
 {
     $t = static::$strTable;
     $arrOptions['column'] = array();
     $arrOptions['value'] = array();
     if ($objProduct->hasAdvancedPrices()) {
         $time = \Date::floorToMinute($objCollection->getLastModification());
         $arrGroups = static::getMemberGroups($objCollection->getRelated('member'));
         $arrOptions['column'][] = "{$t}.config_id IN (" . (int) $objCollection->config_id . ",0)";
         $arrOptions['column'][] = "{$t}.member_group IN(" . implode(',', $arrGroups) . ")";
         $arrOptions['column'][] = "({$t}.start='' OR {$t}.start<'{$time}')";
         $arrOptions['column'][] = "({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "')";
         $arrOptions['order'] = "{$t}.config_id DESC, " . \Database::getInstance()->findInSet('member_group', $arrGroups) . ", {$t}.start DESC, {$t}.stop DESC";
     } else {
         $arrOptions['column'][] = "{$t}.config_id=0";
         $arrOptions['column'][] = "{$t}.member_group=0";
         $arrOptions['column'][] = "{$t}.start=''";
         $arrOptions['column'][] = "{$t}.stop=''";
     }
     if ($objProduct->hasVariantPrices() && !$objProduct->isVariant()) {
         $arrIds = $objProduct->getVariantIds() ?: array(0);
         $arrOptions['column'][] = "{$t}.pid IN (" . implode(',', $arrIds) . ")";
     } else {
         $arrOptions['column'][] = "{$t}.pid=" . ($objProduct->hasVariantPrices() ? $objProduct->id : $objProduct->getProductId());
     }
     $objResult = static::find($arrOptions);
     return null === $objResult ? null : $objResult->filterDuplicatesBy('pid');
 }
예제 #7
0
 /**
  * Return calculated price for this attribute option
  *
  * @param IsotopeProduct $objProduct
  *
  * @return float
  *
  * @deprecated Deprecated since Isotope 2.2.6, to be removed in 3.0.
  *             This method can result in an endless loop, use getAmount() instead.
  */
 public function getPrice(IsotopeProduct $objProduct = null)
 {
     if ($this->isPercentage() && null !== $objProduct) {
         /** @type ProductPrice|ProductPrice[] $objPrice */
         $objPrice = $objProduct->getPrice();
         if (null !== $objPrice) {
             if ($objPrice instanceof ProductPriceCollection) {
                 $fltPrice = null;
                 foreach ($objPrice as $objPriceModel) {
                     $fltAmount = $objPriceModel->getAmount();
                     if (null === $fltPrice || $fltAmount < $fltPrice) {
                         $fltPrice = $fltAmount;
                     }
                 }
             } else {
                 $fltPrice = $objPrice->getAmount();
             }
             return $fltPrice / 100 * $this->getPercentage();
         }
     } else {
         /** @type ProductPrice|ProductPrice[] $objPrice */
         if (null !== $objProduct && ($objPrice = $objProduct->getPrice()) !== null) {
             return Isotope::calculatePrice($this->price, $this, 'price', $objPrice->tax_class);
         } else {
             return Isotope::calculatePrice($this->price, $this, 'price');
         }
     }
     return $this->price;
 }
예제 #8
0
파일: Product.php 프로젝트: Aziz-JH/core
 /**
  * Find variant of a product
  * @param   IsotopeProduct
  * @param   array
  * @param   array
  */
 public static function findVariantOfProduct(IsotopeProduct $objProduct, array $arrVariant, array $arrOptions = array())
 {
     $t = static::$strTable;
     $arrColumns = array("{$t}.id IN (" . implode(',', $objProduct->getVariantIds()) . ")", "{$t}." . implode("=? AND {$t}.", array_keys($arrVariant)) . "=?");
     $arrOptions = array_merge(array('limit' => 1, 'column' => $arrColumns, 'value' => $arrVariant, 'return' => 'Model'), $arrOptions);
     return static::find($arrOptions);
 }
 /**
  * Currently only works for products containing one single download
  *
  * @param IsotopeProduct $objProduct
  * @param array          $arrConfig
  */
 public function downloadSingleProduct(IsotopeProduct $objProduct, array $arrConfig = array())
 {
     if (($objDownload = Download::findByPid($objProduct->getProductId())) !== null && ($strPath = Files::getPathFromUuid($objDownload->singleSRC))) {
         // TODO count downloads
         // start downloading the file (protected folders also supported)
         \Controller::redirect(Environment::getUrl() . '?file=' . $strPath);
     }
 }
예제 #10
0
 /**
  * Adds canonical product URLs to the document
  * @param   IsotopeProduct
  */
 protected function addCanonicalProductUrls(IsotopeProduct $objProduct)
 {
     global $objPage;
     $arrPageIds = \Database::getInstance()->getChildRecords($objPage->rootId, \PageModel::getTable());
     $arrPageIds[] = $objPage->rootId;
     // Find the categories in the current root
     $arrCategories = array_intersect($objProduct->getCategories(), $arrPageIds);
     foreach ($arrCategories as $intPage) {
         // Do not use the index page as canonical link
         if ($objPage->alias == 'index' && count($arrCategories) > 1) {
             continue;
         }
         // Current page is the primary one, do not generate canonical link
         if ($intPage == $objPage->id) {
             break;
         }
         if (($objJumpTo = \PageModel::findWithDetails($intPage)) !== null) {
             $strDomain = \Environment::get('base');
             // Overwrite the domain
             if ($objJumpTo->dns != '') {
                 $strDomain = ($objJumpTo->useSSL ? 'https://' : 'http://') . $objJumpTo->dns . TL_PATH . '/';
             }
             $GLOBALS['TL_HEAD'][] = sprintf('<link rel="canonical" href="%s">', $strDomain . $objProduct->generateUrl($objJumpTo));
             break;
         }
     }
 }
예제 #11
0
 /**
  * Find related products of a product
  * @param   IsotopeProduct
  * @param   array
  * @param   array
  * @return  \Model\Collection|null
  */
 public static function findByProductAndCategories(IsotopeProduct $objProduct, array $arrCategories, array $arrOptions = array())
 {
     $t = static::$strTable;
     $arrOptions = array_merge(array('column' => array("{$t}.pid=?", "{$t}.category IN (" . implode(',', $arrCategories) . ")"), 'value' => array($objProduct->getProductId()), 'order' => \Database::getInstance()->findInSet("{$t}.category", $arrCategories), 'return' => 'Collection'), $arrOptions);
     return static::find($arrOptions);
 }