public static function isEnabled() { if (null === self::$isEnabled) { self::$isEnabled = (bool) Mage::getStoreConfig('fitment/general/enabled'); } return self::$isEnabled; }
public function getFacets() { $facets = isset(self::$_ariData['Facets']) ? self::$_ariData['Facets'] : array(); //return $facets; if (!count($facets)) { return $facets; } $pageMode = isset(self::$_ariParams['pageMode']) ? self::$_ariParams['pageMode'] : array(); $categoryFieldsCodes = array(10 => 'categoryid', 20 => 'subcategoryid'); if ('tireBySize' == $pageMode || 'tireByRide' == $pageMode) { // tireshop mode // TODO: check for doing the same for tireByRide mode as well! // TODO: make sure category ID remains at JS config when making requests //remove from sidebar: // Category, subcategory, - by field code // Type, Tire Application, Tire Type - by field label (called Name); detect these dynamically $removedFieldsNames = array(Vikont_Fitment_Helper_Data::normalizeCategoryName(Mage::getStoreConfig('fitment/tireshop/tiresize_attr_type')), Vikont_Fitment_Helper_Data::normalizeCategoryName(Mage::getStoreConfig('fitment/tireshop/tiresize_attr_tireapplication')), Vikont_Fitment_Helper_Data::normalizeCategoryName(Mage::getStoreConfig('fitment/tireshop/tiresize_attr_tiretype'))); foreach ($facets as $facetIndex => $facet) { if (in_array(strtolower($facet['Field']), $categoryFieldsCodes) || in_array(Vikont_Fitment_Helper_Data::normalizeCategoryName($facet['Name']), $removedFieldsNames)) { unset($facets[$facetIndex]); continue; } $facets[$facetIndex]['InputType'] = 'checkbox'; } return $facets; } elseif (!isset(self::$_ariParams['options']['categoryId'])) { // restricting the filters to Category only until a category is selected foreach ($facets as $facet) { if (strtolower($facet['Field']) == 'categoryid') { $facet['InputType'] = 'select'; return array($facet); } } } else { // normal workflow $sortedFacets = array(); foreach ($facets as $facetIndex => $facet) { $sortKey = array_search(strtolower($facet['Field']), $categoryFieldsCodes); if ($sortKey) { $facet['InputType'] = 'select'; $sortedFacets[$sortKey . ' '] = $facet; } else { $facet['InputType'] = 'checkbox'; $sortedFacets[$facet['Name']] = $facet; } } ksort($sortedFacets); $facets = array(); foreach ($sortedFacets as $facet) { if (strtolower($facet['Field']) == 'categoryid') { $facets[] = array('InputType' => 'resetCategory'); } $facets[] = $facet; } } return $facets; }
public function getProducts() { $result = array(); try { $tmsActivityId = $this->getTmsActivityId(); $ariActivityId = Vikont_Fitment_Helper_Data::getTmsActivity($tmsActivityId, 'ari_activity'); $ariProductId = $this->getAriProductId(); $fitmentId = $this->getFitmentId(); $fitmentNotes = Mage::helper('fitment/api')->preventErrorReporting()->request('fitmentnotes', array('productID' => $ariProductId, 'fitmentID' => $fitmentId)); if (!$fitmentNotes) { Mage::log(sprintf('Unable to get fitment notes from ARI API: ARI product ID = %d, ARI fitment ID = %d', $ariProductId, $fitmentId)); } $skuInfo = Mage::helper('fitment/api')->request('skuinfo', array('activityID' => $ariActivityId, 'productID' => $ariProductId), array('fitmentID' => $fitmentId)); if (!$skuInfo) { throw new Exception(sprintf('Unable to get SKU info from ARI API: ARI activity ID = %d, ARI product ID = %d, ARI fitment ID = %d', $ariActivityId, $ariProductId, $fitmentId)); } $fitmentItems = array(); foreach ($skuInfo as $item) { $sku = (string) $item['Id']; $fitmentItems[$sku] = $item; } foreach ($fitmentNotes as $item) { $sku = (string) $item['SkuId']; if (isset($fitmentItems[$sku])) { $fitmentItems[$sku]['Applications'] = $item['Applications']; $fitmentItems[$sku]['Note'] = $item['Note']; } } foreach ($fitmentItems as &$item) { if (!isset($item['Applications'])) { $item['Applications'] = array(); $item['Note'] = ''; } } unset($item); $collection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('name')->addFinalPrice()->addFieldToFilter('sku', array('in' => array_keys($fitmentItems))); // put the check in here // so if an SKU hasn't been found in the Mage DB, then report about that $missingItems = $fitmentItems; foreach ($collection as $product) { $sku = $product->getSku(); if (isset($fitmentItems[$sku])) { $result[$sku] = array('item' => $fitmentItems[$sku], 'product' => $product); unset($missingItems[$sku]); } } if (count($missingItems)) { Mage::log('The following SKUs do not exist in Magento, although they were gathered from ARI API: ' . implode(', ', array_keys($missingItems))); } // borrow a code from Vikont_Wholesale_Helper_Email::notifyCustomer to send an email on this // or make a separate log file } catch (Exception $e) { Mage::logException($e); } return $result; }
public function getTmsActivityId() { $currentCategory = Mage::registry('current_category'); if ($currentCategory instanceof Mage_Catalog_Model_Category) { $activityId = Vikont_Fitment_Helper_Data::getActivityIdFromCategory($currentCategory->getId(), 'tms_activity_id'); } if (null === $activityId) { $activityId = parent::getTmsActivityId(); } return $activityId; }
public function requestAction() { //Mage::register('vd', 1); $params = $this->getRequest()->getParams(); $subject = $params['subject']; unset($params['subject']); $tmsActivityId = (int) $params['activity']; unset($params['activity']); $res = array(); $options = $params; $options['includeFacets'] = 'true'; $options['take'] = '0'; try { switch ($subject) { case 'size': $res = Mage::helper('fitment')->getTireSizes($tmsActivityId); break; case 'brand': $ariActivityId = Vikont_Fitment_Helper_Data::getTireshopActivity($tmsActivityId, 'ari_activity'); $options = Vikont_Fitment_Helper_Data::applyExtraFilter($options, $tmsActivityId); $data = Mage::helper('fitment/api')->request('search', array($ariActivityId), $options); if (!$data) { throw new Exception('Error getting remote data for ' . $subject); } foreach ($data['Facets'] as $facet) { if ($facet['Field'] == 'brandId') { foreach ($facet['Values'] as $facetValue) { $res[] = array('Name' => $facetValue['Name'], 'Value' => $facetValue['Value']); } $res = Vikont_Fitment_Helper_Data::sortOptions($res, 'Name'); break; } } break; case 'price': /** $activityId = Vikont_Fitment_Helper_Data::getTireshopActivity($activityIndex); $options = Vikont_Fitment_Helper_Data::applyExtraFilter($options, $activityIndex); $data = Mage::helper('fitment/api')->request('search', array($activityId), $options); if(!$data) { throw new Exception('Error getting remote data for' . $subject); } /**/ $res = array(array('From' => 0, 'To' => 1000000, 'Value' => '0-0', 'Name' => $this->__('Any price'))); break; } $errorMessage = ''; } catch (Exception $e) { $errorMessage = Vikont_Fitment_Helper_Data::reportError($e->getMessage()); } $response = array('subject' => $subject, 'params' => $this->getRequest()->getParams(), 'data' => $res, 'errorMessage' => $errorMessage); echo json_encode($response); die; }
public function getMakes($filter = array()) { $ariActivityId = Vikont_Fitment_Helper_Data::getTmsActivity($this->getTmsActivityId(), 'ari_activity'); if (count($filter)) { $params = array('subject' => 'makes', 'activity' => $ariActivityId); $params = array_merge($params, $filter); $result = Mage::helper('fitment')->getFitmentValues($params); } else { $result = Mage::helper('fitment')->getMakes($ariActivityId); } return is_array($result) ? $result : array(); }
public function getAllOptions($withEmpty = true) { if (!$this->_options) { $this->_options = array(); foreach (Vikont_Fitment_Helper_Data::getTmsActivities() as $id => $item) { $this->_options[] = array('value' => $id, 'label' => $item['name']); } } if ($withEmpty) { $options = $this->_options; array_unshift($options, array('value' => '', 'label' => Mage::helper('core')->__('-- Please Select --'))); return $options; } return $this->_options; }
public function getTmsActivityId() { if (null === self::$_activityId) { self::$_activityId = Mage::app()->getRequest()->getParam('activity'); if (null === self::$_activityId) { if ($currentCategory = Mage::registry('current_category')) { self::$_activityId = Vikont_Fitment_Helper_Data::getActivityIdFromCategory($currentCategory, 'tms_activity_id'); } } if (null === self::$_activityId) { $currentProduct = Mage::registry('current_product'); if ($currentProduct) { self::$_activityId = (int) Vikont_Fitment_Helper_Data::getActivityIdFromProduct($currentProduct); } } if (null === self::$_activityId) { self::$_activityId = parent::getTmsActivityId(); } } return self::$_activityId; }
public function getTiresCategoryId() { $ariActivityId = Vikont_Fitment_Helper_Data::getTmsActivity($this->getTmsActivityId(), 'ari_activity'); return Mage::helper('fitment')->getTiresCategoryId($ariActivityId); }
public function viewProductAction() { //Mage::register('vd', 1); $params = $this->getRequest()->getParams(); $ariActivityId = Vikont_Fitment_Helper_Data::getTmsActivity($params['activity'], 'ari_activity'); $tmsProductIds = Mage::helper('fitment')->detectProductIdInfo($params['product'], $ariActivityId, $params['fitment']); $params['productIds'] = $tmsProductIds; $response = array('params' => $params, 'errorMessage' => ''); try { $response['html'] = $this->getLayout()->createBlock('fitment/fitment_view')->setTmsActivity($params['activity'])->setAriActivity($ariActivityId)->setAriProductId($params['product'])->setFitmentId($params['fitment'])->setTmsProductIds($tmsProductIds)->setVehicle($params['vehicle'])->setElements($params['options']['elements'])->toHtml(); } catch (Exception $e) { $response['errorMessage'] = $e->getMessage(); Mage::logException($e); } echo json_encode($response); die; }