public function add($order_id, $upsell_id, $answer, $step) { // make sure we have a proper answer if (!in_array($answer, self::$_answer)) { return false; } $this->orderUpsells[] = new OrderUpsell(); $i = count($this->orderUpsells) - 1; $this->orderUpsells[$i]->allFields = true; $this->orderUpsells[$i]->upsell_id = $upsell_id; $this->orderUpsells[$i]->step = $step; $this->orderUpsells[$i]->answer = $answer; $this->orderUpsells[$i]->order_id = $order_id; // populate upsell info $upsell = new Upsell(); $upsell->fillFromDbPk($upsell_id); $this->orderUpsells[$i]->yes_upsell_id = $upsell->yes_upsell_id; $this->orderUpsells[$i]->no_upsell_id = $upsell->no_upsell_id; $this->orderUpsells[$i]->product_id = $upsell->product_id; $this->orderUpsells[$i]->shipping_id = $upsell->shipping_id; unset($upsell); // set step if ((int) $step > (int) $this->currentStep) { $this->currentStep = (int) $step; } }
public function testGetLinkedProducts() { $product = $this->getMock('\\Magento\\Catalog\\Model\\Product', [], [], '', false); $expected = [$product]; $product->expects($this->once())->method('getUpSellProducts')->will($this->returnValue($expected)); $model = new Upsell(); $this->assertEquals($expected, $model->getLinkedProducts($product)); }
private static function upsellDigger($uid) { $arr = array(); $u = new Upsell(); if (!$u->fillFromDbPk($uid)) { return $arr; } $arr[] = $uid; if ($u->yes_upsell_id && $u->no_upsell_id) { $arr = array_merge($arr, self::upsellDigger($u->yes_upsell_id), self::upsellDigger($u->no_upsell_id)); } else { if ($u->yes_upsell_id) { $arr = array_merge($arr, self::upsellDigger($u->yes_upsell_id)); } else { if ($u->no_upsell_id) { $arr = array_merge($arr, self::upsellDigger($u->no_upsell_id)); } } } // this sort is not working. why? //sort($arr); return array_unique($arr); }
* Date: 12/20/13 * Time: 1:18 PM */ include_once '../settings/autoload.php'; $msql = SafeMySQL::getInstance(); $answerVars = array('yes', 'no'); $upsellID = isset($_GET['upsell_id']) ? (int) $_GET['upsell_id'] : false; $orderID = isset($_GET['order_id']) ? $_GET['order_id'] : false; $answer = isset($_GET['answer']) ? $_GET['answer'] : false; if (!in_array($answer, $answerVars)) { $answer = 'no'; } if (!$upsellID) { die; } $upsellModel = new Upsell(); $upsellModel->fillFromDbPk($upsellID); $nextUpsellIDField = $answer . '_upsell_id'; $nextUpsellID = $upsellModel->{$nextUpsellIDField}; if (!$nextUpsellID) { //redirect on the "thank you page" // нужен orderID //Create empty order $order = new Order(); $order->orderLang = new Lang(); echo 1; die; } $productID = $upsellModel->product_id; if (!$productID) { die;
function upsellAction() { $model = new Upsell(); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['model']) && $_POST['model'] == 'upsells' && isset($_POST['ajax'])) { $upsellID = AF::get($_POST, 'upsell_id'); $parent_upsell_id = AF::get($_POST, 'parent_upsell_id'); $answer = AF::get($_POST, 'answer'); $productID = AF::get($_POST, 'product_id'); $shippingID = AF::get($_POST, 'shipping_id'); $campaign_id = AF::get($_POST, "campaign_id"); $main_parent_product_id = AF::get($_POST, "main_parent_product_id"); $product_replace = AF::get($_POST, "product_replace") ? AF::get($_POST, "product_replace") : 0; $url = AF::get($_POST, 'url'); if (!$answer) { Message::echoJsonError(__('upsell_not_upsell_answer')); } //if(!$shippingID) //Message::echoJsonError(__('upsell_select_shipping')); if (!$parent_upsell_id) { if ($upsellID) { $model->findByPk($upsellID); if ($productID) { $model->product_id = $productID; $model->shipping_id = $shippingID; $model->product_replace = $product_replace; $model->url = $url; if ($model->save()) { Message::echoJsonSuccess(array('reload' => '1', 'message' => __('upsell_updated'))); } else { Message::echoJsonError(__('upsell_not_updated')); } } else { $campProdModel = new CampaignProduct(); $campProdModel->findByPk($answer); $campProdModel->upsell_id = null; if ($campProdModel->save()) { $model->delete(); Message::echoJsonSuccess(array('reload' => '1', 'message' => __('upsell_updated'))); } else { Message::echoJsonError(__('upsell_not_updated')); } } } else { if (!$productID) { Message::echoJsonError(__('upsell_select_product')); } $model->product_id = $productID; $model->shipping_id = $shippingID; $model->product_replace = $product_replace; $model->url = $url; if ($model->save()) { $campProdModel = new CampaignProduct(); $campProdModel->findByPk($answer); $campProdModel->upsell_id = $model->upsell_id; if ($campProdModel->save()) { Message::echoJsonSuccess(array('reload' => '1', 'message' => __('upsell_created'))); } else { Message::echoJsonError(__('upsell_not_updated')); } } else { Message::echoJsonError(__('upsell_not_updated')); } } } elseif ($upsellID) { $model->findByPk($upsellID); if (!$productID) { if ($model->delete()) { $parentUpsellModel = new Upsell(); $parentUpsellModel->findByPk($parent_upsell_id); $parentUpsellModel->setAnswer($answer, null); $parentUpsellModel->save(); Message::echoJsonSuccess(__('upsell_not_deleted')); } else { Message::echoJsonError(__('upsell_not_updated')); } } else { $model->product_id = $productID; $model->shipping_id = $shippingID; $model->product_replace = $product_replace; $model->url = $url; if ($model->save()) { Message::echoJsonSuccess(array('reload' => '1', 'message' => __('upsell_updated'))); } else { Message::echoJsonError(__('upsell_not_updated')); } } } else { // parent_upsell_id = 119, upsell_id = 0 if (!$productID) { Message::echoJsonError(__('upsell_select_product')); } $model->fillFromArray($_POST); if ($model->save()) { $upsellModel = new Upsell(); $upsellModel->findByPk($parent_upsell_id); $upsellModel->setAnswer($answer, $model->upsell_id); if ($upsellModel->save()) { Message::echoJsonSuccess(array('reload' => '1', 'message' => __('upsell_created'))); } else { Message::echoJsonError(__('upsell_not_updated')); } } else { Message::echoJsonError(__('upsell_not_updated')); } } die; } }
private function upsellDirect($step = 1) { // pull upsell details $upsell = new Upsell(); $upsell->fillFromDbPk($this->upsell_id); // grab afid info from click to be used for pixels, etc if (!isset($this->click)) { $this->click = new Click(); $this->click->fillFromDbPk($this->order->click_id); } $clickUrlParams = $this->click->getUrlParams(); $url = $upsell->url . '?tempOrderId=' . $this->order->order_id . '&step=' . $step . '&uid=' . $this->upsell_id . '&product_id=' . $upsell->product_id . $clickUrlParams; // are these addl params needed? pixel on the upsell page? $this->apiSuccess($url); }