protected function getProductIdentifiers(ShopgateOrderItem $item) { return explode('_', Tools::substr($item->getItemNumber(), Tools::strlen(self::prefix))); }
/** * @see http://inchoo.net/ecommerce/magento/programatically-add-bundle-product-to-cart-n-magento/ * * @param ShopgateOrderItem $item * @param Mage_Catalog_Model_Product $product * @param int $stackQuantity * * @return Varien_Object */ protected function _createQuoteItemBuyInfo($item, $product, $stackQuantity) { $orderInfo = $item->getInternalOrderInfo(); $orderInfo = $this->jsonDecode($orderInfo, true); $buyInfo = array('qty' => $item->getQuantity() * $stackQuantity, 'product' => $product->getId()); if (isset($orderInfo["options"])) { $buyInfo['super_attribute'] = $orderInfo["options"]; } if ($item->getOptions()) { if ($orderInfo["item_type"] == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) { foreach ($item->getOptions() as $orderOption) { /* @var $orderOption ShopgateOrderItemOption */ $optionId = $orderOption->getOptionNumber(); $value = $orderOption->getValueNumber(); if (self::GIFT_WRAP_OPTION_ID === $optionId && 0 < $value) { $buyInfo[self::GIFT_WRAP_OPTION_ID] = array('id' => $value, 'price' => $orderOption->getAdditionalAmountWithTax()); continue; } /** @var Mage_Catalog_Model_Product_Option $productOption */ $productOption = Mage::getModel("bundle/option")->load($optionId); if (!$productOption->getId() || $productOption->getId() && $productOption->getParentId() != $product->getId()) { /** @var Mage_Catalog_Model_Product_Option $productOption */ $productOption = Mage::getModel("catalog/product_option")->load($optionId); if ($productOption->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX || $productOption->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE) { if ($value == 0) { continue; } $value = array($value); } $buyInfo["options"][$optionId] = $value; } else { if ($productOption->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX || $productOption->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE) { if (!$value) { continue; } $value = array($value); } /** @var Mage_Bundle_Model_Selection $bundleSelection */ $bundleSelection = Mage::getModel("bundle/selection")->load($value); $buyInfo["bundle_option_qty"][$optionId] = max(1, (int) $bundleSelection->getSelectionQty()); $buyInfo["bundle_option"][$optionId] = $value; } } } else { foreach ($item->getOptions() as $orderOption) { /* @var $orderOption ShopgateOrderItemOption */ $optionId = $orderOption->getOptionNumber(); $value = $orderOption->getValueNumber(); if (self::GIFT_WRAP_OPTION_ID === $optionId && 0 < $value) { $buyInfo[self::GIFT_WRAP_OPTION_ID] = array('id' => $value, 'price' => $orderOption->getAdditionalAmountWithTax()); continue; } /** @var Mage_Catalog_Model_Product_Option $productOption */ $productOption = Mage::getModel("catalog/product_option")->load($optionId); if ($productOption->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX || $productOption->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE) { if ($value == "0") { continue; } $value = array($value); } $buyInfo["options"][$optionId] = $value; } } } if ($item->getInputs()) { foreach ($item->getInputs() as $orderInput) { /* @var $orderInput ShopgateOrderItemInput */ $optionId = $orderInput->getInputNumber(); $value = $orderInput->getUserInput(); $buyInfo["options"][$optionId] = $value; } } $obj = new Varien_Object($buyInfo); return $obj; }
public function visitOrderItem(ShopgateOrderItem $i) { // get properties $properties = $i->buildProperties(); // iterate the simple variables $properties = $this->iterateSimpleProperties($properties); // iterate options/attributes/input fields objects $properties['options'] = $this->iterateObjectList($properties['options']); $properties['inputs'] = $this->iterateObjectList($properties['inputs']); $properties['attributes'] = $this->iterateObjectList($properties['attributes']); // set last value to converted array $this->array = $properties; }
/** * @param ShopgateOrderItem $item * * @return array */ public static function getProductIdentifiers(ShopgateOrderItem $item) { return Tools::substr($item->getItemNumber(), 0, 2) == ShopgatePluginPrestashop::PREFIX ? explode('-', Tools::substr($item->getItemNumber(), Tools::strlen(ShopgatePluginPrestashop::PREFIX))) : explode('-', $item->getItemNumber()); }