private function _relateProducts(Mage_Catalog_Model_Product $_product, $data)
 {
     $this->log($this->__('Relating products for %s', $_product->getSku()));
     $relatableData = array();
     foreach ($data as $i => $relatedSku) {
         $relatedProductId = Mage::getModel('catalog/product')->getIdBySku($relatedSku);
         if (!$relatedProductId) {
             throw new Exception($this->__('No product with sku: %s' . $relatedSku));
         }
         $relatableData[$relatedProductId] = array('position' => $i);
         $this->log($this->__('Related %s', $relatedSku), 1);
     }
     $_product->setRelatedLinkData($relatableData);
     $_product->save();
     $this->log($this->__('Finished relating products for %s', $_product->getSku()));
 }
Ejemplo n.º 2
0
 public function testDuplicateSkuGeneration()
 {
     $this->_model->load(1);
     $this->assertEquals('simple', $this->_model->getSku());
     $duplicated = $this->_model->duplicate();
     $this->assertEquals('simple-1', $duplicated->getSku());
 }
Ejemplo n.º 3
0
 public function getUpdateListingWrapper(Mage_Catalog_Model_Product $product)
 {
     $reverbListingWrapper = Mage::getModel('reverbSync/wrapper_listing');
     $sku = $product->getSku();
     // $condition = $this->_getCondition();
     $fieldsArray = array('sku' => $sku);
     if ($this->_getListingsUpdateSyncHelper()->isTitleUpdateEnabled()) {
         $fieldsArray['title'] = $product->getName();
     }
     if ($this->_getListingsUpdateSyncHelper()->isPriceUpdateEnabled()) {
         $fieldsArray['price'] = $this->getProductPrice($product);
     }
     if ($this->_getListingsUpdateSyncHelper()->isDescriptionUpdateEnabled()) {
         $fieldsArray['description'] = $this->getProductDescription($product);
     }
     if ($this->_getListingsUpdateSyncHelper()->isInventoryQtyUpdateEnabled()) {
         $hasInventory = $this->_getHasInventory();
         $fieldsArray['has_inventory'] = $hasInventory;
         $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
         $fieldsArray['inventory'] = $stock->getQty();
     }
     $this->_addMappedAttributes($fieldsArray, $product);
     $this->_addArbitraryMappedAttributes($fieldsArray, $product);
     $this->_addProductAcceptOffers($fieldsArray, $product);
     $this->addCategoryToFieldsArray($fieldsArray, $product);
     $this->addProductConditionIfSet($fieldsArray, $product);
     $reverbListingWrapper->setApiCallContentData($fieldsArray);
     $reverbListingWrapper->setMagentoProduct($product);
     return $reverbListingWrapper;
 }
Ejemplo n.º 4
0
 /**
  * Validate SKU
  *
  * @param Mage_Catalog_Model_Product $object
  * @throws Mage_Core_Exception
  * @return bool
  */
 public function validate($object)
 {
     $helper = Mage::helper('core/string');
     if ($helper->strlen($object->getSku()) > self::SKU_MAX_LENGTH) {
         Mage::throwException(Mage::helper('catalog')->__('SKU length should be %s characters maximum.', self::SKU_MAX_LENGTH));
     }
     return parent::validate($object);
 }
Ejemplo n.º 5
0
 /**
  * @magentoDataFixture Mage/Catalog/_files/product_simple.php
  */
 public function testGenerateUniqueSkuExistingProduct()
 {
     $product = new Mage_Catalog_Model_Product();
     $product->load(1);
     $product->setId(null);
     $this->assertEquals('simple', $product->getSku());
     $product->getResource()->getAttribute('sku')->getBackend()->beforeSave($product);
     $this->assertEquals('simple-1', $product->getSku());
 }
 /**
  * Create Product array from Mage_Catalog_Model_Product
  *
  * @param Mage_Catalog_Model_Product $product
  * @return array
  */
 public function getProductData(Mage_Catalog_Model_Product $product)
 {
     try {
         $data = array('url' => $product->getProductUrl(), 'title' => htmlspecialchars($product->getName()), 'spider' => 1, 'price' => $product->getPrice(), 'description' => urlencode($product->getDescription()), 'tags' => htmlspecialchars($product->getMetaKeyword()), 'images' => array(), 'vars' => array('sku' => $product->getSku(), 'storeId' => '', 'typeId' => $product->getTypeId(), 'status' => $product->getStatus(), 'categoryId' => $product->getCategoryId(), 'categoryIds' => $product->getCategoryIds(), 'websiteIds' => $product->getWebsiteIds(), 'storeIds' => $product->getStoreIds(), 'groupPrice' => $product->getGroupPrice(), 'formatedPrice' => $product->getFormatedPrice(), 'calculatedFinalPrice' => $product->getCalculatedFinalPrice(), 'minimalPrice' => $product->getMinimalPrice(), 'specialPrice' => $product->getSpecialPrice(), 'specialFromDate' => $product->getSpecialFromDate(), 'specialToDate' => $product->getSpecialToDate(), 'relatedProductIds' => $product->getRelatedProductIds(), 'upSellProductIds' => $product->getUpSellProductIds(), 'getCrossSellProductIds' => $product->getCrossSellProductIds(), 'isSuperGroup' => $product->isSuperGroup(), 'isGrouped' => $product->isGrouped(), 'isConfigurable' => $product->isConfigurable(), 'isSuper' => $product->isSuper(), 'isSalable' => $product->isSalable(), 'isAvailable' => $product->isAvailable(), 'isVirtual' => $product->isVirtual(), 'isRecurring' => $product->isRecurring(), 'isInStock' => $product->isInStock(), 'weight' => $product->getSku()));
         // Add product images
         if (self::validateProductImage($product->getImage())) {
             $data['images']['full'] = array("url" => $product->getImageUrl());
         }
         if (self::validateProductImage($product->getSmallImage())) {
             $data['images']['smallImage'] = array("url" => $product->getSmallImageUrl($width = 88, $height = 77));
         }
         if (self::validateProductImage($product->getThumbnail())) {
             $data['images']['thumb'] = array("url" => $product->getThumbnailUrl($width = 75, $height = 75));
         }
         return $data;
         return $data;
     } catch (Exception $e) {
         Mage::logException($e);
     }
 }
Ejemplo n.º 7
0
 /**
  * set identifiers
  */
 public function setIdentifiers()
 {
     $result = array();
     $identifierItemObject = new Shopgate_Model_Catalog_Identifier();
     $identifierItemObject->setType('SKU');
     $identifierItemObject->setValue($this->item->getSku());
     $result[] = $identifierItemObject;
     $this->_getIdentifierByType('ean', $result);
     $this->_getIdentifierByType('upc', $result);
     parent::setIdentifiers($result);
 }
Ejemplo n.º 8
0
 /**
  * Import item data from product model object
  *
  * @param   Mage_Catalog_Model_Product $product
  * @return  Mage_Sales_Model_Quote_Item
  */
 public function importCatalogProduct(Mage_Catalog_Model_Product $product)
 {
     $this->setProductId($product->getId())->setSku($product->getSku())->setName($product->getName())->setWeight($product->getWeight())->setTaxClassId($product->getTaxClassId())->setCost($product->getCost())->setIsQtyDecimal($product->getIsQtyDecimal());
     if ($product->getSuperProduct()) {
         $this->setSuperProductId($product->getSuperProduct()->getId());
         if ($product->getSuperProduct()->isConfigurable()) {
             $this->setName($product->getSuperProduct()->getName());
         }
     }
     $this->setProduct($product);
     return $this;
 }
Ejemplo n.º 9
0
 /**
  * Validate SKU
  *
  * @param Mage_Catalog_Model_Product $object
  * @throws Mage_Core_Exception
  * @return bool
  */
 public function validate($object)
 {
     $helper = Mage::helper('Mage_Core_Helper_String');
     $attrCode = $this->getAttribute()->getAttributeCode();
     $value = $object->getData($attrCode);
     if ($this->getAttribute()->getIsRequired() && $this->getAttribute()->isValueEmpty($value)) {
         return false;
     }
     if ($helper->strlen($object->getSku()) > self::SKU_MAX_LENGTH) {
         Mage::throwException(Mage::helper('Mage_Catalog_Helper_Data')->__('SKU length should be %s characters maximum.', self::SKU_MAX_LENGTH));
     }
     return true;
 }
Ejemplo n.º 10
0
 /**
  * @magentoAppIsolation enabled
  */
 public function testDuplicate()
 {
     $this->_model->load(1);
     // fixture
     $duplicate = $this->_model->duplicate();
     try {
         $this->assertNotEmpty($duplicate->getId());
         $this->assertNotEquals($duplicate->getId(), $this->_model->getId());
         $this->assertNotEquals($duplicate->getSku(), $this->_model->getSku());
         $this->assertEquals(Mage_Catalog_Model_Product_Status::STATUS_DISABLED, $duplicate->getStatus());
         $this->_undo($duplicate);
     } catch (Exception $e) {
         $this->_undo($duplicate);
         throw $e;
     }
 }
Ejemplo n.º 11
0
 /**
  * @param Mage_Catalog_Model_Product $configurableProduct
  * @return array
  * @throws Exception
  */
 public function getSimpleProductsForConfigurableProduct($configurableProduct)
 {
     if ($configurableProduct->getTypeId() != Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
         $error_message = $this->__(self::ERROR_PRODUCT_NOT_CONFIGURABLE, $configurableProduct->getSku());
         throw new Exception($error_message);
     }
     $parent_id = $configurableProduct->getId();
     $child_product_ids_return = $this->_getConfigurableProductTypeModel()->getChildrenIds($parent_id);
     $child_product_ids = reset($child_product_ids_return);
     $child_products_array = array();
     foreach ($child_product_ids as $child_product_id) {
         $childProduct = Mage::getModel('catalog/product')->load($child_product_id);
         if (is_object($childProduct) && $childProduct->getId()) {
             $child_products_array[] = $childProduct;
         }
     }
     return $child_products_array;
 }
Ejemplo n.º 12
0
 /**
  * @magentoAppIsolation enabled
  */
 public function testDuplicate()
 {
     $undo = function ($duplicate) {
         Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
         $duplicate->delete();
     };
     $this->_model->load(1);
     // fixture
     $duplicate = $this->_model->duplicate();
     try {
         $this->assertNotEmpty($duplicate->getId());
         $this->assertNotEquals($duplicate->getId(), $this->_model->getId());
         $this->assertNotEquals($duplicate->getSku(), $this->_model->getSku());
         $this->assertEquals(Mage_Catalog_Model_Product_Status::STATUS_DISABLED, $duplicate->getStatus());
         $undo($duplicate);
     } catch (Exception $e) {
         $undo($duplicate);
         throw $e;
     }
 }
 /**
  * extract the the title value from the DOMNodelist object if value not empty
  * simply append the store id and return the vlaue. if the value is empty
  * append the a know string string with the sku and the store id and return
  * @param DOMNodeList $nodes
  * @param Mage_Catalog_Model_Product $product
  * @return string
  */
 public function extractUrlKeyValue(DOMNodeList $nodes, Mage_Catalog_Model_Product $product)
 {
     $urlKey = $this->coreHelper->extractNodeVal($nodes);
     return $urlKey !== '' ? $urlKey . '-' . $product->getStoreId() : 'Incomplete Product: ' . $product->getSku() . '-' . $product->getStoreId();
 }
Ejemplo n.º 14
0
 protected function _getSku()
 {
     return $this->_product->getSku();
 }
Ejemplo n.º 15
0
 public function isGiftOfferedFor(Mage_Catalog_Model_Product $product)
 {
     return $product->getSku() === self::PRODUCT_SKU_TO_TARGET;
 }
Ejemplo n.º 16
0
 public function getProductHtml(Mage_Catalog_Model_Product $product, $extraClass = '')
 {
     $productName = $product->getName();
     $productName = htmlspecialchars($productName);
     $productShortName = strlen($productName) > 100 ? substr($productName, 0, 100) . '...' : $productName;
     $productId = $product->getId();
     $productType = $product->getTypeId();
     $productSku = $product->getSku();
     $productData = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
     $qtyinc = 1;
     if ($productData->getQtyIncrements()) {
         $qtyinc = $productData->getQtyIncrements();
     }
     $priceAndTaxData = $this->getProductPriceAndTaxData($product);
     $finalPrice = $priceAndTaxData['finalPrice'];
     $tax_amount = $priceAndTaxData['tax_amount'];
     $price = $priceAndTaxData['price'];
     $priceInclTax = $priceAndTaxData['priceInclTax'];
     $tax = $priceAndTaxData['tax'];
     $includeTax = $priceAndTaxData['includeTax'];
     $productPrice = $priceAndTaxData['productPrice'];
     if ($includeTax == true) {
         //$tax = 0;
         //$finalPrice = $price;
     }
     $storeId = $this->_store_id;
     $store = Mage::getModel('core/store')->load($storeId);
     $imgPath = Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(120);
     $productOptions = $options = $customOptions = $groupedChilds = $bundleChilds = $storeCreditOptions = array();
     $priceConditions = '';
     $productOptions = $this->getProductOptions($product);
     $hasOption = $this->isProductHasOptions($product);
     $hasOptionString = $hasOption == true ? 'hasOption' : '0';
     if (isset($productOptions['bundle']) && count($productOptions['bundle']) > 0) {
         $bundleChilds = $productOptions['bundle'];
         $isBundle = true;
         $totalDefault = 0;
         foreach ($bundleChilds as $childId => $childData) {
             $items = $childData['items'];
             if (count($items) > 0) {
                 foreach ($items as $itemId => $itemData) {
                     //if ($itemData['is_default'] == '1') {
                     $totalDefault += $itemData['price'] * $itemData['qty'];
                     //}
                 }
             }
         }
     }
     $priceDisplay = $isBundle == true ? $store->formatPrice($totalDefault) : $store->formatPrice($finalPrice);
     $html = "<div qtyinc='" . $qtyinc . "' tax_amount='" . $tax_amount . "' class='product " . $extraClass . " col-lg-3 col-md-3 col-sm-3 col-xs-3' id='prd_" . $productId . "' prd_type='" . $product->getTypeID() . "' hasoption='" . $hasOptionString . "'>\r\n\t\t\t\t\t<div class='item' hasoption=" . $hasOptionString . " prdid='" . $productId . "' onclick=\"addProduct('" . $productId . "', '" . $finalPrice . "', '" . $imgPath . "')\">\r\n\t\t\t\t\t\t<div class='img-product'>\r\n\t\t\t\t\t\t\t<div class='prd_sku'>" . $productSku . "</div>\r\n\t\t\t\t\t\t\t<div class='prd_price_bg'></div>\r\n\t\t\t\t\t\t\t<div class='prd_price'>" . $priceDisplay . "</div>\r\n\t\t\t\t\t\t\t<img class='product_image' src='' imgpath='" . $imgPath . "'/>\r\n\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t<h2 id='prd_name_" . $productId . "'>" . $productShortName . "</h2>\r\n\t\t\t\t\t\t<p id='prd_fullname_" . $productId . "' class='hide'>" . $productName . "</p>\r\n\t\t\t\t\t</div>";
     if (isset($productOptions['configurable']) && count($productOptions['configurable']) > 0 || isset($productOptions['custom_options']) && count($productOptions['custom_options']) > 0 || isset($productOptions['grouped']) && count($productOptions['grouped']) > 0 || isset($productOptions['bundle']) && count($productOptions['bundle']) > 0 || isset($productOptions['customercredit']) && count($productOptions['customercredit']) > 0) {
         if (isset($productOptions['configurable']) && count($productOptions['configurable']) > 0) {
             $options = $productOptions['configurable'];
             if (isset($options['price_condition'])) {
                 $priceConditions = $options['price_condition'];
             }
         }
         if (isset($productOptions['custom_options']) && count($productOptions['custom_options']) > 0) {
             $customOptions = $productOptions['custom_options'];
         }
         if (isset($productOptions['grouped']) && count($productOptions['grouped']) > 0) {
             $groupedChilds = $productOptions['grouped'];
             $isGrouped = true;
         }
         if (isset($productOptions['bundle']) && count($productOptions['bundle']) > 0) {
             $bundleChilds = $productOptions['bundle'];
             $isBundle = true;
         }
         if (isset($productOptions['customercredit']) && count($productOptions['customercredit']) > 0) {
             $storeCreditOptions = $productOptions['customercredit'];
         }
         $totalDefault = $store->formatPrice($finalPrice);
         $options_label = 'Select Options';
         $option_value_label = "Price <span finalprice='" . $finalPrice . "' id='totals_price_" . $productId . "' class='bundle_price'>" . $totalDefault . "<span>";
         if (isset($isGrouped) && $isGrouped == true) {
             $options_label = 'Select Child';
             $option_value_label = 'Qty';
         }
         if (isset($isBundle) && $isBundle == true) {
             $totalDefault = 0;
             foreach ($bundleChilds as $childId => $childData) {
                 $items = $childData['items'];
                 if (count($items) > 0) {
                     foreach ($items as $itemId => $itemData) {
                         if ($itemData['is_default'] == '1') {
                             $totalDefault += $itemData['price'] * $itemData['qty'];
                         }
                     }
                 }
             }
             $totalDefault = $store->formatPrice($totalDefault);
             $options_label = 'Select childs';
             $option_value_label = "Price <span finalprice='" . $finalPrice . "' id='totals_price_" . $productId . "' class='bundle_price'>" . $totalDefault . "<span>";
         }
         $html .= "<div class='product_options hide' id='" . $productId . "_options_popup' price_condition='" . $priceConditions . "'>\r\n\t\t\t\t\t\t<ul>\r\n\t\t\t\t\t\t\t<div class='product-name col-lg-12 col-md-12 col-sm-12 col-xs-12' style='padding:0'>\r\n\t\t\t\t\t\t\t\t<h2>" . $productShortName . "<button type='button' class='btn btn-warning' onclick=\"addProductWidthOptions('" . $productId . "','" . $product->getFinalPrice() . "','" . Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(120) . "')\">" . $this->__('Add to Cart') . "</button></h2>\r\n\t\t\t\t\t\t\t</div>\t\t\t\t\t\t\t\t\t  \r\n\t\t\t\t\t\t\t<div class='col-lg-12 col-md-12 col-sm-12 col-xs-12' style='padding:0'>\r\n\t\t\t\t\t\t\t\t<div class='col col-lg-6 col-md-6 col-sm-6 col-xs-6'>\r\n\t\t\t\t\t\t\t\t\t<div class='pospanel panel-default'>\r\n\t\t\t\t\t\t\t\t\t\t<div class='panel-heading'>" . $this->__($options_label) . "</div>\r\n\t\t\t\t\t\t\t\t\t\t\t<div class='options'>\r\n\t\t\t\t\t\t\t\t\t\t\t\t<ul>";
         $countOption = 1;
         if (count($options) > 0) {
             foreach ($options as $optionCode => $optionValues) {
                 if ($optionCode == 'price_condition') {
                     continue;
                 }
                 $optionActive = $countOption == 1 ? 'option_active' : '';
                 $html .= "<li optiontype='configurable' id='" . $productId . "_" . $optionCode . "' onclick=\"showProductOptions('" . $productId . "','" . $optionCode . "')\"  class='" . $productId . "_options_label " . $optionActive . "'>\r\n\t\t\t\t\t\t\t\t<span>" . $optionValues['optionLabel'] . "<span class='required'>*</span></span><span class='glyphicon glyphicon-chevron-right' aria-hidden='true'></span>\r\n\t\t\t\t\t\t\t</li>";
                 $countOption++;
             }
         }
         if (count($customOptions) > 0) {
             foreach ($customOptions as $option) {
                 if ($option['price'] > 0) {
                     if ($option['price_type'] == 'fixed') {
                         $priceFormated = ' +' . $store->formatPrice($option['price']);
                     } else {
                         $priceFormated = ' +' . $store->formatPrice($option['price'] * $product->getFinalPrice() / 100);
                     }
                 } else {
                     $priceFormated = '';
                 }
                 $optionActive = $countOption == 1 ? 'option_active' : '';
                 $optionTitle = $option['is_require'] == '1' ? $option['title'] . "<span class='required'>*</span>" : $option['title'];
                 $html .= "<li optiontype='custom' id='" . $productId . "_co_" . $option['option_id'] . "' onclick=\"showProductOptions('" . $productId . "', '" . $option['option_id'] . "')\" value='" . $productId . "_co_" . $option['option_id'] . "' class='" . $productId . "_options_label " . $optionActive . "'>\r\n\t\t\t\t\t\t\t\t<span>" . $optionTitle . $priceFormated . "</span><span class='glyphicon glyphicon-chevron-right' aria-hidden='true'></span>\r\n\t\t\t\t\t\t\t</li>";
                 $countOption++;
             }
         }
         if (count($groupedChilds) > 0) {
             foreach ($groupedChilds as $childId => $childData) {
                 $optionActive = $countOption == 1 ? 'option_active' : '';
                 $html .= "<li optiontype='grouped' id='" . $productId . "_grouped_" . $childId . "' onclick=\"showProductOptions('" . $productId . "', '" . $childId . "')\" value='" . $productId . "_grouped_" . $childId . "' class='" . $productId . "_options_label grouped_label " . $optionActive . "'>\r\n\t\t\t\t\t<span>" . $childData['name'] . "</span><span class='glyphicon glyphicon-chevron-right' aria-hidden='true'></span>\r\n\t\t\t\t</li>";
                 $countOption++;
             }
         }
         if (count($bundleChilds) > 0) {
             foreach ($bundleChilds as $childId => $childData) {
                 $optionActive = $countOption == 1 ? 'option_active' : '';
                 $childName = $childData['required'] == '1' ? $childData['title'] . "<span class='required'>*</span>" : $childData['title'];
                 $html .= "<li optiontype='bundle' id='" . $productId . "_bundle_" . $childId . "' onclick=\"showProductOptions('" . $productId . "', '" . $childId . "')\" value='" . $productId . "_bundle_" . $childId . "' class='" . $productId . "_options_label bundle_label " . $optionActive . "'>\r\n\t\t\t\t\t<span>" . $childName . "</span><span class='glyphicon glyphicon-chevron-right' aria-hidden='true'></span>\r\n\t\t\t\t</li>";
                 $countOption++;
             }
         }
         if (count($storeCreditOptions) > 0) {
             $optionActive = 'option_active';
             $childName = $this->__('Credit option');
             $html .= "<li optiontype='storecredit' id='" . $productId . "_storecredit_' onclick=\"showProductOptions('" . $productId . "', '')\" value='" . $productId . "_storecredit_' class='" . $productId . "_options_label " . $optionActive . "'>\r\n\t\t\t\t\t<span>" . $childName . "</span><span class='glyphicon glyphicon-chevron-right' aria-hidden='true'></span>\r\n\t\t\t\t</li>";
         }
         $html .= "</ul></div></div></div>\r\n                     <div class='col col-value col-lg-6 col-md-6 col-sm-6 col-xs-6'>\r\n\t\t\t\t\t\t<div class='pospanel panel-default'>\r\n\t\t\t\t\t\t\t<div class='panel-heading'><span>" . $this->__($option_value_label) . "</span></div>\r\n\t\t\t\t\t\t\t\t<div class='options'>";
         $numberOption = 1;
         if (count($options) > 0) {
             foreach ($options as $optionCode => $optionValues) {
                 if ($optionCode == 'price_condition') {
                     continue;
                 }
                 $onlyOption = false;
                 $onlyOptionValue = '';
                 $onlyOptionLabel = '';
                 if (count($optionValues) == 3) {
                     $onlyOption = true;
                     foreach ($optionValues as $optionValue => $optionLabel) {
                         if ($optionValue == 'optionId' || $optionValue == 'optionLabel') {
                             continue;
                         }
                         $onlyOptionValue = $optionValue;
                         $onlyOptionLabel = "optionLabel='" . $optionLabel . "'";
                     }
                 }
                 $hideClass = $numberOption != 1 ? 'hide' : '';
                 $hideOnlyClass = !$onlyOption ? 'hide' : '';
                 $html .= "<ul id='" . $productId . "_" . $optionCode . "_values' class='" . $productId . "_option_values " . $hideClass . "'>\r\n\t\t\t\t\t\t\t\t<input " . $onlyOptionLabel . " type='hidden' optionCode='" . $optionCode . "' optionId='" . $optionValues['optionId'] . "'  id='" . $productId . "_" . $optionCode . "_value' class='input_options input_options_" . $productId . "' value='" . $onlyOptionValue . "'/>";
                 foreach ($optionValues as $optionValue => $optionLabel) {
                     if ($optionValue == 'optionId' || $optionValue == 'optionLabel') {
                         continue;
                     }
                     $html .= "<li onclick=\"selectProductOption('" . $productId . "', '" . $optionCode . "', '" . $optionValue . "', '" . $optionLabel . "')\" value='" . $optionValue . "'>" . $optionLabel . "\r\n\t\t\t\t\t\t\t\t\t<span class='glyphicon glyphicon-ok prd_options_selected_icon prd_options_selected_icon_" . $optionCode . " " . $hideOnlyClass . "' id='" . $product->getId() . "_" . $optionCode . "_" . $optionValue . "_selected_icon'></span>\r\n\t\t\t\t\t\t\t\t\t</li>";
                     $numberOption++;
                 }
                 $html .= "</ul>";
             }
         }
         if (count($customOptions) > 0) {
             foreach ($customOptions as $option) {
                 $hideClass = $numberOption != 1 ? 'hide' : '';
                 $html .= "<ul id='" . $productId . "_co_" . $option['option_id'] . "_values' class='" . $productId . "_option_values custom_options_values  " . $hideClass . "'>\r\n\t\t\t\t\t\t\t\t<li>";
                 $html .= $this->getCustomOptionHtml($option);
                 $html .= "<span class='glyphicon glyphicon-ok prd_options_selected_icon prd_options_selected_icon_" . $optionCode . " hide' id='" . $productId . "_" . $optionCode . "_" . $optionValue . "_selected_icon'></span>\r\n                               </li>\r\n                               </ul>";
                 $numberOption++;
             }
         }
         if (count($storeCreditOptions) > 0) {
             $html .= "<ul id='" . $productId . "_storecredit__values' class='" . $productId . "_option_values custom_options_values '><li>";
             $html .= $this->getStoreCreditOptionHtml($product, $storeCreditOptions);
             $html .= "</li></ul>";
         }
         if (count($groupedChilds) > 0) {
             $hideClass = $numberOption != 1 ? 'hide' : '';
             $html .= "<ul id='" . $productId . "_grouped_qtys' class='" . $productId . "_option_values grouped_childs_qty  " . $hideClass . "'>";
             foreach ($groupedChilds as $childId => $childData) {
                 $html .= "<li class='grouped_qty_area'>\r\n\t\t\t\t\t\t\t\t<p id='prd_fullname_" . $childId . "' class='hide'>" . $childData['name'] . "</p>\r\n\t\t\t\t\t\t\t\t<img id='grouped_child_imgpath_" . $childId . "' src='" . $childData['imgpath'] . "'/>\r\n\t\t\t\t\t\t\t\t<input id='grouped_child_price_" . $childId . "' value='" . $childData['price'] . "' class='hide'/>\r\n\t\t\t\t\t\t\t\t<input value='0' childid='" . $childId . "' class='" . $productId . "_grouped_childs_qty'/>\r\n\t\t\t\t\t\t\t\t<span class='price'>" . Mage::helper('core')->currency($childData['price'], true, false) . "</span>\r\n\t\t\t\t\t\t\t\t<span class='glyphicon glyphicon-ok prd_options_selected_icon prd_options_selected_icon_" . $optionCode . " hide' id='" . $productId . "_" . $optionCode . "_" . $optionValue . "_selected_icon'></span>\r\n\t\t\t\t\t\t\t\t</li>";
                 $numberOption++;
             }
             $html .= "</ul>";
         }
         if (count($bundleChilds) > 0) {
             foreach ($bundleChilds as $childId => $childData) {
                 $hideClass = $numberOption != 1 ? 'hide' : '';
                 $html .= "<ul id='" . $productId . "_bundle_" . $childId . "_values' class='" . $productId . "_option_values bundle_childs_values  " . $hideClass . "'>\r\n\t\t\t\t\t\t\t\t<li>";
                 $html .= $this->getBundleSelectionHtml($childData);
                 $html .= "</li>\r\n                               </ul>";
                 $numberOption++;
             }
         }
         $html .= "</div>\r\n                               </div>\r\n                            </div>\r\n                        </div>\r\n                     </ul>\r\n                 </div>";
         if ($extraClass == '') {
             $html .= "<script type='text/javascript'>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t</script> ";
         }
     }
     $html .= " </div>";
     return $html;
 }
Ejemplo n.º 17
0
 public function importProducts()
 {
     $queue = Mage::getModel('Erply/Queue')->loadActive('erply_product_import');
     $params = array();
     if ($queue) {
         $runEvery = Mage::getStoreConfig('eepohs_erply/queue/run_every', $queue->getStoreId());
         $loops = $queue->getLoopsPerRun();
         $pageSize = $queue->getRecordsPerRun();
         $recordsLeft = $queue->getTotalRecords() - $pageSize * $queue->getLastPageNo();
         if ($queue->getChangedSince()) {
             $params = array('changedSince' => $queue->getChangedSince());
         }
         if ($loops * $pageSize > $recordsLeft) {
             $loops = ceil($recordsLeft / $pageSize);
             $queue->setStatus(0);
         } else {
             $thisRunTime = strtotime($queue->getScheduledAt());
             $newRunTime = strtotime('+' . $runEvery . 'minute', $thisRunTime);
             $scheduleDateTime = date('Y-m-d H:i:s', $newRunTime);
             Mage::getModel('Erply/Cron')->addCronJob('erply_product_import', $scheduleDateTime);
             $queue->setScheduledAt($scheduleDateTime);
         }
         $loops--;
         $firstPage = $queue->getLastPageNo() + 1;
         $queue->setLastPageNo($firstPage + $loops);
         $queue->setUpdatedAt(date('Y-m-d H:i:s', time()));
         $queue->save();
         $this->verifyUser($queue->getStoreId());
         $store = Mage::getModel('core/store')->load($queue->getStoreId());
         for ($i = $firstPage; $i <= $firstPage + $loops; $i++) {
             $parameters = array_merge(array('recordsOnPage' => $pageSize, 'pageNo' => $i), $params);
             Mage::helper('Erply')->log("Erply request: ");
             Mage::helper('Erply')->log($parameters);
             $result = $this->sendRequest('getProducts', $parameters);
             $return = "";
             Mage::helper('Erply')->log("Erply product import:");
             Mage::helper('Erply')->log($result);
             $output = json_decode($result, true);
             $start = time();
             foreach ($output["records"] as $_product) {
                 if ($_product["code2"]) {
                     $sku = $_product["code2"];
                 } elseif ($_product["code"]) {
                     $sku = $_product["code"];
                 } else {
                     $sku = $_product["code3"];
                 }
                 $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
                 if (!$product) {
                     $product = Mage::getModel('catalog/product')->load($_product["productID"]);
                     if (!$product->getName()) {
                         $product = new Mage_Catalog_Model_Product();
                         $product->setId($_product["productID"]);
                         Mage::helper('Erply')->log("Creating new product: " . $_product["productID"]);
                     } else {
                         Mage::helper('Erply')->log("Editing old product: " . $_product["productID"]);
                     }
                 }
                 // product does not exist so we will be creating a new one.
                 $product->setIsMassupdate(true);
                 $product->setExcludeUrlRewrite(true);
                 $product->setTypeId('simple');
                 $product->setWeight(1.0);
                 $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
                 $product->setStatus(1);
                 $product->setSku($sku);
                 $product->setTaxClassId(0);
                 //                    if (Mage::app()->isSingleStoreMode()) {
                 //                        $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsiteId()));
                 //                    }
                 //                    else {
                 //                        $product->setWebsiteIds(array(Mage::getModel('core/store')->load($queue->getStoreId())->getWebsiteId()));
                 //                    }
                 //                    $product->setStoreIDs(array($queue->getStoreId()));  // your store ids
                 //                    $product->setStockData(array(
                 //                        'is_in_stock' => 1,
                 //                        'qty' => 99999,
                 //                        'manage_stock' => 0,
                 //                    ));
                 // set the rest of the product information here that can be set on either new/update
                 $product->setAttributeSetId(4);
                 // the product attribute set to use
                 $product->setName($_product["name"]);
                 $product->setCategoryIds(array($_product["groupID"]));
                 // array of categories it will relate to
                 if (Mage::app()->isSingleStoreMode()) {
                     $product->setWebsiteIds(array(Mage::app()->getStore($queue->getStoreId())->getWebsiteId()));
                 } else {
                     $product->setWebsiteIds(array($store->getWebsiteId()));
                 }
                 $product->setDescription($_product["longdesc"]);
                 $product->setShortDescription($_product["description"]);
                 $product->setPrice($_product["price"]);
                 // set the product images as such
                 // $image is a full path to the image. I found it to only work when I put all the images I wanted to import into the {magento_path}/media/catalog/products - I just created my own folder called import and it read from those images on import.
                 //        $image = '/path/to/magento/media/catalog/products/import/image.jpg';
                 //
                 //        $product->setMediaGallery (array('images'=>array (), 'values'=>array ()));
                 //        $product->addImageToMediaGallery ($image, array ('image'), false, false);
                 //        $product->addImageToMediaGallery ($image, array ('small_image'), false, false);
                 //        $product->addImageToMediaGallery ($image, array ('thumbnail'), false, false);
                 // setting custom attributes. for example for a custom attribute called special_attribute
                 // special_attribute will be used on all examples below for the various attribute types
                 //$product->setSpecialAttribute('value here');
                 // setting a Yes/No Attribute
                 //        $product->setSpecialField(1);
                 // setting a Selection Attribute
                 //$product->setSpecialAttribute($idOfAttributeOption); //specify the ID of the attribute option, eg you creteated an option called Blue in special_attribute it was assigned an ID of some number. Use that number.
                 // setting a Mutli-Selection Attribute
                 //$data['special_attribute'] = '101 , 102 , 103'; // coma separated string of option IDs. As ID , ID (mind the spaces before and after coma, it worked for me like that)
                 //        $product->setData($data);
                 $product->save();
                 Mage::helper('Erply')->log("Added: " . $product->getSku());
             }
             unset($output);
         }
     }
 }
 /**
  * given a DOMNodeList and a Mage_Catalog_Model_Product make sure this is
  * a product of type configurable and then extract the configurable attribute from the node list
  * then get the configurable attribute array for each configured attributes
  * @param DOMNOdeList $nodes the node with configurableAttributes data
  * @param Mage_Catalog_Model_Product $product
  * @return array | null an array of configurable attribute data if the given product is configurable otherwise null
  */
 public function extractConfigurableAttributesData(DOMNodeList $nodes, Mage_Catalog_Model_Product $product)
 {
     // We are ensuring that the given product is a parent configurable product by first checking if the product sku
     // doesn't match the product style id. If this condition is met then we know we have a child product and we won't
     // proceed otherwise we know we have a parent product and proceed continue.
     if ($product->getSku() !== $this->_normalizeStyleId($product->getStyleId())) {
         return null;
     }
     $typeInstance = $product->getTypeInstance(true);
     // making sure the right type instance is set on the product
     if (!$typeInstance instanceof Mage_Catalog_Model_Product_Type_Configurable) {
         $product->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)->setTypeInstance(Mage_Catalog_Model_Product_Type::factory($product, true), true);
     }
     $data = null;
     // purposely setting this to null just in cause all the attribute already exists
     // we need to know which configurable attribute we already have for this product
     // so that we don't try to create the same super attribute relationship which will
     // cause unique key duplication SQL constraint to be thrown
     $existedData = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
     foreach (explode(',', strtolower(Mage::helper('eb2ccore')->extractNodeVal($nodes))) as $attributeCode) {
         // if we don't currently have a super attribute relationship then get the
         // configurable attribute data
         if (!$this->_isSuperAttributeExists($existedData, $attributeCode) && $this->_isAttributeInSet($attributeCode, $product)) {
             $data[] = $this->_getConfiguredAttributeData($attributeCode);
         }
     }
     // At this point we know we are dealing with a configurable product; therefore,
     // this is the right place to make sure manage stock get turn off.
     $this->_turnOffManageStock($product);
     return $data;
 }
Ejemplo n.º 19
0
 /**
  * Returns product SKU for specified options set
  * @param Mage_Catalog_Model_Product $Product
  * @param mixed                      $options
  * @return string
  */
 public function getProductSku(Mage_Catalog_Model_Product $Product, $options = null)
 {
     if ($options) {
         $productOptions = $Product->getOptions();
         foreach ($options as $option) {
             if ($ProductOption = @$productOptions[$option['option_id']]) {
                 $values = $ProductOption->getValues();
                 if (($value = $values[$option['option_value']]) && $value->getSku()) {
                     return $value->getSku();
                 }
             }
         }
     }
     return $Product->getSku();
 }
Ejemplo n.º 20
0
 /**
  * @param Mage_Catalog_Model_Product $product
  * @return array
  */
 protected function _createSkus(Mage_Catalog_Model_Product $product)
 {
     $base_skus = array();
     if ($product->isConfigurable()) {
         /** @var $type Mage_Catalog_Model_Product_Type_Configurable */
         $type = $product->getTypeInstance();
         $attributeCodes = array();
         foreach ($type->getConfigurableAttributesAsArray() as $value) {
             //                Mage::log('attributes configurable: ' . print_r($value, true), null, 'debug.log', true);
             //                Mage::log('attribute_code: ' . $value['attribute_code'], null, 'debug.log', true);
             $attributeCodes[] = array('code' => $value['attribute_code'], 'label' => $value['label'], 'id' => $value['attribute_id']);
             foreach ($value['values'] as $val) {
                 //                    Mage::log('store_label: ' . $val['store_label'], null, 'debug.log', true);
             }
         }
         $groups = $type->getChildrenIds($product->getId());
         //            Mage::log("groups: " . print_r($groups, true), null, 'debug.log', true);
         foreach ($groups as $group) {
             foreach ($group as $childId) {
                 /** @var $childProduct Mage_Catalog_Model_Product */
                 $childProduct = Mage::getModel('catalog/product')->load($childId);
                 $attributes = array();
                 foreach ($attributeCodes as $array) {
                     //                        $attributes[$array['code']] = array('value' => $childProduct->getAttributeText($array['code']),
                     //                            'name'  => $array['label']);
                     $attributes[] = $childProduct->getTypeInstance(true)->getAttributeById($array['id'], $childProduct);
                 }
                 $attributes = $this->_createAttributes($childProduct, $attributes);
                 $base_skus[] = array('sku' => $childProduct->getSku(), 'attributes' => $attributes);
             }
         }
     } else {
         $base_skus[] = array('sku' => $product->getSku());
     }
     $stack = array($base_skus);
     //        Mage::log(print_r($stack, true), null, 'debug.log', true);
     $skus = $this->_findAllSkus($stack);
     //        Mage::log(print_r($skus, true), null, 'debug.log', true);
     // TODO: Need to test this case again
     //        $sku = $product->getSku();
     //        if(!isset($sku)) {
     //            return array();
     //        }
     $data = array();
     foreach ($skus as $node) {
         $sku = $node['sku'];
         $attributes = $node['attributes'];
         $data[] = $this->_createSku($sku, $attributes);
     }
     return $data;
 }
 /**
  * extracting image data from a given Mage_Catalog_Model_Product object
  * @param Mage_Catalog_Model_Product $product
  * @return array | null
  */
 protected function _extractImageData(Mage_Catalog_Model_Product $product)
 {
     $media = $product->getMediaGalleryImages();
     return $media && $media->count() ? ['id' => $product->getSku(), 'image_data' => $this->_getMediaData($media, $product)] : null;
 }
Ejemplo n.º 22
0
 public function importProducts($products, $storeId, $store)
 {
     Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
     if (!empty($products)) {
         foreach ($products as $_product) {
             $update = false;
             if ($_product["code"]) {
                 $sku = $_product["code"];
             } elseif ($_product["code2"]) {
                 $sku = $_product["code2"];
             } else {
                 $sku = $_product["code3"];
             }
             $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
             if (!$product) {
                 $product = Mage::getModel('catalog/product')->load($_product["productID"]);
                 if (!$product->getName()) {
                     $product = new Mage_Catalog_Model_Product();
                     $product->setId($_product["productID"]);
                     Mage::helper('Erply')->log("Creating new product: " . $_product["productID"]);
                 } else {
                     Mage::helper('Erply')->log("Editing old product: " . $_product["productID"]);
                     $update = true;
                 }
             } else {
                 $update = true;
             }
             if ($_product["displayedInWebshop"] == 0) {
                 if ($update) {
                     try {
                         $product->delete();
                         Mage::helper('Erply')->log("Delete existing product which should be in webshop id: " . $_product["productID"] . " - sku: " . $sku);
                     } catch (Exception $e) {
                         Mage::helper('Erply')->log("Failed to delete product with message: " . $e->getMessage());
                     }
                 }
                 continue;
             }
             $product->setStoreId($storeId);
             // product does not exist so we will be creating a new one.
             $product->setIsMassupdate(true);
             $product->setExcludeUrlRewrite(true);
             $product->setTypeId('simple');
             $product->setWeight(1.0);
             $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
             $product->setStatus(1);
             $product->setSku($sku);
             $product->setTaxClassId(0);
             // set the rest of the product information here that can be set on either new/update
             if (!$update) {
                 $product->setAttributeSetId((int) Mage::getStoreConfig('eepohs_erply/product/attribute_set', $storeId));
                 // the product attribute set to use
             }
             $product->setName($_product["name"]);
             $category = Mage::getModel('catalog/category')->load($_product["groupID"]);
             if ($category->getName()) {
                 $product->setCategoryIds(array($_product["groupID"]));
                 // array of categories it will relate to
             }
             if (Mage::app()->isSingleStoreMode()) {
                 $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsiteId()));
             } else {
                 $product->setWebsiteIds(array($store->getWebsiteId()));
             }
             $product->setBatchPrices(array());
             $product->setStockPriorities(array());
             //$product->setPrice($_product["price"]);
             // set the product images as such
             // $image is a full path to the image. I found it to only work when I put all the images I wanted to import into the {magento_path}/media/catalog/products - I just created my own folder called import and it read from those images on import.
             //        $image = '/path/to/magento/media/catalog/products/import/image.jpg';
             //
             //        $product->setMediaGallery (array('images'=>array (), 'values'=>array ()));
             //        $product->addImageToMediaGallery ($image, array ('image'), false, false);
             //        $product->addImageToMediaGallery ($image, array ('small_image'), false, false);
             //        $product->addImageToMediaGallery ($image, array ('thumbnail'), false, false);
             // setting custom attributes. for example for a custom attribute called special_attribute
             // special_attribute will be used on all examples below for the various attribute types
             //$product->setSpecialAttribute('value here');
             // setting a Yes/No Attribute
             //        $product->setSpecialField(1);
             // setting a Selection Attribute
             //$product->setSpecialAttribute($idOfAttributeOption); //specify the ID of the attribute option, eg you creteated an option called Blue in special_attribute it was assigned an ID of some number. Use that number.
             // setting a Mutli-Selection Attribute
             //$data['special_attribute'] = '101 , 102 , 103'; // coma separated string of option IDs. As ID , ID (mind the spaces before and after coma, it worked for me like that)
             //        $product->setData($data);
             if (isset($_product["attributes"])) {
                 $erplyAttributes = $_product["attributes"];
                 $mapping = unserialize(Mage::getStoreConfig('eepohs_erply/product/attributes', $storeId));
                 if (!empty($erplyAttributes) && !empty($mapping)) {
                     $mappings = array();
                     foreach ($mapping as $map) {
                         $mappings[$map["erply_attribute"]] = $map["magento_attribute"];
                     }
                     foreach ($erplyAttributes as $attribute) {
                         if (in_array($attribute["attributeName"], array_keys($mappings))) {
                             if ($attribute["attributeValue"]) {
                                 $product->setData($mappings[$attribute["attributeName"]], $attribute["attributeValue"]);
                             }
                         }
                     }
                 }
             }
             $product->save();
             Mage::helper('Erply')->log("Added: " . $product->getSku());
         }
     }
 }
 /**
  * Simple product that needs to be added as a configuration to a configurable product.
  * @param Mage_Catalog_Model_Product $product Simple product used to configure a configurable product.
  * @return $this object
  */
 protected function _addToConfigurableProduct(Mage_Catalog_Model_Product $product)
 {
     $configurableProduct = null;
     $styleId = $this->_helper->normalizeSku($product->getStyleId(), $this->_config->catalogId);
     foreach ($this->_products as $collectionProduct) {
         if ($collectionProduct->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE && $collectionProduct->getSku() === $styleId) {
             $configurableProduct = $collectionProduct;
             break;
         }
     }
     if ($configurableProduct) {
         $usedProductIds = $configurableProduct->getTypeInstance()->getUsedProductIds();
         $usedProductIds[] = $product->getId();
         // save the configurable product links
         Mage::getResourceModel('catalog/product_type_configurable')->saveProducts($configurableProduct, array_unique($usedProductIds));
         $configurableProduct->setData(self::USED_PRODUCT_IDS_PROPERTY, $usedProductIds)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
     } else {
         // @todo put in error confirmation feed
         $logData = ['style_id' => $product->getStyleId(), 'sku' => $product->getSku()];
         $logMessage = 'No configurable product with SKU "{style_id}" found for used product with SKU "{sku}".';
         $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData));
     }
     return $this;
 }
 public function __construct(Mage_Catalog_Model_Product $product)
 {
     $this->id = $product->getId();
     $this->sku = $product->getSku();
     $this->name = $product->getName();
     $statuses = Mage::getModel('catalog/product_status')->getOptionArray();
     $this->status = $statuses[$product->getStatus()];
     $options = Mage::getModel('catalog/product_visibility')->getOptionArray();
     $this->visibility = $options[$product->getVisibility()];
     $this->price = (double) number_format($product->getPrice(), 2, '.', '');
     $this->specialPrice = (double) number_format($product->getSpecialPrice(), 2, '.', '');
     $this->url = $product->getProductUrl();
     $this->imagePath = Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getSmallImage());
     $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
     $this->stock = (double) number_format($stock->getQty(), 2, '.', '');
     $short_description = $product->getShortDescription();
     //limit short description
     if (strlen($short_description) > 250) {
         $short_description = substr($short_description, 0, 250);
     }
     $this->short_description = $short_description;
     //category data
     $count = 0;
     $categoryCollection = $product->getCategoryCollection()->addNameToResult();
     foreach ($categoryCollection as $cat) {
         $this->categories[$count]['Id'] = $cat->getId();
         $this->categories[$count]['Name'] = $cat->getName();
         $count++;
     }
     //website data
     $count = 0;
     $websiteIds = $product->getWebsiteIds();
     foreach ($websiteIds as $websiteId) {
         $website = Mage::app()->getWebsite($websiteId);
         $this->websites[$count]['Id'] = $website->getId();
         $this->websites[$count]['Name'] = $website->getName();
         $count++;
     }
     //bundle product options
     if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
         $optionCollection = $product->getTypeInstance()->getOptionsCollection();
         $selectionCollection = $product->getTypeInstance()->getSelectionsCollection($product->getTypeInstance()->getOptionsIds());
         $options = $optionCollection->appendSelections($selectionCollection);
         foreach ($options as $option) {
             $count = 0;
             $title = str_replace(' ', '', $option->getDefaultTitle());
             $selections = $option->getSelections();
             $sOptions = array();
             foreach ($selections as $selection) {
                 $sOptions[$count]['name'] = $selection->getName();
                 $sOptions[$count]['sku'] = $selection->getSku();
                 $sOptions[$count]['id'] = $selection->getProductId();
                 $sOptions[$count]['price'] = (double) number_format($selection->getPrice(), 2, '.', '');
                 $count++;
             }
             $this->{$title} = $sOptions;
         }
     }
     //configurable product options
     if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
         $productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
         foreach ($productAttributeOptions as $productAttribute) {
             $count = 0;
             $label = strtolower(str_replace(' ', '', $productAttribute['label']));
             $options = array();
             foreach ($productAttribute['values'] as $attribute) {
                 $options[$count]['option'] = $attribute['default_label'];
                 $options[$count]['price'] = (double) number_format($attribute['pricing_value'], 2, '.', '');
                 $count++;
             }
             $this->{$label} = $options;
         }
     }
 }
Ejemplo n.º 25
0
 /**
  * @see Mage_Catalog_Model_Product_Type_SimpleTest
  */
 public function testGetSku()
 {
     $this->assertEmpty($this->_model->getSku());
     $this->_model->setSku('sku');
     $this->assertEquals('sku', $this->_model->getSku());
 }
 public function action(Mage_Catalog_Model_Product $product, $action = self::SYNC_ACTION_INSERT)
 {
     $this->getQueue()->send(Zend_Json::encode(array('action' => $action, 'website_id' => $product->getWebsiteId(), 'plant_id' => $this->getHelper()->getPlantId(), 'deposit_number' => $this->getHelper()->getDepositorNumber(), 'product_id' => $product->getId(), 'product_sku' => $product->getSku(), 'product_weight' => $product->getWeight(), 'product_name' => $product->getName(), 'product_length' => $product->getData('yc_dimension_length'), 'product_width' => $product->getData('yc_dimension_width'), 'product_height' => $product->getData('yc_dimension_height'), 'product_uom' => $product->getData('yc_dimension_uom'), 'product_volume' => $product->getData('yc_dimension_height') * $product->getData('yc_dimension_length') * $product->getData('yc_dimension_width'), 'tara_factor' => Mage::getStoreConfig(Swisspost_YellowCube_Helper_Data::CONFIG_TARA_FACTOR, Mage::app()->getWebsite($product->getWebsiteId())->getDefaultStore()->getId()), 'product_ean' => $product->getData('yc_ean_code'), 'product_ean_type' => $product->getData('yc_ean_type'), 'product_lot_management' => $product->getData('yc_requires_lot_management'))));
     return $this;
 }
Ejemplo n.º 27
0
 public function getProductEntity(Mage_Catalog_Model_Product $product, $storeId, $includeExtras = true)
 {
     $result = array();
     $result['entity_id'] = $product->getEntityId();
     $result['sku'] = $product->getSku();
     $result['name'] = $product->getName();
     $result['price'] = $product->getPrice();
     $result['special_price'] = $product->getSpecialPrice();
     $result['special_from_date'] = $product->getSpecialFromDate();
     $result['special_to_date'] = $product->getSpecialToDate();
     $result['cost'] = $product->getCost();
     $result['description'] = $product->getDescription();
     $result['short_description'] = $product->getShortDescription();
     $result['weight'] = $product->getWeight();
     if ($product->isVisibleInSiteVisibility()) {
         $result['url_path'] = $this->_getProductUrlWithCache($product);
     }
     $parentProduct = $this->_getParentProduct($product);
     if ($parentProduct != null) {
         $result['parent_id'] = $parentProduct->getEntityId();
         $result['parent_sku'] = $parentProduct->getSku();
         if (!$product->isVisibleInSiteVisibility()) {
             $result['name'] = $parentProduct->getName();
             if ($parentProduct->isVisibleInSiteVisibility()) {
                 $result['url_path'] = $this->_getProductUrlWithCache($parentProduct);
             }
         }
         if ($includeExtras && Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE == $parentProduct->getTypeId()) {
             $result['purchasable'] = $this->_isPurchasable($product, $parentProduct);
             $attributes = $parentProduct->getTypeInstance(true)->getUsedProductAttributes($parentProduct);
             $freshProduct = null;
             foreach ($attributes as $attribute) {
                 if (!array_key_exists('configurable_attributes', $result)) {
                     $result['configurable_attributes'] = array();
                 }
                 $attr = array();
                 $attr['attribute_name'] = $attribute->getFrontend()->getLabel();
                 $attr['value'] = $product->getAttributeText($attribute->getAttributeCode());
                 if (empty($attr['value'])) {
                     // use the EAV tables only if the flat table doesn't work
                     if ($freshProduct == null) {
                         $freshProduct = Mage::getModel('catalog/product')->load($product->getEntityId());
                     }
                     $attr['value'] = $attribute->getFrontend()->getValue($freshProduct);
                 }
                 $result['configurable_attributes'][] = $attr;
             }
         }
     }
     if (!isset($result['purchasable'])) {
         $result['purchasable'] = $this->_isPurchasable($product);
     }
     $images = $this->_getProductImages($product);
     if (isset($images['image'])) {
         $result['image'] = $images['image'];
     }
     if (isset($images['small_image'])) {
         $result['small_image'] = $images['small_image'];
     }
     if (isset($images['thumbnail'])) {
         $result['thumbnail'] = $images['thumbnail'];
     }
     if ($includeExtras) {
         // Metas
         $metas = $this->_getMetas($storeId, $product, $parentProduct);
         if ($metas != null) {
             //if(isset($metas['meta1'])) $result['meta1'] = $metas['meta1'];
             //if(isset($metas['meta2'])) $result['meta2'] = $metas['meta2'];
             //if(isset($metas['meta3'])) $result['meta3'] = $metas['meta3'];
             //if(isset($metas['meta4'])) $result['meta4'] = $metas['meta4'];
             if (isset($metas['meta5'])) {
                 $result['meta5'] = $metas['meta5'];
             }
         }
         //Custom For ST Bernard Sports
         // Set IsNew Flag if product is less then 45 days old.
         $result['meta4'] = strtotime($product->getCreatedAt()) + 45 * 24 * 60 * 60 < time() ? "False" : "True";
         // Brand and Category
         $brandAndCategoryProduct = !$parentProduct || $product->isVisibleInSiteVisibility() ? $product : $parentProduct;
         $setSettings = $this->_getProductAttributeSetSettings($brandAndCategoryProduct);
         if ($setSettings['brandAttribute'] != null) {
             $result['brand'] = $brandAndCategoryProduct->getAttributeText($setSettings['brandAttribute']);
         }
         if ($setSettings['catFromMagento']) {
             $cats = $this->_getCategoryInformation($storeId, $brandAndCategoryProduct);
             if (isset($cats['category'])) {
                 $result['category'] = $cats['category'];
             }
             if (isset($cats['sub_category'])) {
                 $result['sub_category'] = $cats['sub_category'];
             }
             //Custom For ST Bernard Sports
             if (isset($cats['third_category'])) {
                 $result['meta3'] = $cats['third_category'];
             }
         } else {
             if ($setSettings['catFromAttributes']) {
                 if ($setSettings['categoryAttribute'] != null) {
                     $result['category'] = $brandAndCategoryProduct->getAttributeText($setSettings['categoryAttribute']);
                 }
                 if ($setSettings['subcategoryAttribute'] != null) {
                     $result['sub_category'] = $brandAndCategoryProduct->getAttributeText($setSettings['subcategoryAttribute']);
                 }
             }
         }
         // Inventory
         $result['in_stock'] = $product->isAvailable() ? "true" : "false";
         $stockItem = $product->getStockItem();
         if ($stockItem) {
             $result['qty_on_hand'] = $stockItem->getStockQty();
         }
         // Related Products
         $result['links'] = $this->_getProductLinks($product);
     }
     $result['type'] = $product->getTypeId();
     return $result;
 }
Ejemplo n.º 28
0
 /**
  * Inflate an API object from a product object
  *
  * @param Mage_Catalog_Model_Product $product       Product
  * @param int                        $storeId       Magento store ID
  * @param bool                       $includeExtras Retrieve all information
  *
  * @return array
  */
 public function getProductEntity(Mage_Catalog_Model_Product $product, $storeId, $includeExtras = true)
 {
     $result = array();
     $result['entity_id'] = $product->getEntityId();
     $result['sku'] = $product->getSku();
     $result['name'] = $product->getName();
     $result['price'] = $product->getPrice();
     $result['special_price'] = $product->getSpecialPrice();
     $result['special_from_date'] = $product->getSpecialFromDate();
     $result['special_to_date'] = $product->getSpecialToDate();
     $result['cost'] = $product->getCost();
     $result['description'] = $product->getDescription();
     $result['short_description'] = $product->getShortDescription();
     $result['weight'] = $product->getWeight();
     if ($product->isVisibleInSiteVisibility()) {
         $result['url_path'] = $this->_getProductUrlWithCache($product);
     }
     $parentProduct = $this->_getParentProduct($product);
     if ($parentProduct != null) {
         $result['parent_id'] = $parentProduct->getEntityId();
         $result['parent_sku'] = $parentProduct->getSku();
         if (!$product->isVisibleInSiteVisibility()) {
             $result['name'] = $parentProduct->getName();
             if ($parentProduct->isVisibleInSiteVisibility()) {
                 $result['url_path'] = $this->_getProductUrlWithCache($parentProduct);
             }
         }
         if ($includeExtras && $this->_isConfigurableProduct($parentProduct)) {
             $result['purchasable'] = $this->_isPurchasable($product, $parentProduct);
             /* @var Mage_Catalog_Model_Product_Type_Configurable $typeInst */
             $typeInst = $parentProduct->getTypeInstance(true);
             $attributes = $typeInst->getUsedProductAttributes($parentProduct);
             /* @var Mage_Eav_Model_Entity_Attribute_Abstract $attribute */
             foreach ($attributes as $attribute) {
                 if (!array_key_exists('configurable_attributes', $result)) {
                     $result['configurable_attributes'] = array();
                 }
                 $result['configurable_attributes'][] = array('attribute_name' => $attribute->getAttributeCode());
             }
         }
     }
     if (!isset($result['purchasable'])) {
         $result['purchasable'] = $this->_isPurchasable($product);
     }
     $images = $this->_getProductImages($product);
     if (isset($images['image'])) {
         $result['image'] = $images['image'];
     }
     if (isset($images['small_image'])) {
         $result['small_image'] = $images['small_image'];
     }
     if (isset($images['thumbnail'])) {
         $result['thumbnail'] = $images['thumbnail'];
     }
     if ($includeExtras) {
         $metas = $this->_getMetas($storeId, $product, $parentProduct);
         if ($metas != null) {
             /*if (isset($metas['meta3'])) {
                   $result['meta3'] = $metas['meta3'];
               }*/
             if (isset($metas['meta4'])) {
                 $result['meta4'] = $metas['meta4'];
             }
             if (isset($metas['meta5'])) {
                 $result['meta5'] = $metas['meta5'];
             }
         }
         //Custom for Sportys
         $stores = array();
         foreach ($product->getStoreIds() as $storeID) {
             $store = Mage::getModel('core/store')->load($storeID);
             $stores[] = $store->getCode();
         }
         $result["meta3"] = implode(',', $stores);
         // Brand and Category
         $brandCatProduct = $product;
         if ($parentProduct && !$product->isVisibleInSiteVisibility()) {
             $brandCatProduct = $parentProduct;
         }
         $setSettings = $this->_getProductAttributeSetSettings($brandCatProduct);
         if ($setSettings['brandAttribute'] != null) {
             $result['brand'] = $this->_getProductAttribute($brandCatProduct, $setSettings['brandAttribute']);
         }
         if ($setSettings['catFromMagento']) {
             $cats = $this->_getCategoryInformation($storeId, $brandCatProduct);
             if (isset($cats['category'])) {
                 $result['category'] = $cats['category'];
             }
             if (isset($cats['sub_category'])) {
                 $result['sub_category'] = $cats['sub_category'];
             }
         } else {
             if ($setSettings['catFromAttributes']) {
                 if ($setSettings['categoryAttribute'] != null) {
                     $result['category'] = $this->_getProductAttribute($brandCatProduct, $setSettings['categoryAttribute']);
                 }
                 if ($setSettings['subcategoryAttribute'] != null) {
                     $result['sub_category'] = $this->_getProductAttribute($brandCatProduct, $setSettings['subcategoryAttribute']);
                 }
             }
         }
         $result['attributes'] = $this->_getProductAttributes($product);
         // Inventory
         $result['in_stock'] = $product->isAvailable() ? "true" : "false";
         /* @var Mage_Cataloginventory_Model_Stock_Item $stockItem */
         $stockItem = $product->getStockItem();
         if ($stockItem) {
             $result['qty_on_hand'] = $stockItem->getStockQty();
         }
         // Related Products
         $result['links'] = $this->_getProductLinks($product);
     }
     $result['type'] = $product->getTypeId();
     return $result;
 }
 /**
  * @param Mage_Catalog_Model_Product $product
  * @return array
  */
 public function getProductData(Mage_Catalog_Model_Product $product)
 {
     $id = $product->getId();
     if (!$this->helper()->shouldUseRealProductId()) {
         $id = $product->getSku() ? $product->getSku() : md5($id);
     }
     $data = array('id' => $id, 'url' => $product->getProductUrl(), 'name' => $product->getName(), 'unit_price' => (double) $product->getPrice(), 'unit_sale_price' => (double) $product->getFinalPrice(), 'currency' => $this->_getCurrency(), 'description' => strip_tags($product->getShortDescription()), 'sku_code' => $product->getSku());
     if ($this->helper()->shouldShowProductStockInfo()) {
         $data['stock'] = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();
     }
     $catIndex = $catNames = array();
     $limit = 2;
     $k = 0;
     foreach ($product->getCategoryIds() as $catId) {
         if (++$k > $limit) {
             break;
         }
         if (!isset($catIndex[$catId])) {
             $catIndex[$catId] = Mage::getModel('catalog/category')->load($catId);
         }
         $catNames[] = $catIndex[$catId]->getName();
     }
     if (isset($catNames[0])) {
         $data['category'] = $catNames[0];
     }
     if (isset($catNames[1])) {
         $data['subcategory'] = $catNames[1];
     }
     return $data;
 }
 /**
  * Get an item in the collection for the given product using the sku
  * of the product and the configured client id and catalog id for the store
  * the product was loaded within the context of.
  * @param  Mage_Catalog_Model_Product $product
  * @return EbayEnterprise_Catalog_Model_Pim_Product
  */
 public function getItemForProduct(Mage_Catalog_Model_Product $product)
 {
     $cfg = Mage::helper('eb2ccore')->getConfigModel($product->getStore());
     return $this->getItemById($this->_formatId($product->getSku(), $cfg->clientId, $cfg->catalogId));
 }